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;
- public class Podar {
- Image img;
- int x, y;
- boolean act = false;
- Timer timerUpdate;
- public Podar(Image img) {
- this.img = img;
- timerUpdate = new Timer(250, (e) -> vniz());
- }
- //
- public Image getImg() {
- return img;
- }
- public void setImg(Image img) {
- this.img = img;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- public boolean isAct() {
- return act;
- }
- public void setAct(boolean act) {
- this.act = act;
- }
- public void start() {
- //
- timerUpdate.start();
- y = 0;
- x = (int) (Math.random() * 700);
- act = true;
- }
- //
- private void vniz() {
- //
- if(act){
- y += 6;
- }
- if(y + img.getHeight(null) >= 470){
- timerUpdate.stop();
- }
- }
- // метод draw для отображения объекта
- public void draw(Graphics gr){
- //
- if(act){
- gr.drawImage(img, x, y, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement