-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTipToeVolcano.ino
More file actions
306 lines (259 loc) · 7.22 KB
/
TipToeVolcano.ino
File metadata and controls
306 lines (259 loc) · 7.22 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
Tip-Toe Volcano
by Big Potato Games 2020
Lead development by Daniel King
Original game by Big Potato Games
--------------------
Blinks by Move38
Brought to life via Kickstarter 2018
@madewithblinks
www.move38.com
--------------------
*/
enum signalStates {SETUP, HIDE, DEATH, RESET};
byte signalState = SETUP;
bool isMagma = false;
bool isChaos = false;
bool isRevealed = false;
bool isKiller = false;
Timer eruptionTimer;
#define ERUPTION_TIME 2000
bool magmaFaces[6] = {false, false, false, false, false, false};
void setup() {
// put your setup code here, to run once:
randomize();
}
void loop() {
switch (signalState) {
case SETUP:
setupLoop();
setupDisplay();
break;
case HIDE:
hideLoop();
hideDisplay();
break;
case DEATH:
deathLoop();
deathDisplay();
break;
case RESET:
resetLoop();
setupDisplay();
break;
}
FOREACH_FACE(f) {
byte sendData = (magmaFaces[f] << 3) | (isKiller << 2) | (signalState);
setValueSentOnFace(sendData, f);
}
buttonSingleClicked();
buttonDoubleClicked();
buttonMultiClicked();
}
void setupLoop() {
if (buttonSingleClicked()) {
isMagma = !isMagma;
}
if (buttonDoubleClicked()) {
signalState = HIDE;
setGrass();
if (isChaos) {
isMagma = random(1);
}
}
if (buttonMultiClicked() && buttonClickCount() == 3) {
isChaos = !isChaos;
}
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
if (getSignalState(getLastValueReceivedOnFace(f)) == HIDE) {
signalState = HIDE;
setGrass();
if (isChaos) {
isMagma = random(1);
}
}
}
}
}
void hideLoop() {
if (buttonDoubleClicked()) {
signalState = RESET;
}
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
if (getSignalState(getLastValueReceivedOnFace(f)) == DEATH) {
signalState = DEATH;
eruptionTimer.set(ERUPTION_TIME);
} else if (getSignalState(getLastValueReceivedOnFace(f)) == RESET) {
signalState = RESET;
}
}
}
if (buttonSingleClicked()) {
isRevealed = true;
if (isMagma) {
signalState = DEATH;
eruptionTimer.set(ERUPTION_TIME);
isKiller = true;
}
}
}
void deathLoop() {
if (buttonDoubleClicked()) {
signalState = SETUP;
if (isChaos) {
isMagma = false;
}
}
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
if (getSignalState(getLastValueReceivedOnFace(f)) == SETUP) {
signalState = SETUP;
} else if (getSignalState(getLastValueReceivedOnFace(f)) == RESET) {
signalState = RESET;
}
}
}
}
void resetLoop() {
signalState = SETUP;
FOREACH_FACE(f) {
if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
if (getSignalState(getLastValueReceivedOnFace(f)) == HIDE || getSignalState(getLastValueReceivedOnFace(f)) == DEATH) {
signalState = RESET;
}
}
}
}
byte getSignalState(byte data) {
return (data & 3);
}
byte getIsKiller(byte data) {
return ((data >> 2) & 1);
}
byte getIsMagma(byte data) {
return ((data >> 3) & 1);
}
#define SETUP_ANIM_INTERVAL 200
Timer setupAnimTimer;
byte setupAnimFace = 0;
byte randomAnimFace = 1;
void setupDisplay() {
//deal with the timer
if (setupAnimTimer.isExpired()) {
setupAnimTimer.set(SETUP_ANIM_INTERVAL);
setupAnimFace = (setupAnimFace + 1) % 6;
}
setColor(OFF);
if (isMagma || isChaos) {
setColorOnFace(RED, (setupAnimFace + 1) % 6);
setColorOnFace(RED, (setupAnimFace + 2) % 6);
setColorOnFace(RED, (setupAnimFace + 4) % 6);
setColorOnFace(RED, (setupAnimFace + 5) % 6);
}
if (!isMagma || isChaos) {
setColorOnFace(GREEN, setupAnimFace);
setColorOnFace(GREEN, (setupAnimFace + 3) % 6);
}
}
#define GRASS_HUE_LO 56
#define GRASS_HUE_HI 88
byte grassHues[6];
void setGrass() {
isRevealed = false;
isKiller = false;
FOREACH_FACE(f) {
grassHues[f] = GRASS_HUE_LO + random(GRASS_HUE_HI - GRASS_HUE_LO);
magmaFaces[f] = false;
}
}
void hideDisplay() {
//determine brightness
byte grassBrightness = 255;
if (isRevealed) {
grassBrightness = 100;
}
FOREACH_FACE(f) {
setColorOnFace(makeColorHSB(grassHues[f], 255, grassBrightness), f);
}
}
Timer magmaSpreadTimer;
#define MAGMA_INTERVAL 1000
void deathDisplay() {
//first figure out which faces should be automatically magma'd
if (isKiller) {//the center of the volcano
FOREACH_FACE(f) {
magmaFaces[f] = true;
}
} else {//things that are not the volcano
// //look around to see if you neighbor the volcano
// FOREACH_FACE(f) {
// if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
// if (getIsKiller(getLastValueReceivedOnFace(f)) == true) {//this neighbor is the volcano itself
// magmaFaces[f] = true;
// magmaFaces[(f + 5) % 6] = true;
// magmaFaces[(f + 1) % 6] = true;
// }
// }
// }
}
//do magma spreading stuff!
if (magmaSpreadTimer.isExpired()) {
magmaSpreadTimer.set(MAGMA_INTERVAL - random(500));
//let's evaluate our neighbors!
byte tempMagmaFaces[6] = {false, false, false, false, false, false};
FOREACH_FACE(f) {
byte magmaNeighbors = 0;
if (magmaFaces[f] == false) {//I am not magma yet!
if (magmaFaces[(f + 1) % 6] == true) {
magmaNeighbors++;
}
if (magmaFaces[(f + 5) % 6] == true) {
magmaNeighbors++;
}
if (!isValueReceivedOnFaceExpired(f)) {//neighbor!
if (getIsMagma(getLastValueReceivedOnFace(f)) == true) {//this neighbor is magma
magmaNeighbors++;
}
}
//now that we've evaluated the neighbors, should we become magma?
switch (magmaNeighbors) {
case 0:
break;
case 1:
if (random(2) == 0) {//ok chance of becoming magma
tempMagmaFaces[f] = true;
}
break;
// case 2:
// if (random(8) == 0) {//low chance of becoming magma
// tempMagmaFaces[f] = true;
// }
// break;
}
}
}//end checking loop
//now actually apply the new magma faces
FOREACH_FACE(f) {
if (tempMagmaFaces[f] == true) {
magmaFaces[f] = true;
}
}
}
//now do the graphics
byte timerProgress = map(eruptionTimer.getRemaining(), 0, ERUPTION_TIME, 0, 255); //goes from 255 at the beginning to 0 at the end
timerProgress = (timerProgress * 2) - ((timerProgress * timerProgress) / 255);
byte brightnessRumble = timerProgress / 2;//As the explosion happens, the amount of random reduction in brightness reduces
FOREACH_FACE(f) {
if (magmaFaces[f] == true) {
if (isKiller) {
setColorOnFace(makeColorHSB(random(31), 255 - timerProgress, 255 - random(brightnessRumble / 2)), f);
} else {
setColorOnFace(makeColorHSB(random(23), 255 - timerProgress, 255 - random(brightnessRumble)), f);
}
} else {
setColorOnFace(makeColorHSB(grassHues[f], 255 - timerProgress, map(timerProgress, 0, 255, 100, 255 - random(brightnessRumble))), f);
}
}
}