-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.pde
60 lines (55 loc) · 1 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
class Player
{
PVector position;
float myWidth;
float myHeight;
float speed = 1.0f;
int lives = 3;
int score = 0;
Player()
{
myWidth = width / 10;
myHeight = width / 10;
position = new PVector(width / 2 - (myWidth / 2), height - (myHeight * 1.5f));
}
boolean collidesWith(Enemy enemy)
{
if (position.x > enemy.position.x + enemy.myWidth)
{
return false;
}
if (position.x + myWidth < enemy.position.x)
{
return false;
}
if (position.y > enemy.position.y + enemy.myHeight)
{
return false;
}
if (position.y + myWidth < enemy.position.y)
{
return false;
}
return true;
}
void update()
{
if (keyPressed)
{
if (keyCode == LEFT)
{
position.x -= speed;
}
if (keyCode == RIGHT)
{
position.x += speed;
}
}
}
void draw()
{
fill(0,0,255);
stroke(0,0,255);
rect(position.x, position.y, myWidth, myHeight);
}
}