-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.pde
70 lines (56 loc) · 1.26 KB
/
Player.pde
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
class Player extends GameObject {
int coolDownTime;
private int fireCooldown;
ArrayList<GameObject> bulletList;
Player(PlayField p) {
this.pf = p;
this.img = loadImage("rocket.png");
imageMode(CENTER);
this.w = img.width;
this.h = img.height;
this.x = pf.getWidth()/2;
this.y = pf.getHeight() - h/2;
this.xSpeed = 5;
bulletList = new ArrayList<GameObject>();
fireCooldown = 0;
coolDownTime = 20;
}
void display() {
super.display();
for (GameObject bullet : bulletList) {
bullet.display();
}
}
void update() {
if (pf.leftPressed) {
x -= xSpeed;
}
if (pf.rightPressed) {
x += xSpeed;
}
if (pf.spacePressed) {
fire();
}
if (fireCooldown > 0) {
fireCooldown--;
}
for (int i=0; i<bulletList.size(); i++) {
bulletList.get(i).update();
if(bulletList.get(i).getY() < 0){
bulletList.remove(i);
}
}
}
void fire() {
if (fireCooldown == 0) {
bulletList.add(new Bullet(this));
fireCooldown = coolDownTime;
}
}
boolean collidesWith(AmigaBall b){
return intersectsCircle(b.getX(), b.getY(), b.getRadius() );
}
ArrayList<GameObject> getBulletList(){
return bulletList;
}
}