-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame_State.pde
65 lines (55 loc) · 1.37 KB
/
Game_State.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
void runState() {
rectMode(CORNER);
if (millis() - delta >= 100) {
delta = millis();
clear();
// Move the snake
cubes.remove(0);
Position pos = cubes.get(cubes.size()-1).clone();
pos.move(direction, CUBE_SIZE);
cubes.add(pos);
print("X: " + pos.x + " Y: " + pos.y + "\n");
listenKey = true;
// Draw the Cube
fill(255);
stroke(0);
for (Position cube : cubes) {
// Check if collision with self.
if (cubes.indexOf(cube) != cubes.size()-1 && cube.at(pos)) {
STATE = 4;
mouseMoved();
}
rect(cube.x, cube.y, CUBE_SIZE, CUBE_SIZE);
}
// Check if out of bounds
if (pos.x > boxX + BOX_WIDTH || pos.x < boxX || pos.y > boxY + BOX_HEIGHT || pos.y < boxY) {
STATE = 4;
mouseMoved();
}
// Check if colliding with food
if (pos.at(food)) {
newFood();
addToFront();
}
//Food
fill(50);
stroke(255);
//image(spriteAnt, food.x, food.y, CUBE_SIZE, CUBE_SIZE);
rect(food.x, food.y, CUBE_SIZE, CUBE_SIZE);
noFill();
// TODO fix this
rect(boxX - 10, boxY - 10, BOX_WIDTH + 30, BOX_HEIGHT + 30);
}
}
void initGame() {
cubes.clear();
cubes.add(new Position(BOX_WIDTH/2 + boxX, BOX_HEIGHT/2 + boxY));
addToFront();
addToFront();
addToFront();
addToFront();
addToFront();
newFood();
delta = millis();
STATE = 2;
}