Browse Source

feat: add Game Over screen when 10 rats are spawned

master
Matteo Benedetto 3 days ago
parent
commit
f34d3824fc
  1. 32
      src/main.c
  2. 9
      src/rat.c
  3. 4
      src/rat.h

32
src/main.c

@ -10,6 +10,7 @@
#include <gb/gb.h>
#include <stdint.h>
#include <rand.h>
#include <stdio.h>
#include "maze.h"
#include "tiles.h"
@ -73,6 +74,37 @@ void main(void) {
// Game Loop primario
while (1) {
if (game_over_flag) {
HIDE_SPRITES;
move_bkg(0, 0); // Resetta lo scrolling hardware per il testo
// Pulisce brutalmente lo schermo riempiendolo di spazi
for (y = 0; y < 18; y++) {
printf("\n");
}
// Disegna l'ASCII art e il messaggio di sconfitta!
printf("\n\n");
printf(" GAME OVER!\n\n");
printf(" /\\___/\\\n");
printf(" ( ^ ^ )\n");
printf(" > w <\n");
printf(" \\___/\n\n");
printf(" L'INVASIONE VINCE!\n");
// Suono di risata malefica (una specie di trillo)
NR10_REG = 0x1E;
NR11_REG = 0x80;
NR12_REG = 0xF3;
NR13_REG = 0x00;
NR14_REG = 0x87;
while(1) {
update_music(); // La musica del tracollo continua
wait_vbl_done();
}
}
// Aggiorna la musica in background
update_music();

9
src/rat.c

@ -32,6 +32,7 @@ typedef struct {
} Rat;
static Rat rats[MAX_RATS];
uint8_t game_over_flag = 0;
static uint8_t get_opposite(uint8_t dir) {
if (dir == 0) return 1;
@ -91,6 +92,14 @@ void spawn_rat(uint8_t x, uint8_t y) {
rats[i].cooldown_timer = 120; // Il cucciolo non si riproduce subito
rats[i].is_mother = 0;
play_sfx_plop(); // Suono di nascita!
uint8_t count = 0;
for (uint8_t j = 0; j < MAX_RATS; j++) {
if (rats[j].active) count++;
}
if (count >= MAX_RATS) {
game_over_flag = 1;
}
break;
}
}

4
src/rat.h

@ -3,7 +3,9 @@
#include <stdint.h>
#define MAX_RATS 12
#define MAX_RATS 10
extern uint8_t game_over_flag;
void init_rats(void);
void update_rats(void);

Loading…
Cancel
Save