mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-30 10:19:23 +11:00
Show score and moves
This commit is contained in:
parent
4ea5c7147e
commit
1a3635fc9a
5 changed files with 55 additions and 35 deletions
41
src/main.c
41
src/main.c
|
|
@ -30,20 +30,31 @@ void init(void) {
|
|||
#define MOVES_TEXT_Y 14
|
||||
#define MOVES_TEXT_WIDTH 4
|
||||
|
||||
#define SCORE_TEXT_X 28
|
||||
#define SCORE_TEXT_Y 22
|
||||
#define SCORE_TEXT_WIDTH 5
|
||||
|
||||
__task int main(void) {
|
||||
uint16_t moves_count = 0;
|
||||
uint16_t moves_count;
|
||||
uint16_t score;
|
||||
uint8_t done;
|
||||
|
||||
init();
|
||||
|
||||
game_state state;
|
||||
|
||||
|
||||
while(1){ // Outer loop
|
||||
reset_game();
|
||||
|
||||
moves_count = 0;
|
||||
|
||||
score = reset_game();
|
||||
|
||||
// Draw the initial state of the game
|
||||
draw_game_background();
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y);
|
||||
draw_tiles();
|
||||
|
||||
// Swap graphical buffers
|
||||
swap_display_buffers();
|
||||
|
||||
while(1) { // Game loop
|
||||
lfsr_update();
|
||||
|
||||
|
|
@ -51,22 +62,22 @@ __task int main(void) {
|
|||
case K_UP:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x0E);
|
||||
state = step_game(UP);
|
||||
done = step_game(UP);
|
||||
break;
|
||||
case K_DOWN:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x0D);
|
||||
state = step_game(DOWN);
|
||||
done = step_game(DOWN);
|
||||
break;
|
||||
case K_LEFT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x0B);
|
||||
state = step_game(LEFT);
|
||||
done = step_game(LEFT);
|
||||
break;
|
||||
case K_RIGHT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x07);
|
||||
state = step_game(RIGHT);
|
||||
done = step_game(RIGHT);
|
||||
break;
|
||||
default:
|
||||
continue; // Do nothing, loop again
|
||||
|
|
@ -76,11 +87,12 @@ __task int main(void) {
|
|||
moves_count++;
|
||||
|
||||
// If we have won, break out of this loop
|
||||
if(state.done) break;
|
||||
if(done) break;
|
||||
|
||||
// Draw the number of moves
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
|
||||
|
||||
// Draw the moved tiles
|
||||
draw_tiles();
|
||||
|
||||
|
|
@ -88,6 +100,13 @@ __task int main(void) {
|
|||
uint8_t random_tile_off = add_random_tile();
|
||||
if(!random_tile_off) break;
|
||||
|
||||
score = calculate_score();
|
||||
|
||||
// Draw the score
|
||||
draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y);
|
||||
|
||||
swap_display_buffers();
|
||||
|
||||
// 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