Fixed some game logic

* Each tile can only merge once per move
* Game update correctly after just moving
* Slowed down animation because it looked weird out of the emulator
* Fixed a single typo
This commit is contained in:
Geoffrey Frogeye 2014-04-08 17:33:30 +02:00
parent e363b2872b
commit 91e395a35e
5 changed files with 86 additions and 345 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
/SDCard/* /SDCard/*
/imgres/* /imgres/*
*.sublime-* *.sublime-*
*Thumbs.db

BIN
2048.G1A

Binary file not shown.

18
2048.c
View file

@ -56,7 +56,7 @@ bool Game_over = false;
bool Game_won = false; bool Game_won = false;
bool Game_keepPlaying = true; bool Game_keepPlaying = true;
int storage_bestScore = 0; int Storage_bestScore = 0;
Grid Grid_grid; Grid Grid_grid;
@ -124,7 +124,7 @@ int Grid_avaiableCellsAmount() {
} }
void storage_setBestScore(int bestScore) { void storage_setBestScore(int bestScore) {
storage_bestScore = bestScore; Storage_bestScore = bestScore;
// Sauvegarder dans la mémoire // Sauvegarder dans la mémoire
} }
@ -211,7 +211,7 @@ void Screen_actuate() {
SaveDisp(SAVEDISP_PAGE1); SaveDisp(SAVEDISP_PAGE1);
for (i = 0; i <= 1; i += 0.02) { for (i = 0; i <= 1; i += 0.01) {
RestoreDisp(SAVEDISP_PAGE1); RestoreDisp(SAVEDISP_PAGE1);
Screen_drawMovingTiles(i); Screen_drawMovingTiles(i);
ML_display_vram(); ML_display_vram();
@ -238,7 +238,7 @@ void Screen_actuate() {
void Game_actuate() { void Game_actuate() {
if (storage_bestScore < Game_score) { if (Storage_bestScore < Game_score) {
storage_setBestScore(Game_score); storage_setBestScore(Game_score);
} }
Screen_actuate(); Screen_actuate();
@ -315,6 +315,7 @@ bool Game_moveTile(Tile tile, Cell cell) {
tile.x = cell.x; tile.x = cell.x;
tile.y = cell.y; tile.y = cell.y;
Grid_insertTile(tile); Grid_insertTile(tile);
return true;
} }
} }
@ -382,7 +383,7 @@ void Game_move(int direction) { // 0: up, 1: right, 2: down, 3: left
position = Game_findFarthestPosition(cell, vector); position = Game_findFarthestPosition(cell, vector);
next = position.next; next = position.next;
farthest = position.farthest; farthest = position.farthest;
if (Grid_cellContent(next).value == tile.value && !tile.hasMerged) { // Merge if (Grid_cellContent(next).value == tile.value && !tile.hasMerged && !Grid_cellContent(next).hasMerged) { // Merge
merged.x = next.x; merged.x = next.x;
merged.y = next.y; merged.y = next.y;
merged.value = tile.value + 1; merged.value = tile.value + 1;
@ -486,13 +487,6 @@ int AddIn_main(int isAppli, unsigned short OptionNum) {
case KEY_CTRL_DEL: case KEY_CTRL_DEL:
initGame(); initGame();
break; break;
/*case KEY_CHAR_PLUS: // DEBUG
Game_addRandomTile();
Game_actuate();
break;
case KEY_CHAR_STORE: // DEBUG
Game_actuate();
break;*/
default: default:
break; break;
} }

408
2048.dlr
View file

@ -1,489 +1,235 @@
[DLSimRunSpace] [DLSimRunSpace]
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=184 Line=184
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=149 Line=149
Flags=00001012 Flags=00001012
Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=130 Line=130
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=198 Line=198
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=204 Line=204
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=210 Line=210
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=150 Line=150
Flags=00001012 Flags=00001012
Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=117 Line=117
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=124 Line=124
Flags=00001012 Flags=00001012
Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=151 Line=151
Flags=00001012 Flags=00001012
Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=147 Line=147
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=157 Line=157
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=158 Line=158
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=54 Line=54
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=54 Line=54
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=49 Line=49
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=47 Line=47
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=46 Line=46
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=45 Line=45
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=55 Line=55
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=55 Line=55
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=147 Line=147
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=147 Line=147
Flags=00001012 Flags=00001012
Sublevel=3 Sublevel=3
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=220 Line=220
Flags=00001012 Flags=00001012
Sublevel=1 Sublevel=1
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=210 Line=210
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=220 Line=220
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=117 Line=117
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=208
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=78
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=78
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=411
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=170
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=170
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=176
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=180
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=316
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=324
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=324
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=326
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=327
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=329
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=330
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=326
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=327
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=327
Flags=00001012
Sublevel=3
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=333
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=335
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=176
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=176
Flags=00001012
Sublevel=3
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=330
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=333
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=333
Flags=00001012
Sublevel=3
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=339
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=340
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=341
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=347
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=348
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=348
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=355
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=473
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=509
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=470
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=337
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=476
Flags=00001012
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=124
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=316
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=329
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=339
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=341
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=150
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=151
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=157 Line=157
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=157 Line=149
Flags=00001012 Flags=00001012
Sublevel=3 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=158 Line=158
Flags=00001012 Flags=00001012
Sublevel=2 Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=175 Line=188
Flags=00001012
Sublevel=1
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=175
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=140
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\ECode.c
Line=137 Line=321
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\ECode.c
Line=208 Line=323
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=347
Flags=00001012
Sublevel=2
[Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=238
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\ECode.c
Line=245 Line=330
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\ECode.c
Line=416 Line=343
Flags=00001012 Flags=00001012
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=335 Line=191
Flags=00001012 Flags=00001012
Sublevel=2
[Breakpoint] [Breakpoint]
File=Z:\home\geoffrey\Documents\Programmation\CASIO\2048\2048.c File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=355 Line=477
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=474
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=475
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=197
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=194
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=473
Flags=00001012
[Breakpoint]
File=C:\Users\Geoffrey\Documents\Programmation\CASIO\2048\2048.c
Line=189
Flags=00001012 Flags=00001012
Sublevel=2

View file

@ -10,7 +10,7 @@ if exist FXADDINror.bin del FXADDINror.bin
cd .. cd ..
if not exist debug\FXADDINror.bin goto error if not exist debug\FXADDINror.bin goto error
"C:\CASIO SDK\Tools\MakeAddinHeader363.exe" "Z:\home\geoffrey\Documents\Programmation\CASIO\2048" "C:\CASIO SDK\Tools\MakeAddinHeader363.exe" "C:\Users\Geoffrey\Documents\Programmation\CASIO\2048"
if not exist 2048.G1A goto error if not exist 2048.G1A goto error
echo Build has completed. echo Build has completed.
goto end goto end