Browse Source

feat: add playtime timer in the bottom right corner

master
Matteo Benedetto 3 days ago
parent
commit
0265208638
  1. 68
      src/main.c
  2. 25
      src/numbers_gfx.c
  3. 6
      src/numbers_gfx.h

68
src/main.c

@ -22,6 +22,7 @@
#include "cursor.h"
#include "bomb.h"
#include "pause_gfx.h"
#include "numbers_gfx.h"
static uint8_t main_prev_keys = 0;
@ -73,6 +74,9 @@ void main(void) {
move_sprite(i, 0, 0);
}
// Inizializza i tile dei numeri (0-9) per il timer (li carichiamo all'indice 25)
set_sprite_data(25, 10, NumberTiles);
// La mappa background in memoria hardware è grande 32x32 tiles.
// Inizializziamo il "fuori mappa" con siepi solide (mask 15 -> indice 21)
for (y = 0; y < 32; y++) {
@ -124,6 +128,10 @@ void main(void) {
SHOW_SPRITES;
DISPLAY_ON;
// Variabili per il timer
uint16_t play_time_seconds = 0;
uint8_t timer_frames = 0;
// Game Loop primario
while (1) {
if (game_over_flag) {
@ -142,8 +150,35 @@ void main(void) {
// Avvia la tragica sequenza musicale di Game Over
play_game_over_music();
SHOW_SPRITES;
while(1) {
update_music();
// Continua a disegnare il timer (punteggio finale) sopra il Game Over
{
uint16_t temp = play_time_seconds;
uint8_t d3 = temp / 1000; temp %= 1000;
uint8_t d2 = temp / 100; temp %= 100;
uint8_t d1 = temp / 10; temp %= 10;
uint8_t d0 = temp;
set_sprite_tile(25, 25 + d3);
set_sprite_tile(26, 25 + d2);
set_sprite_tile(27, 25 + d1);
set_sprite_tile(28, 25 + d0);
// Palette S_PALETTE per mantenere il timer bianco.
set_sprite_prop(25, S_PALETTE);
set_sprite_prop(26, S_PALETTE);
set_sprite_prop(27, S_PALETTE);
set_sprite_prop(28, S_PALETTE);
move_sprite(25, 136, 152);
move_sprite(26, 144, 152);
move_sprite(27, 152, 152);
move_sprite(28, 160, 152);
}
wait_vbl_done();
uint8_t keys = joypad();
if ((keys & J_START) && !(main_prev_keys & J_START)) {
@ -153,6 +188,39 @@ void main(void) {
}
}
// Logica del timer (incrementa ogni 60 frame = 1 secondo)
timer_frames++;
if (timer_frames >= 60) {
timer_frames = 0;
play_time_seconds++;
if (play_time_seconds > 9999) play_time_seconds = 9999;
}
// Disegna il timer
{
uint16_t temp = play_time_seconds;
uint8_t d3 = temp / 1000; temp %= 1000;
uint8_t d2 = temp / 100; temp %= 100;
uint8_t d1 = temp / 10; temp %= 10;
uint8_t d0 = temp;
set_sprite_tile(25, 25 + d3);
set_sprite_tile(26, 25 + d2);
set_sprite_tile(27, 25 + d1);
set_sprite_tile(28, 25 + d0);
set_sprite_prop(25, S_PALETTE);
set_sprite_prop(26, S_PALETTE);
set_sprite_prop(27, S_PALETTE);
set_sprite_prop(28, S_PALETTE);
// Y in basso (152 = margine inferiore visibile: 152 - 16 = 136), X a destra
move_sprite(25, 136, 152);
move_sprite(26, 144, 152);
move_sprite(27, 152, 152);
move_sprite(28, 160, 152);
}
uint8_t keys = joypad();
// Controllo per la Pausa

25
src/numbers_gfx.c

@ -0,0 +1,25 @@
#include "numbers_gfx.h"
// Font numerico 8x8 con sfondo bianco opaco e cifre nere.
const unsigned char NumberTiles[160] = {
// 0
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x44, 0xFF, 0x44, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00,
// 1
0xFF, 0x00, 0xFF, 0x10, 0xFF, 0x30, 0xFF, 0x10, 0xFF, 0x10, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00,
// 2
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x08, 0xFF, 0x10, 0xFF, 0x7C, 0xFF, 0x00, 0xFF, 0x00,
// 3
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x18, 0xFF, 0x44, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00,
// 4
0xFF, 0x00, 0xFF, 0x48, 0xFF, 0x48, 0xFF, 0x7C, 0xFF, 0x08, 0xFF, 0x08, 0xFF, 0x00, 0xFF, 0x00,
// 5
0xFF, 0x00, 0xFF, 0x7C, 0xFF, 0x40, 0xFF, 0x78, 0xFF, 0x04, 0xFF, 0x78, 0xFF, 0x00, 0xFF, 0x00,
// 6
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x40, 0xFF, 0x78, 0xFF, 0x44, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00,
// 7
0xFF, 0x00, 0xFF, 0x7C, 0xFF, 0x04, 0xFF, 0x08, 0xFF, 0x10, 0xFF, 0x10, 0xFF, 0x00, 0xFF, 0x00,
// 8
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00,
// 9
0xFF, 0x00, 0xFF, 0x38, 0xFF, 0x44, 0xFF, 0x3C, 0xFF, 0x04, 0xFF, 0x38, 0xFF, 0x00, 0xFF, 0x00
};

6
src/numbers_gfx.h

@ -0,0 +1,6 @@
#ifndef NUMBERS_GFX_H
#define NUMBERS_GFX_H
extern const unsigned char NumberTiles[160];
#endif
Loading…
Cancel
Save