Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vladislav;
- // Import libraries for create UI and event
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- // Class for prize
- public class Prize {
- // Texture, coordinates, activity and timer
- private Image image;
- public int x, y;
- public boolean activity;
- private Timer timer;
- // In constructor load image and initialize all param
- public Prize(Image image) {
- // For 0.5 seconds move prize to down
- timer = new Timer(500, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- down();
- }
- });
- // Load image and initialize activity
- this.image = image;
- activity = false;
- }
- // If start - move object in start for random x. (If)
- public void start() {
- timer.start();
- y = 0; x = (int)(Math.random() * 700);
- activity = true;
- }
- // For moving
- public void down() {
- if (activity == true)
- y += 6;
- // If go to limit edge
- if (y + image.getHeight(null) >= 470)
- timer.stop();
- }
- public void draw(Graphics graph) {
- if (activity == true)
- graph.drawImage(image, x, y, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement