summaryrefslogtreecommitdiff
path: root/apps/recorder/sokoban.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/sokoban.c')
-rw-r--r--apps/recorder/sokoban.c1203
1 files changed, 818 insertions, 385 deletions
diff --git a/apps/recorder/sokoban.c b/apps/recorder/sokoban.c
index a15b8eedd1..2e98774676 100644
--- a/apps/recorder/sokoban.c
+++ b/apps/recorder/sokoban.c
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: sokoban.c,v 0.01 2002/06/15 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 Eric Linenberg 10 * Copyright (C) 2002 Eric Linenberg
11 * 11 *
@@ -31,21 +31,445 @@
31 31
32#define SOKOBAN_TITLE "Sokoban" 32#define SOKOBAN_TITLE "Sokoban"
33#define SOKOBAN_TITLE_FONT 2 33#define SOKOBAN_TITLE_FONT 2
34#define NUM_LEVELS 25 34#define NUM_LEVELS sizeof(levels)/320
35 35
36int board[16][20]; 36static char board[16][20];
37int current_level=0; 37static int current_level=0;
38int moves=0; 38static int moves=0;
39int row=0; 39static int row=0;
40int col=0; 40static int col=0;
41int boxes_to_go=0; 41static int boxes_to_go=0;
42int current_spot=1; 42static int current_spot=1;
43 43
44/* 320 boxes per level */ 44/* 320 boxes per level */
45char levels[320*NUM_LEVELS] = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002220000000000000000023200000000000000000212222000000000000222414320000000000002314522200000000000022224200000000000000000232000000000000000002220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222000000000000000211120000000000000002544202220000000000021412023200000000000222122232000000000000221111320000000000002111211200000000000021112222000000000000222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222222200000000000002111112220000000000224222111200000000002151411412000000000021332141220000000000223321112000000000000222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222200000000000022221132000000000000211141120000000000002144143200000000000022522332000000000000022222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222200000000000000002512220000000000000021411200000000000002221212200000000000023212112000000000000234112120000000000002311141200000000000022222222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222222200000000000022112152000000000000211121120000000000002414141200000000000021422112000000000022214121220000000000233333112000000000002222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222200000000000022211112000000000002231422122000000000023341411520000000000233141412200000000002222221120000000000000000222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222200000000000000211112000000000000222444120000000000002514331200000000000021433322000000000000222211200000000000000002222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222200000000000000002332000000000000000221322000000000000002114320000000000000221411220000000000002112441200000000000021151112000000000000222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222000000000000022211520000000000000211431220000000000002113431200000000000022211412000000000000002111220000000000000022222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222222200000000000021121112000000000000214334120000000000002543112200000000000021433412000000000000211211120000000000002222222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222220000000000000021111222000000000000214111120000000000222141221200000000002333141112000000000023334241220000000000222212141200000000000002115112000000000000022222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222222000000000000002111120000000000000021444220000000000000211233222000000000002211334120000000000002151111200000000000022222222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222222220000000000002111231200000000000221143332000000000002114121320000000000221224212200000000002111411412000000000021112111120000000000222222251200000000000000002222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222220000000000000233331200000000000022233342220000000000211424141200000000002144112412000000000021111211120000000000222215122200000000000002222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222222220000000000002331111200000000000023341452000000000000242444220000000000002334141200000000000023311112000000000000222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222222000000000000211111120000000000002124411200000000000021333212000000000000223334122000000000000212214120000000000002411411200000000000021121152000000000000222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222200000000000002221112222000000000021114141120000000000214111415200000000002224422222000000000000211332000000000000002333320000000000000022222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222222220000000000021111111200000000000214343152000000000002134343120000000000021434341200000000000211111112000000000002222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022222222200000000002211111112000000000021112424120000000000214411343200000000002152223332000000000022220222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222220000000000000023133200000000000000231432000000000000022211422000000000000214114120000000000002124221200000000000021115112000000000000222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222200000000000000021112222000000000002212411120000000000021411441200000000000212423132000000000002111533320000000000022222222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222200000000000022221112200000000000214141112000000000002523132120000000000021231321200000000000211141412000000000002211122220000000000002222200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222220000000000002222311220000000000021434311200000000000254212412000000000002143131120000000000022224241200000000000002313112000000000000022222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002222222200000000022221111312000000000211414143120000000002113222232200000000021434141520000000000211311112200000000002222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; 45static const char levels[][320] = {
46 46 "00000000000000000000"
47 47 "00000000000000000000"
48void load_level(int level_to_load) { 48 "00000000000000000000"
49 "00000000000000000000"
50 "00000000222000000000"
51 "00000000232000000000"
52 "00000000212222000000"
53 "00000022241432000000"
54 "00000023145222000000"
55 "00000022224200000000"
56 "00000000023200000000"
57 "00000000022200000000"
58 "00000000000000000000"
59 "00000000000000000000"
60 "00000000000000000000"
61 "00000000000000000000",
62
63 "00000000000000000000"
64 "00000000000000000000"
65 "00000000000000000000"
66 "00000000000000000000"
67 "00000222220000000000"
68 "00000211120000000000"
69 "00000254420222000000"
70 "00000214120232000000"
71 "00000222122232000000"
72 "00000022111132000000"
73 "00000021112112000000"
74 "00000021112222000000"
75 "00000022222000000000"
76 "00000000000000000000"
77 "00000000000000000000"
78 "00000000000000000000",
79
80 "00000000000000000000"
81 "00000000000000000000"
82 "00000000000000000000"
83 "00000000000000000000"
84 "00000000000000000000"
85 "00000022222220000000"
86 "00000021111122200000"
87 "00000224222111200000"
88 "00000215141141200000"
89 "00000213321412200000"
90 "00000223321112000000"
91 "00000022222222000000"
92 "00000000000000000000"
93 "00000000000000000000"
94 "00000000000000000000"
95 "00000000000000000000",
96
97 "00000000000000000000"
98 "00000000000000000000"
99 "00000000000000000000"
100 "00000000000000000000"
101 "00000000000000000000"
102 "00000000022222000000"
103 "00000022221132000000"
104 "00000021114112000000"
105 "00000021441432000000"
106 "00000022522332000000"
107 "00000002222222000000"
108 "00000000000000000000"
109 "00000000000000000000"
110 "00000000000000000000"
111 "00000000000000000000"
112 "00000000000000000000",
113
114 "00000000000000000000"
115 "00000000000000000000"
116 "00000000000000000000"
117 "00000000000000000000"
118 "00000002222000000000"
119 "00000002512220000000"
120 "00000002141120000000"
121 "00000022212122000000"
122 "00000023212112000000"
123 "00000023411212000000"
124 "00000023111412000000"
125 "00000022222222000000"
126 "00000000000000000000"
127 "00000000000000000000"
128 "00000000000000000000"
129 "00000000000000000000",
130
131 "00000000000000000000"
132 "00000000000000000000"
133 "00000000000000000000"
134 "00000000000000000000"
135 "00000000222222200000"
136 "00000002211215200000"
137 "00000002111211200000"
138 "00000002414141200000"
139 "00000002142211200000"
140 "00000222141212200000"
141 "00000233333112000000"
142 "00000222222222000000"
143 "00000000000000000000"
144 "00000000000000000000"
145 "00000000000000000000"
146 "00000000000000000000",
147
148 "00000000000000000000"
149 "00000000000000000000"
150 "00000000000000000000"
151 "00000000000000000000"
152 "00000000000000000000"
153 "00000000222222000000"
154 "00000022211112000000"
155 "00000223142212200000"
156 "00000233414115200000"
157 "00000233141412200000"
158 "00000222222112000000"
159 "00000000002222000000"
160 "00000000000000000000"
161 "00000000000000000000"
162 "00000000000000000000"
163 "00000000000000000000",
164
165 "00000000000000000000"
166 "00000000000000000000"
167 "00000000000000000000"
168 "00000000000000000000"
169 "00000000222222000000"
170 "00000000211112000000"
171 "00000022244412000000"
172 "00000025143312000000"
173 "00000021433322000000"
174 "00000022221120000000"
175 "00000000022220000000"
176 "00000000000000000000"
177 "00000000000000000000"
178 "00000000000000000000"
179 "00000000000000000000"
180 "00000000000000000000",
181
182 "00000000000000000000"
183 "00000000000000000000"
184 "00000000000000000000"
185 "00000000000000000000"
186 "00000000222200000000"
187 "00000000233200000000"
188 "00000002213220000000"
189 "00000002114320000000"
190 "00000022141122000000"
191 "00000021124412000000"
192 "00000021151112000000"
193 "00000022222222000000"
194 "00000000000000000000"
195 "00000000000000000000"
196 "00000000000000000000"
197 "00000000000000000000",
198
199 "00000000000000000000"
200 "00000000000000000000"
201 "00000000000000000000"
202 "00000000000000000000"
203 "00000000000000000000"
204 "00000000222220000000"
205 "00000022211520000000"
206 "00000021143122000000"
207 "00000021134312000000"
208 "00000022211412000000"
209 "00000000211122000000"
210 "00000000222220000000"
211 "00000000000000000000"
212 "00000000000000000000"
213 "00000000000000000000"
214 "00000000000000000000",
215
216 "00000000000000000000"
217 "00000000000000000000"
218 "00000000000000000000"
219 "00000000000000000000"
220 "00000022222222000000"
221 "00000021121112000000"
222 "00000021433412000000"
223 "00000025431122000000"
224 "00000021433412000000"
225 "00000021121112000000"
226 "00000022222222000000"
227 "00000000000000000000"
228 "00000000000000000000"
229 "00000000000000000000"
230 "00000000000000000000",
231
232 "00000000000000000000"
233 "00000000000000000000"
234 "00000000000000000000"
235 "00000000000000000000"
236 "00000000000000000000"
237 "00000002222220000000"
238 "00000002111122200000"
239 "00000002141111200000"
240 "00000222141221200000"
241 "00000233314111200000"
242 "00000233342412200000"
243 "00000222212141200000"
244 "00000000211511200000"
245 "00000000222222200000"
246 "00000000000000000000"
247 "00000000000000000000",
248
249 "00000000000000000000"
250 "00000000000000000000"
251 "00000000000000000000"
252 "00000000000000000000"
253 "00000000000000000000"
254 "00000022222200000000"
255 "00000021111200000000"
256 "00000021444220000000"
257 "00000021123322200000"
258 "00000022113341200000"
259 "00000002151111200000"
260 "00000002222222200000"
261 "00000000000000000000"
262 "00000000000000000000"
263 "00000000000000000000"
264 "00000000000000000000",
265
266 "00000000000000000000"
267 "00000000000000000000"
268 "00000000000000000000"
269 "00000000000000000000"
270 "00000000000000000000"
271 "00000002222222200000"
272 "00000002111231200000"
273 "00000022114333200000"
274 "00000021141213200000"
275 "00000221224212200000"
276 "00000211141141200000"
277 "00000211121111200000"
278 "00000222222251200000"
279 "00000000000222200000"
280 "00000000000000000000"
281 "00000000000000000000",
282
283 "00000000000000000000"
284 "00000000000000000000"
285 "00000000000000000000"
286 "00000000000000000000"
287 "00000000000000000000"
288 "00000022222220000000"
289 "00000023333120000000"
290 "00000222333422200000"
291 "00000211424141200000"
292 "00000214411241200000"
293 "00000211112111200000"
294 "00000222215122200000"
295 "00000000222220000000"
296 "00000000000000000000"
297 "00000000000000000000"
298 "00000000000000000000",
299
300 "00000000000000000000"
301 "00000000000000000000"
302 "00000000000000000000"
303 "00000000000000000000"
304 "00000000000000000000"
305 "00000022222222000000"
306 "00000023311112000000"
307 "00000023341452000000"
308 "00000024244422000000"
309 "00000023341412000000"
310 "00000023311112000000"
311 "00000022222222000000"
312 "00000000000000000000"
313 "00000000000000000000"
314 "00000000000000000000"
315 "00000000000000000000",
316
317 "00000000000000000000"
318 "00000000000000000000"
319 "00000000000000000000"
320 "00000000000000000000"
321 "00000000000000000000"
322 "00000222222220000000"
323 "00000211111120000000"
324 "00000212441120000000"
325 "00000213332120000000"
326 "00000223334122000000"
327 "00000021221412000000"
328 "00000024114112000000"
329 "00000021121152000000"
330 "00000022222222000000"
331 "00000000000000000000"
332 "00000000000000000000",
333
334 "00000000000000000000"
335 "00000000000000000000"
336 "00000000000000000000"
337 "00000000000000000000"
338 "00000000000000000000"
339 "00000002222200000000"
340 "00000222111222200000"
341 "00000211141411200000"
342 "00000214111415200000"
343 "00000222442222200000"
344 "00000002113320000000"
345 "00000002333320000000"
346 "00000002222220000000"
347 "00000000000000000000"
348 "00000000000000000000"
349 "00000000000000000000",
350
351 "00000000000000000000"
352 "00000000000000000000"
353 "00000000000000000000"
354 "00000000000000000000"
355 "00000000000000000000"
356 "00000222222222000000"
357 "00000211111112000000"
358 "00000214343152000000"
359 "00000213434312000000"
360 "00000214343412000000"
361 "00000211111112000000"
362 "00000222222222000000"
363 "00000000000000000000"
364 "00000000000000000000"
365 "00000000000000000000"
366 "00000000000000000000",
367
368 "00000000000000000000"
369 "00000000000000000000"
370 "00000000000000000000"
371 "00000000000000000000"
372 "00000000000000000000"
373 "00000000000000000000"
374 "00000022222222200000"
375 "00000221111111200000"
376 "00000211124241200000"
377 "00000214411343200000"
378 "00000215222333200000"
379 "00000222202222200000"
380 "00000000000000000000"
381 "00000000000000000000"
382 "00000000000000000000"
383 "00000000000000000000",
384
385 "00000000000000000000"
386 "00000000000000000000"
387 "00000000000000000000"
388 "00000000000000000000"
389 "00000000000000000000"
390 "00000002222220000000"
391 "00000002313320000000"
392 "00000002314320000000"
393 "00000022211422000000"
394 "00000021411412000000"
395 "00000021242212000000"
396 "00000021115112000000"
397 "00000022222222000000"
398 "00000000000000000000"
399 "00000000000000000000"
400 "00000000000000000000",
401
402 "00000000000000000000"
403 "00000000000000000000"
404 "00000000000000000000"
405 "00000000000000000000"
406 "00000000000000000000"
407 "00000000000000000000"
408 "00000022222000000000"
409 "00000021112222000000"
410 "00000221241112000000"
411 "00000214114412000000"
412 "00000212423132000000"
413 "00000211153332000000"
414 "00000222222222000000"
415 "00000000000000000000"
416 "00000000000000000000"
417 "00000000000000000000",
418
419 "00000000000000000000"
420 "00000000000000000000"
421 "00000000000000000000"
422 "00000000000000000000"
423 "00000000000000000000"
424 "00000000022222000000"
425 "00000022221112200000"
426 "00000021414111200000"
427 "00000025231321200000"
428 "00000021231321200000"
429 "00000021114141200000"
430 "00000022111222200000"
431 "00000002222200000000"
432 "00000000000000000000"
433 "00000000000000000000"
434 "00000000000000000000",
435
436 "00000000000000000000"
437 "00000000000000000000"
438 "00000000000000000000"
439 "00000000000000000000"
440 "00000000000000000000"
441 "00000000222220000000"
442 "00000222231122000000"
443 "00000214343112000000"
444 "00000254212412000000"
445 "00000214313112000000"
446 "00000222242412000000"
447 "00000002313112000000"
448 "00000002222222000000"
449 "00000000000000000000"
450 "00000000000000000000"
451 "00000000000000000000",
452
453 "00000000000000000000"
454 "00000000000000000000"
455 "00000000000000000000"
456 "00000000000000000000"
457 "00000000000000000000"
458 "00000000222222220000"
459 "00000222211113120000"
460 "00000211414143120000"
461 "00000211322223220000"
462 "00000214341415200000"
463 "00000211311112200000"
464 "00000222222222000000"
465 "00000000000000000000"
466 "00000000000000000000"
467 "00000000000000000000"
468 "00000000000000000000"
469};
470
471
472void load_level (int level_to_load) {
49 int a = 0; 473 int a = 0;
50 int b = 0; 474 int b = 0;
51 int c = 0; 475 int c = 0;
@@ -53,22 +477,10 @@ void load_level(int level_to_load) {
53 boxes_to_go = 0; 477 boxes_to_go = 0;
54 /* load level into board */ 478 /* load level into board */
55 /* get to the current level in the level array */ 479 /* get to the current level in the level array */
56 a = level_to_load*320;
57 480
58 for(b=0 ; b<16 ; b++) { 481 for(b=0 ; b<16 ; b++) {
59 for (c=0 ; c<20 ; c++) { 482 for (c=0 ; c<20 ; c++) {
60 if (levels[a] == '0') 483 board[b][c] = levels[level_to_load][a] - '0';
61 board[b][c]=0;
62 if (levels[a] == '1')
63 board[b][c]=1;
64 if (levels[a] == '2')
65 board[b][c]=2;
66 if (levels[a] == '3')
67 board[b][c]=3;
68 if (levels[a] == '4')
69 board[b][c]=4;
70 if (levels[a] == '5')
71 board[b][c]=5;
72 a++; 484 a++;
73 if (board[b][c]==5) { 485 if (board[b][c]==5) {
74 row = b; 486 row = b;
@@ -89,44 +501,44 @@ void update_screen(void) {
89 /* load the board to the screen */ 501 /* load the board to the screen */
90 for(b=0 ; b<16 ; b++) { 502 for(b=0 ; b<16 ; b++) {
91 for (c=0 ; c<20 ; c++) { 503 for (c=0 ; c<20 ; c++) {
92 504 switch ( board[b][c] ) {
93 /* this is a black space */ 505 case 0: /* this is a black space */
94 if (board[b][c]==0) { 506 lcd_drawrect (c*4, b*4, c*4+3, b*4+3);
95 lcd_drawrect (c*4, b*4, c*4+3, b*4+3); 507 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2);
96 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2); 508 break;
97 } 509
98 /* this is a wall */ 510 case 2: /* this is a wall */
99 if (board[b][c]==2) { 511 lcd_drawpixel (c*4, b*4);
100 lcd_drawpixel (c*4, b*4); 512 lcd_drawpixel (c*4+2, b*4);
101 lcd_drawpixel (c*4+2, b*4); 513 lcd_drawpixel (c*4+1, b*4+1);
102 lcd_drawpixel (c*4+1, b*4+1); 514 lcd_drawpixel (c*4+3, b*4+1);
103 lcd_drawpixel (c*4+3, b*4+1); 515 lcd_drawpixel (c*4, b*4+2);
104 lcd_drawpixel (c*4, b*4+2); 516 lcd_drawpixel (c*4+2, b*4+2);
105 lcd_drawpixel (c*4+2, b*4+2); 517 lcd_drawpixel (c*4+1, b*4+3);
106 lcd_drawpixel (c*4+1, b*4+3); 518 lcd_drawpixel (c*4+3, b*4+3);
107 lcd_drawpixel (c*4+3, b*4+3); 519 break;
108 } 520
109 /* this is a box */ 521 case 3: /* this is a home location */
110 if (board[b][c]==4) { 522 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2);
111 lcd_drawrect (c*4, b*4, c*4+3, b*4+3); 523 break;
112 } 524
113 /* this is a home location */ 525 case 4: /* this is a box */
114 if (board[b][c]==3) { 526 lcd_drawrect (c*4, b*4, c*4+3, b*4+3);
115 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2); 527 break;
116 } 528
117 /* this is you */ 529 case 5: /* this is you */
118 if (board[b][c]==5) { 530 lcd_drawline (c*4+1, b*4, c*4+2, b*4);
119 lcd_drawline (c*4+1, b*4, c*4+2, b*4); 531 lcd_drawline (c*4, b*4+1, c*4+3, b*4+1);
120 lcd_drawline (c*4, b*4+1, c*4+3, b*4+1); 532 lcd_drawline (c*4+1, b*4+2, c*4+2, b*4+2);
121 lcd_drawline (c*4+1, b*4+2, c*4+2, b*4+2); 533 lcd_drawpixel (c*4, b*4+3);
122 lcd_drawpixel (c*4, b*4+3); 534 lcd_drawpixel (c*4+3, b*4+3);
123 lcd_drawpixel (c*4+3, b*4+3); 535 break;
536
537 case 7: /* this is a box on a home spot */
538 lcd_drawrect (c*4, b*4, c*4+3, b*4+3);
539 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2);
540 break;
124 } 541 }
125 /* this is a box on a home spot */
126 if (board[b][c]==7) {
127 lcd_drawrect (c*4, b*4, c*4+3, b*4+3);
128 lcd_drawrect (c*4+1, b*4+1, c*4+2, b*4+2);
129 }
130 } 542 }
131 } 543 }
132 544
@@ -148,336 +560,355 @@ void update_screen(void) {
148 560
149void sokoban_loop(void) { 561void sokoban_loop(void) {
150 int ii = 0; 562 int ii = 0;
151 int b = 0;
152 moves = 0; 563 moves = 0;
153 current_level = 0; 564 current_level = 0;
154 load_level(current_level); 565 load_level(current_level);
155 update_screen(); 566 update_screen();
156 567
157
158 while(1) { 568 while(1) {
159 b = button_get(true); 569 switch ( button_get(true) ) {
160 570
161 if ( b & BUTTON_OFF ) { 571 case BUTTON_OFF:
162 /* get out of here */ 572 /* get out of here */
163 return; 573 return;
164 } 574
165 575 case BUTTON_F3:
166 576 /* increase level */
167 if ( b & BUTTON_F3 ) { 577 boxes_to_go=0;
168 /* increase level */ 578 break;
169 boxes_to_go=0; 579
170 } 580 case BUTTON_F2:
171 581 /* same level */
172 if ( b & BUTTON_F2 ) { 582 load_level(current_level);
173 /* same level */ 583 lcd_clear_display();
174 load_level(current_level); 584 update_screen();
175 lcd_clear_display(); 585 moves=0;
176 update_screen(); 586 break;
177 moves=0;
178 587
588 case BUTTON_F1:
589 /* previous level */
590 if (current_level==0) {
591 current_level=0;
592 }
593 else {
594 current_level--;
595 }
596 load_level(current_level);
597 lcd_clear_display();
598 update_screen();
599 moves=0;
600 break;
601
602 case BUTTON_LEFT:
603 switch ( board[row][col-1] ) {
604 case 1: /* if it is a blank spot */
605 board[row][col-1]=5;
606 board[row][col]=current_spot;
607 current_spot=1;
608 col--;
609 moves++;
610 break;
611
612 case 3: /* if it is a home spot */
613 board[row][col-1]=5;
614 board[row][col]=current_spot;
615 current_spot=3;
616 col--;
617 moves++;
618 break;
619
620 case 4:
621 switch ( board[row][col-2] ) {
622 case 1: /* if we are going from blank to blank */
623 board[row][col-2]=board[row][col-1];
624 board[row][col-1]=board[row][col];
625 board[row][col]=current_spot;
626 current_spot=1;
627 col--;
628 moves++;
629 break;
630
631 /* if there is a wall then do not move the box */
632 case 2:
633 /* do nothing */
634 break;
635
636 case 3: /* if we are going from a blank to home */
637 board[row][col-2]=7;
638 board[row][col-1]=board[row][col];
639 board[row][col]=current_spot;
640 current_spot=1;
641 col--;
642 boxes_to_go--;
643 moves++;
644 break;
645 }
646 break;
647
648 case 7:
649 switch ( board[row][col-2] ) {
650 case 1: /* we are going from a home to a blank */
651 board[row][col-2]=4;
652 board[row][col-1]=board[row][col];
653 board[row][col]=current_spot;
654 current_spot=3;
655 col--;
656 boxes_to_go++;
657 moves++;
658 break;
659
660 /* if there is a wall then do not move the box */
661 case 2:
662 /* do nothing */
663 break;
664
665 case 3: /* if we are going from a home to home */
666 board[row][col-2]=7;
667 board[row][col-1]=board[row][col];
668 board[row][col]=current_spot;
669 current_spot=3;
670 col--;
671 moves++;
672 break;
673 }
674 }
675 lcd_clear_display();
676 update_screen();
677 break;
678
679 case BUTTON_RIGHT: /* if it is a blank spot */
680 switch ( board[row][col+1] ) {
681 case 1:
682 board[row][col+1]=5;
683 board[row][col]=current_spot;
684 current_spot=1;
685 col++;
686 moves++;
687 break;
688
689 case 3: /* if it is a home spot */
690 board[row][col+1]=5;
691 board[row][col]=current_spot;
692 current_spot=3;
693 col++;
694 moves++;
695 break;
696
697 case 4:
698 switch ( board[row][col+2] ) {
699 case 1: /* if we are going from blank to blank */
700 board[row][col+2]=board[row][col+1];
701 board[row][col+1]=board[row][col];
702 board[row][col]=current_spot;
703 current_spot=1;
704 col++;
705 moves++;
706 break;
707
708 /* if there is a wall then do not move the box */
709 case 2:
710 /* do nothing */
711 break;
712
713 case 3: /* if we are going from a blank to home */
714 board[row][col+2]=7;
715 board[row][col+1]=board[row][col];
716 board[row][col]=current_spot;
717 current_spot=1;
718 col++;
719 boxes_to_go--;
720 moves++;
721 break;
722 }
723 break;
724
725 case 7:
726 switch ( board[row][col+2] ) {
727 case 1: /* we are going from a home to a blank */
728 board[row][col+2]=4;
729 board[row][col+1]=board[row][col];
730 board[row][col]=current_spot;
731 current_spot=3;
732 col++;
733 boxes_to_go++;
734 moves++;
735 break;
736
737 /* if there is a wall then do not move the box */
738 case 2:
739 /* do nothing */
740 break;
741
742 case 3:
743 board[row][col+2]=7;
744 board[row][col+1]=board[row][col];
745 board[row][col]=current_spot;
746 current_spot=3;
747 col++;
748 moves++;
749 break;
750 }
751 break;
752 }
753 lcd_clear_display();
754 update_screen();
755 break;
756
757 case BUTTON_UP:
758 switch ( board[row-1][col] ) {
759 case 1: /* if it is a blank spot */
760 board[row-1][col]=5;
761 board[row][col]=current_spot;
762 current_spot=1;
763 row--;
764 moves++;
765 break;
766
767 case 3: /* if it is a home spot */
768 board[row-1][col]=5;
769 board[row][col]=current_spot;
770 current_spot=3;
771 row--;
772 moves++;
773 break;
774
775 case 4:
776 switch ( board[row-2][col] ) {
777 case 1: /* if we are going from blank to blank */
778 board[row-2][col]=board[row-1][col];
779 board[row-1][col]=board[row][col];
780 board[row][col]=current_spot;
781 current_spot=1;
782 row--;
783 moves++;
784 break;
785
786 /* if there is a wall then do not move the box */
787 case 2:
788 /* do nothing */
789 break;
790
791 case 3: /* if we are going from a blank to home */
792 board[row-2][col]=7;
793 board[row-1][col]=board[row][col];
794 board[row][col]=current_spot;
795 current_spot=1;
796 row--;
797 boxes_to_go--;
798 moves++;
799 break;
800 }
801 break;
802
803 case 7:
804 switch ( board[row-2][col] ) {
805 case 1: /* we are going from a home to a blank */
806 board[row-2][col]=4;
807 board[row-1][col]=board[row][col];
808 board[row][col]=current_spot;
809 current_spot=3;
810 row--;
811 boxes_to_go++;
812 moves++;
813 break;
814
815 /* if there is a wall then do not move the box */
816 case 2:
817 /* do nothing */
818 break;
819
820 case 3: /* if we are going from a home to home */
821 board[row-2][col]=7;
822 board[row-1][col]=board[row][col];
823 board[row][col]=current_spot;
824 current_spot=3;
825 row--;
826 moves++;
827 break;
828 }
829 break;
830 }
831 lcd_clear_display();
832 update_screen();
833 break;
834
835 case BUTTON_DOWN:
836 switch ( board[row+1][col] ) {
837 case 1: /* if it is a blank spot */
838 board[row+1][col]=5;
839 board[row][col]=current_spot;
840 current_spot=1;
841 row++;
842 moves++;
843 break;
844
845 case 3: /* if it is a home spot */
846 board[row+1][col]=5;
847 board[row][col]=current_spot;
848 current_spot=3;
849 row++;
850 moves++;
851 break;
852
853 case 4:
854 switch ( board[row+2][col] ) {
855 case 1: /* if we are going from blank to blank */
856 board[row+2][col]=board[row+1][col];
857 board[row+1][col]=board[row][col];
858 board[row][col]=current_spot;
859 current_spot=1;
860 row++;
861 moves++;
862 break;
863
864 /* if there is a wall then do not move the box */
865 case 2:
866 /* do nothing */
867 break;
868
869 case 3: /* if we are going from a blank to home */
870 board[row+2][col]=7;
871 board[row+1][col]=board[row][col];
872 board[row][col]=current_spot;
873 current_spot=1;
874 row++;
875 boxes_to_go--;
876 moves++;
877 break;
878 }
879 break;
880
881 case 7:
882 switch ( board[row+2][col] ) {
883 case 1: /* we are going from a home to a blank */
884 board[row+2][col]=4;
885 board[row+1][col]=board[row][col];
886 board[row][col]=current_spot;
887 current_spot=3;
888 row++;
889 boxes_to_go++;
890 moves++;
891 break;
892
893 /* if there is a wall then do not move the box */
894 case 2:
895 /* do nothing */
896 break;
897
898 case 3: /* if we are going from a home to home */
899 board[row+2][col]=7;
900 board[row+1][col]=board[row][col];
901 board[row][col]=current_spot;
902 current_spot=3;
903 row++;
904 moves++;
905 break;
906 }
907 }
908 lcd_clear_display();
909 update_screen();
910 break;
179 } 911 }
180
181 if ( b & BUTTON_F1 ) {
182 /* previous level */
183 if (current_level==0) {
184 current_level=0;
185 }
186 else {
187 current_level--;
188 }
189 load_level(current_level);
190 lcd_clear_display();
191 update_screen();
192 moves=0;
193 }
194
195 if ( b & BUTTON_LEFT ) {
196 /* if it is a blank spot */
197 if (board[row][col-1]==1) {
198 board[row][col-1]=5;
199 board[row][col]=current_spot;
200 current_spot=1;
201 col--;
202 moves++;
203 }
204 /* if it is a home spot */
205 else if (board[row][col-1]==3) {
206 board[row][col-1]=5;
207 board[row][col]=current_spot;
208 current_spot=3;
209 col--;
210 moves++;
211 }
212 else if (board[row][col-1]==4) {
213 /* if there is a wall then do not move the box */
214 if(board[row][col-2]==2) {
215 /* do nothing */
216 }
217 /* if we are going from blank to blank */
218 else if(board[row][col-2]==1) {
219 board[row][col-2]=board[row][col-1];
220 board[row][col-1]=board[row][col];
221 board[row][col]=current_spot;
222 current_spot=1;
223 col--;
224 moves++;
225 }
226 /* if we are going from a blank to home */
227 else if(board[row][col-2]==3) {
228 board[row][col-2]=7;
229 board[row][col-1]=board[row][col];
230 board[row][col]=current_spot;
231 current_spot=1;
232 col--;
233 boxes_to_go--;
234 moves++;
235 }
236 }
237 else if (board[row][col-1]==7) {
238 /* if there is a wall then do not move the box */
239 if(board[row][col-2]==2) {
240 /* do nothing */
241 }
242 /* we are going from a home to a blank */
243 else if(board[row][col-2]==1) {
244 board[row][col-2]=4;
245 board[row][col-1]=board[row][col];
246 board[row][col]=current_spot;
247 current_spot=3;
248 col--;
249 boxes_to_go++;
250 moves++;
251 }
252 /* if we are going from a home to home */
253 else if(board[row][col-2]==3) {
254 board[row][col-2]=7;
255 board[row][col-1]=board[row][col];
256 board[row][col]=current_spot;
257 current_spot=3;
258 col--;
259 moves++;
260 }
261 }
262 lcd_clear_display();
263 update_screen();
264 }
265
266
267 if ( b & BUTTON_RIGHT ) {
268 /* if it is a blank spot */
269 if (board[row][col+1]==1) {
270 board[row][col+1]=5;
271 board[row][col]=current_spot;
272 current_spot=1;
273 col++;
274 moves++;
275 }
276 /* if it is a home spot */
277 else if (board[row][col+1]==3) {
278 board[row][col+1]=5;
279 board[row][col]=current_spot;
280 current_spot=3;
281 col++;
282 moves++;
283 }
284 else if (board[row][col+1]==4) {
285 /* if there is a wall then do not move the box */
286 if(board[row][col+2]==2) {
287 /* do nothing */
288 }
289 /* if we are going from blank to blank */
290 else if(board[row][col+2]==1) {
291 board[row][col+2]=board[row][col+1];
292 board[row][col+1]=board[row][col];
293 board[row][col]=current_spot;
294 current_spot=1;
295 col++;
296 moves++;
297 }
298 /* if we are going from a blank to home */
299 else if(board[row][col+2]==3) {
300 board[row][col+2]=7;
301 board[row][col+1]=board[row][col];
302 board[row][col]=current_spot;
303 current_spot=1;
304 col++;
305 boxes_to_go--;
306 moves++;
307 }
308 }
309 else if (board[row][col+1]==7) {
310 /* if there is a wall then do not move the box */
311 if(board[row][col+2]==2) {
312 /* do nothing */
313 }
314 /* we are going from a home to a blank */
315 else if(board[row][col+2]==1) {
316 board[row][col+2]=4;
317 board[row][col+1]=board[row][col];
318 board[row][col]=current_spot;
319 current_spot=3;
320 col++;
321 boxes_to_go++;
322 moves++;
323 }
324 /* if we are going from a home to home */
325 else if(board[row][col+2]==3) {
326 board[row][col+2]=7;
327 board[row][col+1]=board[row][col];
328 board[row][col]=current_spot;
329 current_spot=3;
330 col++;
331 moves++;
332 }
333 }
334 lcd_clear_display();
335 update_screen();
336 }
337
338 if ( b & BUTTON_UP ) {
339 /* if it is a blank spot */
340 if (board[row-1][col]==1) {
341 board[row-1][col]=5;
342 board[row][col]=current_spot;
343 current_spot=1;
344 row--;
345 moves++;
346 }
347 /* if it is a home spot */
348 else if (board[row-1][col]==3) {
349 board[row-1][col]=5;
350 board[row][col]=current_spot;
351 current_spot=3;
352 row--;
353 moves++;
354 }
355 else if (board[row-1][col]==4) {
356 /* if there is a wall then do not move the box */
357 if(board[row-2][col]==2) {
358 /* do nothing */
359 }
360 /* if we are going from blank to blank */
361 else if(board[row-2][col]==1) {
362 board[row-2][col]=board[row-1][col];
363 board[row-1][col]=board[row][col];
364 board[row][col]=current_spot;
365 current_spot=1;
366 row--;
367 moves++;
368 }
369 /* if we are going from a blank to home */
370 else if(board[row-2][col]==3) {
371 board[row-2][col]=7;
372 board[row-1][col]=board[row][col];
373 board[row][col]=current_spot;
374 current_spot=1;
375 row--;
376 boxes_to_go--;
377 moves++;
378 }
379 }
380 else if (board[row-1][col]==7) {
381 /* if there is a wall then do not move the box */
382 if(board[row-2][col]==2) {
383 /* do nothing */
384 }
385 /* we are going from a home to a blank */
386 else if(board[row-2][col]==1) {
387 board[row-2][col]=4;
388 board[row-1][col]=board[row][col];
389 board[row][col]=current_spot;
390 current_spot=3;
391 row--;
392 boxes_to_go++;
393 moves++;
394 }
395 /* if we are going from a home to home */
396 else if(board[row-2][col]==3) {
397 board[row-2][col]=7;
398 board[row-1][col]=board[row][col];
399 board[row][col]=current_spot;
400 current_spot=3;
401 row--;
402 moves++;
403 }
404 }
405 lcd_clear_display();
406 update_screen();
407 }
408
409 if ( b & BUTTON_DOWN ) {
410 /* if it is a blank spot */
411 if (board[row+1][col]==1) {
412 board[row+1][col]=5;
413 board[row][col]=current_spot;
414 current_spot=1;
415 row++;
416 moves++;
417 }
418 /* if it is a home spot */
419 else if (board[row+1][col]==3) {
420 board[row+1][col]=5;
421 board[row][col]=current_spot;
422 current_spot=3;
423 row++;
424 moves++;
425 }
426 else if (board[row+1][col]==4) {
427 /* if there is a wall then do not move the box */
428 if(board[row+2][col]==2) {
429 /* do nothing */
430 }
431 /* if we are going from blank to blank */
432 else if(board[row+2][col]==1) {
433 board[row+2][col]=board[row+1][col];
434 board[row+1][col]=board[row][col];
435 board[row][col]=current_spot;
436 current_spot=1;
437 row++;
438 moves++;
439 }
440 /* if we are going from a blank to home */
441 else if(board[row+2][col]==3) {
442 board[row+2][col]=7;
443 board[row+1][col]=board[row][col];
444 board[row][col]=current_spot;
445 current_spot=1;
446 row++;
447 boxes_to_go--;
448 moves++;
449 }
450 }
451 else if (board[row+1][col]==7) {
452 /* if there is a wall then do not move the box */
453 if(board[row+2][col]==2) {
454 /* do nothing */
455 }
456 /* we are going from a home to a blank */
457 else if(board[row+2][col]==1) {
458 board[row+2][col]=4;
459 board[row+1][col]=board[row][col];
460 board[row][col]=current_spot;
461 current_spot=3;
462 row++;
463 boxes_to_go++;
464 moves++;
465 }
466 /* if we are going from a home to home */
467 else if(board[row+2][col]==3) {
468 board[row+2][col]=7;
469 board[row+1][col]=board[row][col];
470 board[row][col]=current_spot;
471 current_spot=3;
472 row++;
473 moves++;
474 }
475 }
476 lcd_clear_display();
477 update_screen();
478 }
479
480
481 912
482 if (boxes_to_go==0) { 913 if (boxes_to_go==0) {
483 moves=0; 914 moves=0;
@@ -489,6 +920,8 @@ void sokoban_loop(void) {
489 lcd_update(); 920 lcd_update();
490 lcd_invertrect(0,0,111,63); 921 lcd_invertrect(0,0,111,63);
491 lcd_update(); 922 lcd_update();
923 if ( button_get(false) )
924 return;
492 } 925 }
493 return; 926 return;
494 } 927 }