-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.pde
63 lines (50 loc) · 1.03 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
class Player {
boolean[] states = new boolean[4];
PVector pos;
int d, v;
float gravity = 1;
float time;
Player(int x, int y, int d, int v) {
pos = new PVector(x, y);
this.d = d;
this.v = v;
time = millis();
}
void display() {
rect(pos.x, pos.y, d, d, d / 2);
}
void jump() {
}
void move() {
pos.x = constrain(pos.x + v*(int(states[0]) - int(states[1])), d, width - d);
if (states[2]) {
} else {
pos.y = constrain(pos.y + v*(gravity + int(states[3])), d, height - d);
}
}
boolean setMove(int k, boolean b) {
switch (k) {
case 'W':
case ' ':
case UP:
return states[2] = b;
case 'S':
case DOWN:
return states[3] = b;
case 'A':
case LEFT:
return states[1] = b;
case 'D':
case RIGHT:
return states[0] = b;
default:
return b;
}
}
float getX() {
return pos.x;
}
float getY() {
return pos.y;
}
}