Advertisement
sergAccount

Untitled

Dec 26th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 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. public class Podar {
  13.  
  14.     Image img;
  15.     int x, y;
  16.     boolean act = false;
  17.     Timer timerUpdate;
  18.  
  19.     public Podar(Image img) {
  20.         this.img = img;
  21.         timerUpdate = new Timer(250, (e) -> vniz());
  22.     }
  23.  
  24.     //
  25.     public Image getImg() {
  26.         return img;
  27.     }
  28.  
  29.     public void setImg(Image img) {
  30.         this.img = img;
  31.     }
  32.  
  33.     public int getX() {
  34.         return x;
  35.     }
  36.  
  37.     public void setX(int x) {
  38.         this.x = x;
  39.     }
  40.  
  41.     public int getY() {
  42.         return y;
  43.     }
  44.  
  45.     public void setY(int y) {
  46.         this.y = y;
  47.     }
  48.  
  49.     public boolean isAct() {
  50.         return act;
  51.     }
  52.  
  53.     public void setAct(boolean act) {
  54.         this.act = act;
  55.     }
  56.  
  57.     public void start() {
  58.         //
  59.         timerUpdate.start();
  60.         y = 0;
  61.         x = (int) (Math.random() * 700);
  62.         act = true;
  63.     }
  64.     //
  65.     private void vniz() {
  66.          //
  67.         if(act){            
  68.             y += 6;
  69.         }
  70.         if(y + img.getHeight(null) >= 470){
  71.             timerUpdate.stop();
  72.         }
  73.     }
  74.     // метод draw для отображения объекта
  75.     public void draw(Graphics gr){
  76.         //
  77.         if(act){
  78.             gr.drawImage(img, x, y, null);
  79.         }
  80.     }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement