forked from skooter500/OOP-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthPowerup.java
More file actions
66 lines (54 loc) · 1.31 KB
/
HealthPowerup.java
File metadata and controls
66 lines (54 loc) · 1.31 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
package ie.tudublin;
import processing.core.PVector;
public class HealthPowerup extends GameObject implements PowerUp{
float w;
float halfW;
public HealthPowerup(float x, float y, float r, int c, YASC p)
{
super(x, y, r, c, p);
w = 50;
halfW = w / 2;
forward.x = p.random(-1, 1);
forward.y = p.random(-1, 1);
forward.normalize();
}
@Override
public void applyTo(Ship s) {
s.health += 10;
((YASC)p).gameObjects.remove(this);
}
float speed = 1;
@Override
public void update() {
rot += 0.01f;
pos.add(PVector.mult(forward, speed));
if (pos.x < 0)
{
pos.x = p.width;
}
if (pos.y < 0)
{
pos.y = p.height;
}
if (pos.x > p.width)
{
pos.x = 0;
}
if (pos.y > p.height)
{
pos.y = 0;
}
}
@Override
public void render() {
p.pushMatrix();
p.noFill();
p.stroke(255);
p.translate(pos.x, pos.y);
p.rotate(rot);
p.rect(-halfW, -halfW, w, w);
p.line(0, -20, 0, 20);
p.line(-20, 0, 20, 0);
p.popMatrix();
}
}