Browse Source

feat: design 40x32 pixel art rat sprite for Game Over screen and invert palette

master
Matteo Benedetto 3 days ago
parent
commit
d552e4b7d8
  1. 81
      make_rat.py
  2. 24
      src/game_over_face.c
  3. 8
      src/game_over_face.h
  4. 19
      src/main.c

81
make_rat.py

@ -0,0 +1,81 @@
import sys
rat_art = [
" ###### ###### ",
" ######## ######## ",
"########## ##########",
" ########## ########## ",
" ######## ######## ",
" ###### .................. ###### ",
" .................... ",
" ...................... ",
" ........................ ",
" ....++++..........++++.... ",
" ....++++++........++++++.... ",
" ...++++++++......++++++++... ",
" ...++++++++++....++++++++++... ",
" ...+++####+++....+++####+++... ",
" ...++######++....++######++... ",
" ...++######++....++######++... ",
" ...+++####+++....+++####+++... ",
" ...++++++++......++++++++... ",
" ...++++++++......++++++++... ",
" ...++++++........++++++... ",
" .......................... ",
" ........................ ",
" .....++++++++++++..... ",
" ...+############+... ",
" ..+##++####++##+.. ",
" ..+##++####++##+.. ",
" .+############+. ",
" .++++++++++++. ",
" ............ ",
" .......... ",
" ........ ",
" ...... "
]
# 40x32 pixels = 5x4 tiles
WIDTH_TILES = len(rat_art[0]) // 8
HEIGHT_TILES = len(rat_art) // 8
def char_to_color(c):
if c == ' ': return 0
if c == '.': return 1
if c == '+': return 2
if c == '#': return 3
return 0
tiles = []
for ty in range(HEIGHT_TILES):
for tx in range(WIDTH_TILES):
tile_data = []
for y in range(8):
row_str = rat_art[ty*8 + y][tx*8 : tx*8 + 8]
low_byte = 0
high_byte = 0
for x in range(8):
color = char_to_color(row_str[x])
if color & 1:
low_byte |= (1 << (7 - x))
if color & 2:
high_byte |= (1 << (7 - x))
tile_data.append(low_byte)
tile_data.append(high_byte)
tiles.append(tile_data)
with open('src/game_over_face.h', 'w') as f:
f.write("#ifndef GAME_OVER_FACE_H\n")
f.write("#define GAME_OVER_FACE_H\n\n")
f.write("#include <stdint.h>\n\n")
f.write(f"extern const uint8_t game_over_face_tiles[{len(tiles) * 16}];\n\n")
f.write("#endif\n")
with open('src/game_over_face.c', 'w') as f:
f.write("#include \"game_over_face.h\"\n\n")
f.write(f"const uint8_t game_over_face_tiles[{len(tiles) * 16}] = {{\n")
for tile in tiles:
f.write(" " + ", ".join([f"0x{b:02X}" for b in tile]) + ",\n")
f.write("};\n")
print("Generated src/game_over_face.h and src/game_over_face.c")

24
src/game_over_face.c

@ -0,0 +1,24 @@
#include "game_over_face.h"
const uint8_t game_over_face_tiles[320] = {
0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xC0, 0xC0, 0x9F, 0x80, 0x3F, 0x00, 0x7F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x03, 0x03, 0xF9, 0x01, 0xFC, 0x00, 0xFE, 0x00,
0xFC, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00,
0xFF, 0x00, 0xE1, 0x1E, 0xC0, 0x3F, 0x80, 0x7F, 0x00, 0xFF, 0x1E, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7E, 0x81, 0x3C, 0xC3, 0x3C, 0xC3, 0x3C, 0xC3, 0x3C, 0xC3,
0xFF, 0x00, 0x87, 0x78, 0x03, 0xFC, 0x01, 0xFE, 0x00, 0xFF, 0x78, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF,
0x00, 0x00, 0x80, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0xE0, 0x00,
0x07, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1E, 0xFF, 0x80, 0x7F, 0x80, 0x7F, 0xC0, 0x3F, 0xFF, 0x00, 0xFF, 0x00, 0x7C, 0x03, 0x3B, 0x07,
0x3C, 0xC3, 0x7E, 0x81, 0x7E, 0x81, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0x78, 0xFF, 0x01, 0xFE, 0x01, 0xFE, 0x03, 0xFC, 0xFF, 0x00, 0xFF, 0x00, 0x3E, 0xC0, 0xDC, 0xE0,
0xE0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1B, 0x07, 0x1B, 0x07, 0x0B, 0x07, 0x04, 0x03, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3C, 0xFF, 0x3C, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7E, 0x00,
0xD8, 0xE0, 0xD8, 0xE0, 0xD0, 0xE0, 0x20, 0xC0, 0xC0, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

8
src/game_over_face.h

@ -0,0 +1,8 @@
#ifndef GAME_OVER_FACE_H
#define GAME_OVER_FACE_H
#include <stdint.h>
extern const uint8_t game_over_face_tiles[320];
#endif

19
src/main.c

@ -14,6 +14,7 @@
#include "maze.h"
#include "tiles.h"
#include "game_over_face.h"
#include "rat.h"
#include "music.h"
@ -78,20 +79,26 @@ void main(void) {
HIDE_SPRITES;
move_bkg(0, 0); // Resetta lo scrolling hardware per il testo
// Inverti i colori dello schermo! Nero diventa bianco e viceversa.
BGP_REG = 0b00011011;
// Pulisce brutalmente lo schermo riempiendolo di spazi
for (y = 0; y < 18; y++) {
printf("\n");
}
// Disegna l'ASCII art e il messaggio di sconfitta!
// Carica la grafica personalizzata per il faccione (20 tiles) a partire dall'indice 128
set_bkg_data(128, 20, game_over_face_tiles);
printf("\n\n");
printf(" GAME OVER!\n\n");
printf(" /\\_..._/\\\n");
printf(" | @ @ |\n");
printf(" | v |\n");
printf(" \\_/\"V\"\\_/\n\n");
printf(" GAME OVER!\n\n\n\n\n\n");
printf(" L'INVASIONE VINCE!\n");
// Disegna il faccione 5x4 al centro dello schermo (x=7, y=5)
uint8_t rat_map[20];
for (uint8_t i = 0; i < 20; i++) rat_map[i] = 128 + i;
set_bkg_tiles(7, 5, 5, 4, rat_map);
// Suono inquietante e fine della traccia allegra
play_game_over_music();

Loading…
Cancel
Save