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.
- */
- package game;
- import java.awt.Graphics;
- import java.awt.Image;
- import javax.swing.Timer;
- /**
- *
- * @author Sergey
- */
- public class Podar {
- Image img;
- int x, y;
- boolean act;
- Timer timerUpdate;
- public Podar(Image img){
- this.img = img;
- timerUpdate = new Timer(250, (e) -> vniz());
- }
- //
- public Image getImage(){
- return img;
- }
- //
- public int getX(){
- return x;
- }
- public int getY(){
- return y;
- }
- public void start(){
- timerUpdate.start();
- y = 0;
- x = (int) (Math.random()*700);
- act = true;
- }
- // метод дя изменния коорд y
- public void vniz(){
- if(act){
- y = y + 6;
- }
- if(y + img.getHeight(null) >= 470){
- timerUpdate.stop();
- }
- }
- public void draw(Graphics g){
- if(act){
- g.drawImage(img, x, y, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement