-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathAIShip.java
123 lines (104 loc) · 2.79 KB
/
AIShip.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
package ie.dit;
import java.util.ArrayList;
import processing.core.PApplet;
import processing.core.PVector;
public class AIShip extends GameObject
{
float size;
private int health = 10;
private ArrayList<PVector> waypoints = new ArrayList<PVector>();
public AIShip(YASC yasc, float x, float y, float speed, float size)
{
super(yasc, x, y, 0, 5);
this.size = size;
for(int i = 0 ; i < 5 ; i ++)
{
waypoints.add(new PVector(yasc.random(0, yasc.width), yasc.random(0, yasc.height)));
}
}
public void render()
{
yasc.pushMatrix();
yasc.translate(pos.x, pos.y);
yasc.rotate(rotation);
yasc.stroke(0, 0, 255);
float halfSize = size / 2;
yasc.line(- halfSize, halfSize, 0, - halfSize);
yasc.line(0, - halfSize
, halfSize, halfSize);
yasc.line(halfSize, halfSize
,0, 0);
yasc.line(0, 0, -halfSize, halfSize);
yasc.popMatrix();
for(int i = 1 ; i <= waypoints.size() ; i ++)
{
PVector a = waypoints.get(i - 1);
PVector b = waypoints.get(i % waypoints.size());
yasc.stroke(255, 0, 0);
yasc.line(a.x, a.y, b.x, b.y);
}
yasc.fill(0);
yasc.text("Health:" + health, pos.x + 25, pos.y);
}
int current = 0;
public void update()
{
PVector toNext = PVector.sub(waypoints.get(current), pos);
float dist = toNext.mag();
toNext.normalize();
pos.add(toNext);
rotation = (float) Math.atan2(toNext.y, toNext.x) + PApplet.HALF_PI;
if (dist < 1)
{
current = (current + 1) % waypoints.size();
}
}
/**
* @return the size
*/
public float getSize() {
return size;
}
/**
* @param size the size to set
*/
public void setSize(float size) {
this.size = size;
}
/**
* @return the health
*/
public int getHealth() {
return health;
}
/**
* @param health the health to set
*/
public void setHealth(int health) {
this.health = health;
}
/**
* @return the waypoints
*/
public ArrayList<PVector> getWaypoints() {
return waypoints;
}
/**
* @param waypoints the waypoints to set
*/
public void setWaypoints(ArrayList<PVector> waypoints) {
this.waypoints = waypoints;
}
/**
* @return the current
*/
public int getCurrent() {
return current;
}
/**
* @param current the current to set
*/
public void setCurrent(int current) {
this.current = current;
}
}