-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
68 lines (59 loc) · 1.02 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
class Player {
final int UP = 0;
final int DOWN = 1;
final int STILL = 2;
int state = STILL;
float x;
float size;
float speed;
Player(float size, float speed, float x) {
this.size = size;
this. speed = speed;
this.x = 0;
}
Player() {
this(_PLAYER_SIZE, 8, 0);
}
void draw() {
switch(state) {
case UP:
x += speed;
if (x > size) {
state = DOWN;
}
noStroke();
greenFill();
rect(0, 0, x, height);
break;
case DOWN:
x -= speed;
if (x < 0) {
state = STILL;
}
noStroke();
redFill();
rect(0, 0, x, height);
break;
}
}
boolean checkCollision(float x) {
if (state == UP && this.x > x) {
return true;
} else {
return false;
}
}
void redFill() {
fill(100, 100, 60);
}
void greenFill() {
fill(35, 100, 100);
}
void hit() {
if (state != STILL) {
return;
} else {
state = UP;
}
}
}