-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.pde
More file actions
101 lines (74 loc) · 1.94 KB
/
Entity.pde
File metadata and controls
101 lines (74 loc) · 1.94 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
class Entity
{
PVector position = new PVector();
PVector velocity = new PVector();
PVector acceleration = new PVector();
PVector temp = new PVector();
boolean alive = false;
boolean friendly = false;
float radius = 8;
ArrayList<Controller> controllers = new ArrayList<Controller>();
Weapon weapon = new Weapon();
public Entity() {
}
public void draw() {
ellipseMode(CENTER);
if (friendly)
fill(0, 255, 255);
else
fill(255, 255, 0);
ellipse(position.x, position.y, radius * 2, radius * 2);
}
public void update(float delta) {
if (alive) {
temp.set(acceleration);
temp.mult(delta);
velocity.add(temp);
temp.set(velocity);
temp.mult(delta);
position.add(temp);
}
for (Controller controller : controllers) {
controller.update(delta);
}
if (position.x < 0 || position.y < 0 || position.x > width || position.y > height) {
game.pendingRemove.add(this);
}
}
public void onCollision(CollisionEvent event) {
player.score += 99 * player.multiplier;
player.multiplier++;
}
}
class Projectile extends Entity {
}
class Ship extends Entity {
CollisionListener collisionListener;
public void onCollision(CollisionEvent event) {
sound2.play();
if (collisionListener != null) {
collisionListener.onCollision(event);
}
}
}
class PowerUp extends Entity {
}
class Emitter extends Entity {
float period = 2;
float cooldown = 0;
float i = 0;
public void update(float delta) {
if ((cooldown -= delta) < 0) {
cooldown = period;
i++;
Ship s = new Ship();
s.position.x = 200 + 20 * i;
s.position.y = 50;
CircleController c = new CircleController(s);
c.center.set(s.position);
s.controllers.add(c);
game.pendingAdd.add(s);
game.enemyShips.add(s);
}
}
}