-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathAmmoPowerup.java
57 lines (49 loc) · 1.21 KB
/
AmmoPowerup.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
package ie.dit;
import processing.core.PVector;
public class AmmoPowerup extends GameObject implements Powerup
{
public AmmoPowerup(YASC yasc)
{
super(yasc, yasc.random(0, yasc.width)
,yasc.random(0, yasc.height)
, 0, 2);
forward.x = yasc.random(-1, 1);
forward.y = yasc.random(-1, 1);
forward.normalize();
}
@Override
public void update() {
//pos =+ forward * speed;
pos.add(PVector.mult(forward, speed));
rotation += 0.01f;
if (pos.x < 0)
{
pos.x = yasc.width;
}
if (pos.x > yasc.width)
{
pos.x = 0;
}
if (pos.y < 0)
{
pos.y = yasc.height;
}
if (pos.y > yasc.height)
{
pos.y = 0;
}
}
int size = 20;
@Override
public void render() {
yasc.pushMatrix();
yasc.translate(pos.x, pos.y);
yasc.rotate(rotation);
yasc.rect(-size / 2, -size / 2, size, size);
yasc.popMatrix();
}
@Override
public void applyTo(Ship s) {
s.setAmmo(s.getAmmo() + 10);
}
}