Advertisement
sergAccount

Untitled

Mar 19th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 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.  
  7. import javax.swing.*;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. /**
  11.  *
  12.  * @author Sergey
  13.  */
  14. public class Podar {
  15.    
  16.     public Image img;
  17.     public int x, y;
  18.     public Boolean act = false;
  19.     private Timer timerUpdate;
  20.    
  21.     public Podar(Image img){
  22.         //
  23.         timerUpdate = new Timer(500, new ActionListener(){
  24.             @Override
  25.             public void actionPerformed(ActionEvent e) {
  26.                 vniz();
  27.             }                      
  28.         });                
  29.         this.img = img;        
  30.     }
  31.     //
  32.     public void start(){
  33.         //
  34.         timerUpdate.start();
  35.         y = 0;
  36.         x = (int)(Math.random()*700);
  37.         act = true;
  38.     }
  39.     //
  40.     public void vniz(){
  41.          //
  42.         if(act){            
  43.             y += 6;
  44.         }
  45.         if(y + img.getHeight(null) >= 470){
  46.             timerUpdate.stop();
  47.         }
  48.     }    
  49.    
  50.     public void draw(Graphics gr){
  51.         //
  52.         if(act){
  53.             gr.drawImage(img, x, y, null);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement