-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.pde
More file actions
74 lines (59 loc) · 2.27 KB
/
player.pde
File metadata and controls
74 lines (59 loc) · 2.27 KB
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
69
70
71
72
73
74
class Player {
PVector position;
int health, score = 0;
final float stripe_w = 40 * gUnit, circle_w = 20 * gUnit, small_c_w = 15 * gUnit;
final float w = 150 * gUnit, h = 30 * gUnit, velocity = 24 * gUnit;
final float darkenAmount = 0.4;
color darkerColor, brighterColor;
final color base_col = color(200, 200, 200),
stripe_col = color(255, 60, 60),
circle_col = color(0, 155, 255),
small_c_col = color(0, 205, 255);
Player() {
reset();
}
void move(String direction) {
if (direction.equals("LEFT"))
position.x -= velocity;
else if (direction.equals("RIGHT"))
position.x += velocity;
}
void moveMouse() {
position.x = mouseX - w / 2;
}
void checkBounds() {
if (position.x > width - margin - w) // right bound
position.x = width - margin - w;
else if (position.x < margin) // left bound
position.x = margin;
}
void reset() {
position = new PVector(width / 2 - w / 2, height - h / 2 - 50);
health = 2;
score = 0;
}
void draw() {
fill(circle_col);
circle(position.x + circle_w / 4, position.y + h / 2, circle_w);
circle(position.x + w - circle_w / 4, position.y + h / 2, circle_w);
fill(small_c_col);
circle(position.x + circle_w / 4, position.y + h / 2, small_c_w);
circle(position.x + w - circle_w / 4, position.y + h / 2, small_c_w);
darkerColor = lerpColor(stripe_col, color(0), darkenAmount);
brighterColor = lerpColor(stripe_col, color(255), darkenAmount);
fill(darkerColor);
rect(position.x, position.y, w, h);
fill(brighterColor);
triangle(position.x, position.y, position.x + w, position.y, position.x, position.y + h);
fill(stripe_col);
rect(position.x + w / 12, position.y + h / 10, w - 2 * (w / 12), h - 2 * (h / 10));
darkerColor = lerpColor(base_col, color(0), darkenAmount);
brighterColor = lerpColor(base_col, color(255), darkenAmount);
fill(darkerColor);
rect(position.x + stripe_w, position.y + h / 2, w - 2 * stripe_w, h / 2);
fill(brighterColor);
rect(position.x + stripe_w, position.y, w - 2 * stripe_w, h / 2);
fill(base_col);
rect(position.x + stripe_w, position.y + h / 10, w - 2 * stripe_w, h - 2 * (h / 10));
}
}