-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaze-game.ino
117 lines (77 loc) · 2.37 KB
/
maze-game.ino
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <Arduino.h>
#include <inttypes.h>
#include <FastLED.h>
#include "utils.h"
#define START_PIN 3
#define LED_DATA_PIN A0
#define NUM_LEDS 81 // 9 x 9 = 81
CRGB leds[NUM_LEDS];
#include "controller.h"
#include "maze.h"
#include "field.h"
#include "enemy.h"
char maze[9][10];
struct coord9x9 player;
bool gameStarted = false;
void setup(){
//Serial.begin(9600);
pinMode(START_PIN, INPUT);
pinMode(UP_ARROW_PIN, INPUT);
pinMode(DOWN_ARROW_PIN, INPUT);
pinMode(LEFT_ARROW_PIN, INPUT);
pinMode(RIGHT_ARROW_PIN, INPUT);
pinMode(GRID_PIN_00, INPUT);
pinMode(GRID_PIN_01, INPUT);
pinMode(GRID_PIN_02, INPUT);
pinMode(GRID_PIN_10, INPUT);
pinMode(GRID_PIN_11, INPUT);
pinMode(GRID_PIN_12, INPUT);
pinMode(GRID_PIN_20, INPUT);
pinMode(GRID_PIN_21, INPUT);
pinMode(GRID_PIN_22, INPUT);
// link the colors to the LEDs
FastLED.addLeds <WS2812B, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
// say hi on startup :P
Maze::setMaze(Maze::hello);
field::showField();
delay(2000);
}
void loop(){
// Serial.print(digitalRead(UP_ARROW_PIN));
// Serial.print(digitalRead(DOWN_ARROW_PIN));
// Serial.print(digitalRead(LEFT_ARROW_PIN));
// Serial.println(digitalRead(RIGHT_ARROW_PIN));
if (gameStarted) {
// Serial.println("cycle start");
// Serial.print("updating the subgrids...");
// change the maze based on input from the user
field::randSubgrid(controls::subgridInput());
// Serial.println(" done!");
// update the player and enemy positions
// Serial.print("Updating player...");
field::updatePlayer();
// Serial.println(" done!");
// Serial.print("Updating enemy...");
Enemy::updateEnemy();
// Serial.println(" done!");
// turn on the lights
field::showField();
// enemy kills you or you reach the destination
if (field::gameOver())
field::endGame(); // reset the game once it's over
// Serial.println("cycle end");
/// Checks if there is a cup on the coaster? (EDIT: checks if a button is depressed)
/// if so, begin the game and generate the random seed
} else if (controls::gameStart()) {
// select a random maze
Maze::pickMaze();
// put the player at the starting location
player = field::findStart();
// start the game
gameStarted = true;
Enemy::goToSpawn();
while (controls::gameStart())
delay(20);
}
delay(250);
}