-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.pde
More file actions
39 lines (31 loc) · 786 Bytes
/
Player.pde
File metadata and controls
39 lines (31 loc) · 786 Bytes
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
class Player extends Movil {
boolean alive = true;
ArrayList<Bullet> bullets = new ArrayList<Bullet>();
int shotInterval = 30;
int lastShotFired = -shotInterval;
SoundFile sound;
Player(spaceInvaders context){
y = height - 40;
w=26;
h=8;
sound = new SoundFile(context, "assets/laser.mp3");
}
void draw() {
fill(255, 255, 255);
noStroke();
rect(x, y, w, h);
triangle(x+w/2-5, y , x+w/2+5, y , x+w/2, y-5 );
}
void checkWallCollision() {
if (x<0) x=0;
if (x+w > width) x=width-w;
}
void shot(){
if(frameCount - lastShotFired > shotInterval){
Bullet newBullet = new Bullet(x+w/2, y-5, Direction.UP);
bullets.add(newBullet);
lastShotFired = frameCount;
sound.play();
}
}
}