Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- *
- * @author Sergey
- */
- public class Podar {
- public Image img;
- public int x, y;
- public Boolean act = false;
- private Timer timerUpdate;
- public Podar(Image img){
- //
- timerUpdate = new Timer(500, new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- vniz();
- }
- });
- this.img = img;
- }
- //
- public void start(){
- //
- timerUpdate.start();
- y = 0;
- x = (int)(Math.random()*700);
- act = true;
- }
- //
- public void vniz(){
- //
- if(act){
- y += 6;
- }
- if(y + img.getHeight(null) >= 470){
- timerUpdate.stop();
- }
- }
- public void draw(Graphics gr){
- //
- if(act){
- gr.drawImage(img, x, y, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement