Advertisement
sergAccount

Untitled

Oct 18th, 2020
1,984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package game;
  7.  
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import javax.swing.Timer;
  11.  
  12. /**
  13.  *
  14.  * @author Sergey
  15.  */
  16. public class Podar {
  17.    
  18.     Image img;
  19.     int x, y;
  20.     boolean act;
  21.     Timer timerUpdate;
  22.    
  23.     public Podar(Image img){
  24.         this.img = img;
  25.         timerUpdate = new Timer(250, (e) -> vniz());
  26.     }
  27.     //
  28.     public Image getImage(){
  29.         return img;
  30.     }
  31.     //
  32.     public int getX(){
  33.         return x;
  34.     }
  35.     public int getY(){
  36.         return y;
  37.     }
  38.     public void start(){
  39.         timerUpdate.start();
  40.         y = 0;
  41.         x = (int) (Math.random()*700);
  42.         act = true;
  43.     }    
  44.     // метод дя изменния коорд y
  45.     public void vniz(){
  46.         if(act){
  47.             y = y + 6;
  48.         }
  49.         if(y + img.getHeight(null) >= 470){
  50.             timerUpdate.stop();
  51.         }        
  52.     }
  53.     public void draw(Graphics g){
  54.         if(act){
  55.             g.drawImage(img, x, y, null);
  56.         }
  57.     }    
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement