Browse Source

feat: implement game pause via START button and Window layer dialog

master
Matteo Benedetto 3 days ago
parent
commit
a3e7a1579f
  1. 119
      build_pause.py
  2. 30
      src/main.c
  3. 15
      src/pause_gfx.c
  4. 7
      src/pause_gfx.h

119
build_pause.py

@ -0,0 +1,119 @@
letters = {
'P': [
"00000000",
"01111100",
"01000100",
"01111100",
"01000000",
"01000000",
"01000000",
"00000000"
],
'A': [
"00000000",
"00111000",
"01000100",
"01000100",
"01111100",
"01000100",
"01000100",
"00000000"
],
'U': [
"00000000",
"01000100",
"01000100",
"01000100",
"01000100",
"01000100",
"00111000",
"00000000"
],
'S': [
"00000000",
"00111100",
"01000000",
"00111000",
"00000100",
"01000100",
"00111000",
"00000000"
],
'E': [
"00000000",
"01111100",
"01000000",
"01111000",
"01000000",
"01000000",
"01111100",
"00000000"
],
'BLANK': [
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000"
],
'BORDER_H': [
"00000000",
"01111111",
"00000000",
"00000000",
"00000000",
"00000000",
"01111111",
"00000000"
]
}
def to_gb(tile):
b = []
for r in tile:
lo = hi = 0
for i, c in enumerate(r):
if c == '1':
hi |= (1 << (7 - i))
lo |= (1 << (7 - i)) # 3 = white/black depending on palette. Wait, 3 is black. 0 is white.
# Let's make text black on a white dialog!
# If background is white (0), text is black (3).
# So if '1', lo=1, hi=1.
b.append(lo)
b.append(hi)
return b
with open('src/pause_gfx.c', 'w') as f:
f.write('#include "pause_gfx.h"\n\n')
f.write('const unsigned char PauseTiles[] = {\n')
for k in ['P', 'A', 'U', 'S', 'E', 'BLANK', 'BORDER_H']:
b = to_gb(letters[k])
f.write(' ' + ','.join(f'0x{x:02X}' for x in b) + ',\n')
f.write('};\n\n')
# Dialog map: 7x3
# Borders and blank background
# Indices: 22=P, 23=A, 24=U, 25=S, 26=E, 27=BLANK, 28=BORDER_H
# Row 0: all BORDER_H
# Row 1: BLANK, P, A, U, S, E, BLANK
# Row 2: all BORDER_H
map_data = [
28, 28, 28, 28, 28, 28, 28,
27, 22, 23, 24, 25, 26, 27,
28, 28, 28, 28, 28, 28, 28
]
f.write('const unsigned char PauseMap[] = {\n ')
f.write(','.join(str(x) for x in map_data))
f.write('\n};\n')
with open('src/pause_gfx.h', 'w') as f:
f.write('#ifndef PAUSE_GFX_H\n#define PAUSE_GFX_H\n\n')
f.write('extern const unsigned char PauseTiles[];\n')
f.write('extern const unsigned char PauseMap[];\n\n')
f.write('#endif\n')
print("Generated pause_gfx files")

30
src/main.c

@ -21,6 +21,9 @@
#include "music.h"
#include "cursor.h"
#include "bomb.h"
#include "pause_gfx.h"
static uint8_t main_prev_keys = 0;
void main(void) {
uint8_t y, x;
@ -56,6 +59,11 @@ void main(void) {
// Invia i dati grafici del gioco alla VRAM
set_bkg_data(0, 22, TileData); // 6 pavimenti + 16 varianti autotile
// Inizializza la grafica della PAUSA sulla Window
set_bkg_data(22, 7, PauseTiles); // 7 tile per la pausa (P,A,U,S,E, blank, border)
set_win_tiles(0, 0, 7, 3, PauseMap);
move_win(7 + 52, 60); // Centra il dialog 7x3 (160-56)/2 = 52. (144-24)/2 = 60.
// 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++) {
@ -132,6 +140,28 @@ void main(void) {
}
}
uint8_t keys = joypad();
// Controllo per la Pausa
if ((keys & J_START) && !(main_prev_keys & J_START)) {
SHOW_WIN;
waitpadup(); // Aspetta che START sia rilasciato
while (1) {
uint8_t p_keys = joypad();
if (p_keys & J_START) {
break; // Esci dalla pausa
}
update_music(); // La musica continua in pausa
wait_vbl_done();
}
HIDE_WIN;
waitpadup(); // Aspetta il rilascio
keys = joypad(); // Rileggi per evitare salti
}
main_prev_keys = keys;
// Aggiorna la musica in background
update_music();

15
src/pause_gfx.c

@ -0,0 +1,15 @@
#include "pause_gfx.h"
const unsigned char PauseTiles[] = {
0x00,0x00,0x7C,0x7C,0x44,0x44,0x7C,0x7C,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x00,0x00,0x38,0x38,0x44,0x44,0x44,0x44,0x7C,0x7C,0x44,0x44,0x44,0x44,0x00,0x00,
0x00,0x00,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x38,0x00,0x00,
0x00,0x00,0x3C,0x3C,0x40,0x40,0x38,0x38,0x04,0x04,0x44,0x44,0x38,0x38,0x00,0x00,
0x00,0x00,0x7C,0x7C,0x40,0x40,0x78,0x78,0x40,0x40,0x40,0x40,0x7C,0x7C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,
};
const unsigned char PauseMap[] = {
28,28,28,28,28,28,28,27,22,23,24,25,26,27,28,28,28,28,28,28,28
};

7
src/pause_gfx.h

@ -0,0 +1,7 @@
#ifndef PAUSE_GFX_H
#define PAUSE_GFX_H
extern const unsigned char PauseTiles[];
extern const unsigned char PauseMap[];
#endif
Loading…
Cancel
Save