-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
59 lines (53 loc) · 1.28 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
public class Player {
public int x;
public int y;
private Maze maze;
public boolean alive = true;
public boolean won = false;
public boolean moved = false;
public boolean canMove = true;
public Gun gun;
public Player(int x, int y, Maze m) {
this.x = x;
this.y = y;
this.maze = m;
}
public void keyPressed() {
if (key == CODED && alive && canMove) {
if (keyCode == UP && maze.validPos(x, y - 1)) {
y--;
moved = true;
} else if (keyCode == DOWN && maze.validPos(x, y + 1)) {
y++;
moved = true;
} else if (keyCode == LEFT && maze.validPos(x - 1, y)) {
x--;
moved = true;
} else if (keyCode == RIGHT && maze.validPos(x + 1, y)) {
x++;
moved = true;
}
}
}
public void tick() {
if (gun == null && x == maze.gun.x && y == maze.gun.y) {
gun = maze.gun;
gun.pickedUp = true;
}
}
public void update() {
tick();
if (gun != null && !gun.broken) {
image(
maze.stor.gunSmall,
(x * Settings.STEP) + Settings.STEP / 2,
(y * Settings.STEP) - Settings.STEP / 6
);
}
image(
maze.stor.player,
(x * Settings.STEP) + Settings.STEP / 2,
(y * Settings.STEP) + Settings.STEP / 2
);
}
}