mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-28 00:12:19 +11:00
Add border animation when moving
This commit is contained in:
parent
38a40eb2e4
commit
8f877d4677
10 changed files with 98 additions and 17 deletions
17
src/main.c
17
src/main.c
|
|
@ -27,6 +27,8 @@ void init(void) {
|
|||
}
|
||||
|
||||
__task int main(void) {
|
||||
uint16_t moves_count = 0;
|
||||
|
||||
init();
|
||||
|
||||
game_state state;
|
||||
|
|
@ -43,35 +45,42 @@ __task int main(void) {
|
|||
switch(read_kb()) {
|
||||
case K_UP:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x1F);
|
||||
state = step_game(UP);
|
||||
break;
|
||||
case K_DOWN:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x2F);
|
||||
state = step_game(DOWN);
|
||||
break;
|
||||
case K_LEFT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x4F);
|
||||
state = step_game(LEFT);
|
||||
break;
|
||||
case K_RIGHT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x8F);
|
||||
state = step_game(RIGHT);
|
||||
break;
|
||||
default:
|
||||
continue; // Do nothing, loop again
|
||||
}
|
||||
|
||||
// Increase the count of moves we made
|
||||
moves_count++;
|
||||
|
||||
// If we have finished, break out of this loop
|
||||
// If we have won, break out of this loop
|
||||
if(state.done) break;
|
||||
|
||||
// Draw the moved sprites
|
||||
// Draw the moved tiles
|
||||
draw_tiles();
|
||||
|
||||
// Unable to add a tile. We lost!!!
|
||||
// Unable to add a tile: we ran out of space and lost!!!
|
||||
uint8_t random_tile_off = add_random_tile();
|
||||
if(!random_tile_off) break;
|
||||
|
||||
// Draw the new tile directly on the front buffer
|
||||
// Draw the new tile directly on the front buffer, this way we make it appear with an "animation"
|
||||
ddraw_single_tile(random_tile_off - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue