feat: toggle music with SELECT and make newborn rats face opposite parent dir
This commit is contained in:
+1
-1
@@ -93,7 +93,7 @@ def draw_text(text, start_y_tiles, scale=1):
|
||||
is_text_mask[py, px] = True
|
||||
|
||||
# Align to 8x8 grid strictly
|
||||
draw_text("MICE! MAZE", 1, scale=2)
|
||||
draw_text("MICE!", 1, scale=2)
|
||||
draw_text("A GAME BY MATTEO", 5, scale=1)
|
||||
draw_text("BECAUSE HE WAS BORED", 6, scale=1)
|
||||
draw_text("PRESS START", 16, scale=1)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "maze.h"
|
||||
#include <gb/gb.h>
|
||||
#include "bomb.h"
|
||||
#include "music.h"
|
||||
|
||||
const unsigned char CursorSpriteData[] = {
|
||||
// Bordo quadrato 8x8 (Nero, colore 3 -> 11)
|
||||
@@ -50,6 +51,11 @@ void update_cursor(void) {
|
||||
drop_bomb(cursor_x, cursor_y);
|
||||
}
|
||||
|
||||
// Tasto SELECT per attivare/disattivare la musica
|
||||
if ((keys & J_SELECT) && !(previous_keys & J_SELECT)) {
|
||||
toggle_music();
|
||||
}
|
||||
|
||||
previous_keys = keys;
|
||||
|
||||
// Effetto lampeggiante: nascondi il cursore per metà del ciclo (ogni 16 frame)
|
||||
|
||||
+37
-17
@@ -250,6 +250,18 @@ static uint16_t tick = 0;
|
||||
static uint8_t frame_counter = 0;
|
||||
static uint8_t sfx_timer = 0;
|
||||
static uint8_t game_over_mode = 0;
|
||||
uint8_t music_enabled = 1;
|
||||
|
||||
void toggle_music(void) {
|
||||
music_enabled = !music_enabled;
|
||||
if (!music_enabled) {
|
||||
// Muta tutti i canali
|
||||
NR12_REG = 0x00; NR14_REG = 0x80;
|
||||
NR22_REG = 0x00; NR24_REG = 0x80;
|
||||
NR32_REG = 0x00; NR34_REG = 0x80;
|
||||
NR42_REG = 0x00; NR44_REG = 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
#define FRAMES_PER_TICK 8 // Velocità del tracker
|
||||
|
||||
@@ -353,7 +365,7 @@ void update_music(void) {
|
||||
uint8_t sub = tick & 0x3F; // tick % 64
|
||||
|
||||
// --- CH1: Arpeggio ---
|
||||
if (sfx_timer == 0) {
|
||||
if (sfx_timer == 0 && music_enabled) {
|
||||
uint16_t f1 = arp_parts[part][sub];
|
||||
NR10_REG = 0x00;
|
||||
NR11_REG = 0x80;
|
||||
@@ -363,28 +375,33 @@ void update_music(void) {
|
||||
}
|
||||
|
||||
// --- CH2: Melody ---
|
||||
uint16_t f2 = mel_parts[part][sub];
|
||||
if (f2 == N_REST) {
|
||||
NR21_REG = 0x00; NR22_REG = 0x00; NR23_REG = 0x00; NR24_REG = 0x80;
|
||||
} else {
|
||||
NR21_REG = 0x80;
|
||||
NR22_REG = 0xF2; // Volume alto
|
||||
NR23_REG = (uint8_t)(f2 & 0xFF);
|
||||
NR24_REG = 0x80 | ((f2 >> 8) & 0x07);
|
||||
if (music_enabled) {
|
||||
uint16_t f2 = mel_parts[part][sub];
|
||||
if (f2 == N_REST) {
|
||||
NR21_REG = 0x00; NR22_REG = 0x00; NR23_REG = 0x00; NR24_REG = 0x80;
|
||||
} else {
|
||||
NR21_REG = 0x80;
|
||||
NR22_REG = 0xF2; // Volume alto
|
||||
NR23_REG = (uint8_t)(f2 & 0xFF);
|
||||
NR24_REG = 0x80 | ((f2 >> 8) & 0x07);
|
||||
}
|
||||
}
|
||||
|
||||
// --- CH3: Bass ---
|
||||
uint16_t f3 = bass_parts[part][sub];
|
||||
if (f3 == N_REST) {
|
||||
NR32_REG = 0x00; // Vol 0
|
||||
NR34_REG = 0x80;
|
||||
} else {
|
||||
NR32_REG = 0x20; // Vol 100%
|
||||
NR33_REG = (uint8_t)(f3 & 0xFF);
|
||||
NR34_REG = 0x80 | ((f3 >> 8) & 0x07);
|
||||
if (music_enabled) {
|
||||
uint16_t f3 = bass_parts[part][sub];
|
||||
if (f3 == N_REST) {
|
||||
NR32_REG = 0x00; // Vol 0
|
||||
NR34_REG = 0x80;
|
||||
} else {
|
||||
NR32_REG = 0x20; // Vol 100%
|
||||
NR33_REG = (uint8_t)(f3 & 0xFF);
|
||||
NR34_REG = 0x80 | ((f3 >> 8) & 0x07);
|
||||
}
|
||||
}
|
||||
|
||||
// --- CH4: Drums ---
|
||||
if (sfx_timer == 0 && music_enabled) {
|
||||
uint8_t d4 = drum_parts[part][sub];
|
||||
if (d4 == 1) { // Kick
|
||||
NR41_REG = 0x00;
|
||||
@@ -402,6 +419,7 @@ void update_music(void) {
|
||||
NR43_REG = 0x21;
|
||||
NR44_REG = 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
// Avanza il tracker
|
||||
tick++;
|
||||
@@ -428,6 +446,7 @@ void play_sfx_explosion(void) {
|
||||
NR42_REG = 0xF7;
|
||||
NR43_REG = 0x6E;
|
||||
NR44_REG = 0xC0;
|
||||
sfx_timer = 30; // Proteggi CH4 e CH1
|
||||
}
|
||||
|
||||
void play_sfx_bomb_drop(void) {
|
||||
@@ -436,4 +455,5 @@ void play_sfx_bomb_drop(void) {
|
||||
NR42_REG = 0xA2; // Volume alto, decadimento rapido
|
||||
NR43_REG = 0x22; // Frequenza alta, noise
|
||||
NR44_REG = 0xC0; // Trigger
|
||||
sfx_timer = 15; // Proteggi per la durata del suono
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
void init_music(void);
|
||||
void update_music(void);
|
||||
void toggle_music(void);
|
||||
|
||||
void play_sfx_moan(void);
|
||||
void play_sfx_plop(void);
|
||||
|
||||
@@ -79,17 +79,25 @@ void init_rats(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void spawn_rat(uint8_t x, uint8_t y) {
|
||||
void spawn_rat(uint8_t x, uint8_t y, uint8_t initial_dir) {
|
||||
for (uint8_t i = 0; i < MAX_RATS; i++) {
|
||||
if (!rats[i].active) {
|
||||
rats[i].active = 1;
|
||||
rats[i].rat_x = x;
|
||||
rats[i].rat_y = y;
|
||||
|
||||
// Imposta la direzione e target in base all'iniziale (se valida e se possibile muoversi in quella dir)
|
||||
rats[i].current_dir = initial_dir;
|
||||
rats[i].target_x = x;
|
||||
rats[i].target_y = y;
|
||||
if (initial_dir == 0 && y < MAZE_HEIGHT - 1 && maze[y+1][x] == 0) rats[i].target_y++;
|
||||
else if (initial_dir == 1 && y > 0 && maze[y-1][x] == 0) rats[i].target_y--;
|
||||
else if (initial_dir == 2 && x > 0 && maze[y][x-1] == 0) rats[i].target_x--;
|
||||
else if (initial_dir == 3 && x < MAZE_WIDTH - 1 && maze[y][x+1] == 0) rats[i].target_x++;
|
||||
else rats[i].current_dir = 255; // Nessuna direzione valida trovata
|
||||
|
||||
rats[i].pixel_x = x * 8;
|
||||
rats[i].pixel_y = y * 8;
|
||||
rats[i].current_dir = 255;
|
||||
rats[i].reproduce_timer = 0;
|
||||
rats[i].cooldown_timer = 120; // Il cucciolo non si riproduce subito
|
||||
rats[i].is_mother = 0;
|
||||
@@ -172,7 +180,7 @@ void update_rats(void) {
|
||||
r->cooldown_timer = 120; // 2 secondi di pausa
|
||||
if (r->is_mother) {
|
||||
r->is_mother = 0;
|
||||
spawn_rat(r->rat_x, r->rat_y);
|
||||
spawn_rat(r->rat_x, r->rat_y, get_opposite(r->current_dir));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user