-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPlane.java
More file actions
111 lines (100 loc) · 1.75 KB
/
Plane.java
File metadata and controls
111 lines (100 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class Plane {
private int x;
private int y;
private Image image;
private int width;
private int height;
private boolean isVisible;
private int velX;
private int velY;
public Rectangle getRectangle(){
Rectangle r = new Rectangle(x,y,width,height);
return r;
}
public void dontMove(){
velX = 0;
velY = 0;
}
public void direction(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_UP){
velY = -1;
}
else
if(e.getKeyCode() == KeyEvent.VK_DOWN){
velY = 1;
}
else
if(e.getKeyCode()==KeyEvent.VK_LEFT){
if(x==5){
velX = 0;
}
else{
velX = -1;
}
}
else
if(e.getKeyCode()==KeyEvent.VK_RIGHT){
if(x ==GameOne.BOARD_WIDTH-image.getWidth(null)){
velX =0;
}
else{
velX = 1;
}
}
//move();
}
public void move(){
x = x + velX;
y = y + velY;
}
Plane(){
x = 50;
y = 100;
image =
new ImageIcon
(Plane.class.getResource("helicopter.png")).getImage();
width = image.getWidth(null);
height = image.getHeight(null);
isVisible = true;
}
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 Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public boolean isVisible() {
return isVisible;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
}