-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
59 lines (52 loc) · 1.13 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
class Player {
float x, y;
color c;
float speed;
ArrayList<Bullet> bullets;
float bullet_diameter;
float bullet_speed;
Player(float x, float y) {
this.x = x;
this.y = y;
c = 255;
speed = 6;
bullets = new ArrayList<Bullet>();
bullet_diameter = 5;
bullet_speed = 7;
}
void update() {
if(keys[0] && !keys[1]) {
y -= speed;
} else if(keys[1] && !keys[0]) {
y += speed;
}
y = constrain(y, 0, height - 20);
if(keys[2] && !keys[3]) {
x -= speed;
} else if(keys[3] && !keys[2]) {
x += speed;
}
x = constrain(x, 20, width - 20);
for(int i = 0; i < bullets.size(); i++) {
bullets.get(i).update();
if(bullets.get(i).y < -bullets.get(i).d) {
bullets.remove(i);
}
}
}
void show() {
fill(c);
noStroke();
triangle(x-20,y+20,x,y,x+20,y+20);
for(int i = 0; i < bullets.size(); i++) {
bullets.get(i).show();
}
}
void fire() {
bullets.add(new Bullet(x, y, bullet_diameter, 255, bullet_speed));
}
void explode() {
exp.add(new Explosion(x, y));
end = true;
}
}