-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobotObject.java
158 lines (139 loc) · 3.15 KB
/
RobotObject.java
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package application;
import java.util.ArrayList;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
public class RobotObject extends GameObject{
// Pane paneR;
// ImageView i2;
public static int count;
public RobotObject()
{
pane = new Pane();
Image img = new Image("application/istockphoto-1030996148-1024x1024.jpg");
i = new ImageView(img);
i.setFitHeight(25);
i.setFitWidth(25);
pane.getChildren().add(i);
}
public double getX()
{
return i.getTranslateX();
}
public double getY()
{
return i.getTranslateY();
}
public void setX(double x)
{
i.setTranslateX(x);
}
public void setY(double y)
{
i.setTranslateY(y);
}
public void move(PlayerObject p, double dist, double yM, double HEIGHT)
{
if(yM >= 0 && yM <= HEIGHT)
{
if (p.getX() == this.getX())
{
if (p.getY() > this.getY() )
{
this.setY(this.getY() + dist);
}
else
{
this.setY(this.getY() - dist);
}
}
else if ( p.getY() == this.getY())
{
if ( p.getX() > this.getX() )
{
this.setX( this.getX() + dist);
}
else
{
this.setX( this.getX() - dist);
}
}
else if ( this.getX() > p.getX() && this.getY() < p.getY())
{
this.setX(this.getX() - dist);
this.setY(this.getY() + dist);
}
else if ( this.getX() > p.getX() && this.getY() > p.getY())
{
this.setX( this.getX() - dist);
this.setY( this.getY() - dist);
}
else if ( this.getX() < p.getX() && this.getY() < p.getY())
{
this.setX( this.getX() + dist);
this.setY( this.getY() + dist);
}
else if ( this.getX() < p.getX() && this.getY() > p.getY())
{
this.setX( this.getX() + dist);
this.setY( this.getY() - dist);
}
}
}
//method that check robot is collide with each other and rubble
public void isCollide(ArrayList<GameObject> packSp, Pane pane)
{
//the position of the robot
double x = this.getX();
double y = this.getY();
//boolean that check if collide with robot or rubble
boolean checkR = false;
boolean checkF = false;
//iterate through the ArrayList to check whether hit a robot or a rubble
for(int i = 0;i < packSp.size();++i)
{
if(packSp.get(i) instanceof RobotObject)
{
RobotObject rb = (RobotObject)packSp.get(i);
if(this != rb)
{
if(x == rb.getX() && y == rb.getY())
{
pane.getChildren().remove(rb.pane);
packSp.remove(i);
i--;
checkR = true;
}
}
}
else if(packSp.get(i) instanceof Rubble)
{
Rubble fr = (Rubble)packSp.get(i);
double fX = fr.getX();
double fY = fr.getY();
if(x == fX && y == fY)
{
checkF = true;
}
}
}
if(checkR)
{
//remove the picture of the fire out of the pane and remove the Robot out of the ArrayList
pane.getChildren().remove(this.pane);
packSp.remove(this);
//create a new Rubble and add it to the pane and the ArrayList
Rubble fire = new Rubble();
pane.getChildren().add(fire.pane);
fire.setX(x);
fire.setY(y);
packSp.add(fire);
}
else if(checkF)
{
packSp.remove(this);
pane.getChildren().remove(this.pane);
}
}
}