-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimon.c
338 lines (325 loc) · 10.7 KB
/
simon.c
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include "simon.h"
#include "simone.h"
#include "common.h"
void set_big_block(uint8_t color)
{
int y = SCREEN_Y/2-3;
int x = SCREEN_X/2-1;
switch (color)
{
case 0: // note right
set_block(y, x-2, color); // upper left
set_block(y, x, 5); // upper mid
set_block(y, x+2, color); // upper right
y += 2;
set_block(y, x-2, 5); // middle left
set_block(y, x, color); // middle mid
set_block(y, x+2, 5); // middle right
y += 2;
set_block(y, x-2, color); // bottom left
set_block(y, x, 5); // bottom mid
set_block(y, x+2, color); // bottom right
break;
case 1: // note left
set_block(y, x-2, color); // upper left
set_block(y, x, 5); // upper mid
set_block(y, x+2, color); // upper right
y += 2;
set_block(y, x-2, 5); // middle left
set_block(y, x, 5); // middle mid
set_block(y, x+2, 5); // middle right
y += 2;
set_block(y, x-2, color); // bottom left
set_block(y, x, 5); // bottom mid
set_block(y, x+2, color); // bottom right
break;
case 2: // note up
set_block(y, x-2, color); // upper left
set_block(y, x, color); // upper mid
set_block(y, x+2, color); // upper right
y += 2;
set_block(y, x-2, color); // middle left
set_block(y, x, color); // middle mid
set_block(y, x+2, color); // middle right
y += 2;
set_block(y, x-2, color); // bottom left
set_block(y, x, 5); // bottom mid
set_block(y, x+2, color); // bottom right
break;
case 3: // note down
set_block(y, x-2, 5); // upper left
set_block(y, x, 5); // upper mid
set_block(y, x+2, 5); // upper right
y += 2;
set_block(y, x-2, 5); // middle left
set_block(y, x, 5); // middle mid
set_block(y, x+2, 5); // middle right
y += 2;
set_block(y, x-2, 5); // bottom left
set_block(y, x, color); // bottom mid
set_block(y, x+2, 5); // bottom right
break;
default:
set_block(y, x-2, color); // upper left
set_block(y, x, color); // upper mid
set_block(y, x+2, color); // upper right
y += 2;
set_block(y, x-2, color); // middle left
set_block(y, x, color); // middle mid
set_block(y, x+2, color); // middle right
y += 2;
set_block(y, x-2, color); // bottom left
set_block(y, x, color); // bottom mid
set_block(y, x+2, color); // bottom right
}
}
void simon_game_init( void )
{
simone_enter_level(START_LEVEL);
//ply_init(SONGLEN,songdata);
}
int simon_game_frame(void)
{
ply_update_noloop();
read_presses();
if (pause)
{
pause--;
if (PRESSED(0,start) && pause > 5)
{
pause = 2;
UNPRESS(0, start);
}
if (!pause)
if (delayed_level)
{
if (delayed_level == -1)
simone_enter_level(0);
else
{
// switch from memorization to play or vice versa
D.ss.current_round = 0;
D.ss.current_note = 0;
set_big_block(5); // clear the blocks
if (D.ss.memorization)
{
vram[8][16] = tmap_m;
vram[8][17] = tmap_e;
vram[8][18] = tmap_m;
vram[8][19] = tmap_o;
vram[8][20] = tmap_r;
vram[8][21] = tmap_i;
vram[8][22] = tmap_z;
vram[8][23] = tmap_e;
}
else
{
decode_blocks(D.ss.current_round);
D.ss.incorrect = 0;
vram[8][16] = tmap_bg;
vram[8][17] = tmap_bg;
vram[8][18] = tmap_p;
vram[8][19] = tmap_l;
vram[8][20] = tmap_a;
vram[8][21] = tmap_y;
vram[8][22] = tmap_bg;
vram[8][23] = tmap_bg;
}
}
}
return 0;
}
if (level < REAL_LEVEL)
{
// just wait for keypress - wait a bit ?
if (PRESSED(0,start))
{
my_gamepad_buttons[0] = 0;
simone_enter_level(level+1);
}
else if (PRESSED(0, select))
{
my_gamepad_buttons[0] = 0;
if (level == 0)
return 1;
else
simone_enter_level(0);
return 0;
}
else if (PRESSED(0,any))
{
my_gamepad_buttons[0] = 0;
simone_enter_level(level+1);
}
}
else
{
if (D.ss.memorization)
{
if (vga_frame % 60 == 0)
{
if (D.ss.current_note == 0)
{
decode_blocks(D.ss.current_round);
uint8_t color = D.ss.next_blocks[D.ss.current_note];
set_big_block(color);
play_index(color);
++D.ss.current_note;
}
else
{
uint8_t color = D.ss.next_blocks[D.ss.current_note];
set_big_block(color);
play_index(color);
++D.ss.current_note;
if (D.ss.current_note > 3)
{
// increment the round
++D.ss.current_round;
D.ss.current_note = 0;
}
}
if (D.ss.current_round*4 + D.ss.current_note >= D.ss.final_note)
{
D.ss.memorization = 0;
delayed_level = 2;
pause = 60;
}
}
}
else // not in memorization mode
{
if (PRESSED(0, dpad))
{
uint8_t color = D.ss.next_blocks[D.ss.current_note];
set_big_block(color);
if (PRESSED(0,up))
{
if (color == 2)
{
score += 4*D.ss.current_round + D.ss.current_note + 1;
PLAY(note_up);
update_score();
}
else
{
PLAY(note_flub);
++D.ss.incorrect;
}
++D.ss.current_note;
UNPRESS(0, up);
}
else if (PRESSED(0, down))
{
if (color == 3)
{
score += 4*D.ss.current_round + D.ss.current_note + 1;
PLAY(note_down);
update_score();
}
else
{
PLAY(note_flub);
++D.ss.incorrect;
}
++D.ss.current_note;
UNPRESS(0, down);
}
else if (PRESSED(0, right))
{
if (color == 0)
{
score += 4*D.ss.current_round + D.ss.current_note + 1;
PLAY(note_right);
update_score();
}
else
{
PLAY(note_flub);
++D.ss.incorrect;
}
++D.ss.current_note;
UNPRESS(0, right);
}
else // left was pressed
{
if (color == 1)
{
score += 4*D.ss.current_round + D.ss.current_note + 1;
PLAY(note_left);
update_score();
}
else
{
PLAY(note_flub);
++D.ss.incorrect;
}
++D.ss.current_note;
UNPRESS(0, left);
}
if (D.ss.incorrect >= 1 + D.ss.final_note/16)
{
delayed_level = -1;
// write out no good.
vram[8][16] = tmap_n;
vram[8][17] = tmap_o;
vram[8][18] = tmap_bg;
vram[8][19] = tmap_g;
vram[8][20] = tmap_o;
vram[8][21] = tmap_o;
vram[8][22] = tmap_d;
vram[8][23] = tmap_period;
if (score > high_score[game])
{
high_score[game] = score;
}
pause = 180;
}
else if (D.ss.current_round*4 + D.ss.current_note >= D.ss.final_note)
{
D.ss.memorization = 1;
if (D.ss.incorrect)
{
vram[8][16] = tmap_bg;
vram[8][17] = tmap_bg;
vram[8][18] = tmap_bg;
vram[8][19] = tmap_o;
vram[8][20] = tmap_k;
vram[8][21] = tmap_period;
vram[8][22] = tmap_bg;
vram[8][23] = tmap_bg;
}
else
{
vram[8][16] = tmap_p;
vram[8][17] = tmap_e;
vram[8][18] = tmap_r;
vram[8][19] = tmap_f;
vram[8][20] = tmap_e;
vram[8][21] = tmap_c;
vram[8][22] = tmap_t;
vram[8][23] = tmap_exclamation;
}
delayed_level = 2;
// we got enough right, so let's move forward:
++D.ss.final_note;
// check if we need to increment the round, too:
if (D.ss.current_note > 3) //D.ss.final_note / 4 > D.ss.final_round)
{
++D.ss.final_round;
pack_next_blocks(D.ss.final_round);
}
pause = 60;
}
else if (D.ss.current_note > 3)
{
// we are finished with this round.
++D.ss.current_round;
D.ss.current_note = 0;
decode_blocks(D.ss.current_round);
}
}
}
}
return 0;
}