Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class shell {
- // Факт того что снаряд на поле
- public boolean shells_on_board;
- // Таймер
- public Timer new_shell_Timer;
- //Переменные координат зарядов
- public int shell_x1, shell_x2, shell_y1, shell_y2;
- //Переменная картинки заряда
- public Image image_shell;
- // Конструктор класса
- public shell(Image img_shell, final int LocationX1, final int LocationX2,
- final int LocationY1, final int LocationY2) {
- //Получаем все в локальные переменные
- shell_x1 = LocationX1;
- shell_x2 = LocationX2;
- shell_y1 = LocationY1;
- shell_y2 = LocationY2;
- image_shell=img_shell;
- new_shell_Timer = new Timer(1, new ActionListener() {
- public void actionPerformed(ActionEvent Event) {
- if (shell_y1 > 0) {
- shells_on_board = true;
- shell_y1 -= 1;
- shell_y2 -= 1;
- } else {
- shells_on_board = false;
- }
- }
- });
- new_shell_Timer.start();
- }
- public void paintComponent(Graphics gr) {
- System.out.println(shell_y1);
- if (shells_on_board == true) {
- gr.drawImage(image_shell, shell_x1, shell_y1, null);
- gr.drawImage(image_shell, shell_x2, shell_y2, null);
- } else {
- new_shell_Timer.stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement