Add score info in start/end boxes

This commit is contained in:
hkz 2025-07-26 10:22:13 +02:00
commit 2816b20cae
3 changed files with 38 additions and 12 deletions

View file

@ -25,7 +25,9 @@
static uint8_t *front_buf;
static uint8_t *back_buf;
#define BOX_CONTENT_SIZE 544
#define BOX_WIDTH 32
#define BOX_HEIGHT 17
#define BOX_CONTENT_SIZE (BOX_WIDTH * BOX_HEIGHT)
static const uint8_t box_content_win[BOX_CONTENT_SIZE] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -37,7 +39,7 @@ static const uint8_t box_content_win[BOX_CONTENT_SIZE] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 25, 15, 21, 18, 0, 19, 3, 15, 18, 5, 0, 9, 19, 58, 0, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -49,15 +51,15 @@ static const uint8_t box_content_win[BOX_CONTENT_SIZE] = {
static const uint8_t box_content_lose[BOX_CONTENT_SIZE] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 1, 13, 5, 0, 15, 22, 5, 18, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 1, 13, 5, 0, 0, 15, 22, 5, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 77, 0, 77, 0, 83, 77, 84, 0, 77, 0, 77, 0, 0, 77, 0, 0, 0, 83, 77, 84, 0, 83, 77,192, 0, 77, 77, 77, 0, 0,
0, 0, 77, 0, 77, 0, 77, 0, 77, 0, 77, 0, 77, 0, 0, 77, 0, 0, 0, 77, 0, 77, 0,212, 77, 84, 0, 77, 0, 0, 0, 0,
0, 0,212, 77,211, 0, 77, 0, 77, 0, 77, 0, 77, 0, 0, 77, 0, 0, 0, 77, 0, 77, 0, 0, 0, 77, 0, 77, 86, 0, 0, 0,
0, 0,212, 77,211, 0, 77, 0, 77, 0, 77, 0, 77, 0, 0, 77, 0, 0, 0, 77, 0, 77, 0, 0,203, 77, 0, 77,193, 0, 0, 0,
0, 0, 0, 77, 0, 0,212, 77,211, 0,212, 77,211, 0, 0,212, 77, 77, 0,212, 77,211, 0, 77, 77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,
0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 77, 0, 0, 77,192, 77, 0, 77, 77,211, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,203, 77, 0, 0, 77, 0, 0, 77,192, 77, 0, 77, 77,211, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 77, 77,211, 0, 0, 77, 0, 0, 77, 0, 77, 0, 77, 0, 84, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -87,6 +89,11 @@ static const uint8_t box_content_start[BOX_CONTENT_SIZE] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
static const uint8_t box_new_hi_score[BOX_WIDTH] = {
0, 0,102, 0, 23, 5, 0, 7, 15, 20, 0, 1, 0, 14, 5, 23, 0, 8, 9, 7, 8, 45, 19, 3, 15, 18, 5, 33, 0,102, 0, 0
};
// The grid is 5x5 squares,
// It is offset on the left side by 7 pixels and on the top by 14
// Every square is 35x35 pixels
@ -185,6 +192,7 @@ void draw_tiles(void) {
#define ENDGAME_BOX_X_OFFSET 2
#define ENDGAME_BOX_Y_OFFSET 16
#define ENDGAME_BOX_SCORE_LEN 5
void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score) {
// Clear the part of the screen where we'll draw
clear_box((SCREEN_WIDTH_B - (ENDGAME_BOX_X_OFFSET * 2)) + 1, (SCREEN_HEIGHT - (ENDGAME_BOX_Y_OFFSET * 2)) + CHAR_HEIGHT, ENDGAME_BOX_X_OFFSET, ENDGAME_BOX_Y_OFFSET, front_buf);
@ -227,7 +235,7 @@ void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score) {
// And now, the content!!!
for(uint16_t tile = 0; tile < sizeof(box_content_win); tile++) {
for(uint16_t tile = 0; tile < BOX_CONTENT_SIZE; tile++) {
if(!content[tile]) continue;
uint8_t x = tile % (SCREEN_WIDTH_B - (ENDGAME_BOX_X_OFFSET * 2) - 4);
@ -241,6 +249,24 @@ void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score) {
}
}
if(done != 0) { // Print the score
direct_draw_number(score, ENDGAME_BOX_SCORE_LEN, ENDGAME_BOX_X_OFFSET + 23, ENDGAME_BOX_Y_OFFSET + (11 * CHAR_HEIGHT), front_buf);
if(score > hi_score) {
for(uint8_t tile = 0; tile < BOX_WIDTH; tile++) {
if(!box_new_hi_score[tile]) continue;
uint8_t invert = box_new_hi_score[tile] & 0x80;
uint8_t ch_num = box_new_hi_score[tile] & 0x7F;
for(uint8_t row = 0; row < CHAR_HEIGHT; row++) {
uint16_t offset = line_offset_map[ENDGAME_BOX_Y_OFFSET + (2 * CHAR_HEIGHT) + (13 * CHAR_HEIGHT) + row] + ENDGAME_BOX_X_OFFSET + 2 + tile;
front_buf[offset] = invert ? ((~CHARSET[(ch_num * CHAR_HEIGHT) + row]) & 0x7F) : CHARSET[(ch_num * CHAR_HEIGHT) + row];
}
}
}
}
// TODO: Add additional info to the box, if necessary
}

View file

@ -50,11 +50,8 @@ __task int main(void) {
while(1){ // Outer loop
moves_count = 0;
// Check if we have a new high-score
if (score > hi_score) hi_score = score;
// TODO: Draw a screen and wait for a key press here here
// Draw a screen and wait for a key press here here
BELL1();
ddraw_endgame_box(done, score, hi_score);
while(!read_any_key()) {
@ -63,6 +60,9 @@ __task int main(void) {
BELL1();
clear_display_buffers(); // Clear display again
// Check if we have a new high-score from a previous game
if (score > hi_score) hi_score = score;
// Reset the game, calculate the initial score depending on which tiles we randomly get
score = reset_game();