add a palette fade to black.

This commit is contained in:
Moon Man 2025-01-26 13:12:54 -05:00
parent 51ae799d93
commit 18fea6f139
3 changed files with 76 additions and 9 deletions

View File

@ -153,7 +153,13 @@ process-images: $(GRAPHICSFILES)
# Rule for 8-bit images # Rule for 8-bit images
%_8.bin %_8.h: %.png %_8.bin %_8.h: %.png
@echo "Processing 8-bit image $<" @echo "Processing 8-bit image $<"
@magick $< -channel-fx "red=>blue,blue=>red" $(GENERATED)/$*_8.temp.png @if [ "$$(magick identify -format '%k' $<)" -ne 256 ]; then \
echo " Quantizing to 256 colors..."; \
magick $< -colors 256 -depth 8 -type Palette $(GENERATED)/$*_8.temp.png; \
else \
echo " Already quantized, using as-is..."; \
cp $< $(GENERATED)/$*_8.temp.png; \
fi
@grit $(GENERATED)/$*_8.temp.png -gb -gB8 -p -ftb -o $(GENERATED)/$*_8 @grit $(GENERATED)/$*_8.temp.png -gb -gB8 -p -ftb -o $(GENERATED)/$*_8
@rm $(GENERATED)/$*_8.temp.png @rm $(GENERATED)/$*_8.temp.png

BIN
sound/mozartsonata.mod Normal file

Binary file not shown.

View File

@ -9,8 +9,8 @@
#include <maxmod.h> #include <maxmod.h>
#include <mm_types.h> #include <mm_types.h>
#include "splash_8_img_bin.h" #include "together_8_img_bin.h"
#include "splash_8_pal_bin.h" #include "together_8_pal_bin.h"
// Define any soundbank includes here // Define any soundbank includes here
#include "soundbank.h" #include "soundbank.h"
@ -19,9 +19,20 @@
// Global mixing buffer for maxmod // Global mixing buffer for maxmod
u8 mixing_buffer[MM_MIXLEN_16KHZ] __attribute__((aligned(4))); u8 mixing_buffer[MM_MIXLEN_16KHZ] __attribute__((aligned(4)));
// Set the two variables below to start the palette fade
// The number of steps to fade the palette to black
const u8 palette_fade_steps = 12;
// The current step of the palette fade, set this to above to start the fade, the fade will decrement this value until it reaches 0
u8 palette_fade_step = 0;
const u8 fade_pause_frames = 120;
u8 fade_pause_frame_count = 0;
// Function Prototypes // Function Prototypes
void initializeSystem(void); void initializeSystem(void);
void loadIntroScreen(void); void loadIntroScreen(void);
void fadePaletteStep(void);
int main(void) { int main(void) {
// Initialize GBA system and maxmod // Initialize GBA system and maxmod
@ -32,7 +43,7 @@ int main(void) {
// Wait for VBlank before starting music // Wait for VBlank before starting music
VBlankIntrWait(); VBlankIntrWait();
mmStart(MOD_EYETIGER, MM_PLAY_LOOP); mmStart(MOD_MOZARTSONATA, MM_PLAY_LOOP);
// Main game loop // Main game loop
while(1) { while(1) {
@ -42,12 +53,24 @@ int main(void) {
mmFrame(); mmFrame();
// Game logic goes here // Game logic goes here
// Wait for vertical blank
scanKeys(); scanKeys();
if (keysDown() & KEY_A) { u16 keys = keysDown();
// Check for key presses
if (keys & KEY_A) {
mmEffect(SFX_WEAPON); mmEffect(SFX_WEAPON);
} }
if ((keys & KEY_START) && palette_fade_step == 0) {
// Start the palette fade
palette_fade_step = palette_fade_steps;
}
else if (keys & KEY_SELECT) {
// Reset the palette to the original
DMA3COPY(together_8_pal_bin, BG_PALETTE, together_8_pal_bin_size >> 1);
}
fadePaletteStep();
} }
return 0; return 0;
@ -71,9 +94,47 @@ void loadIntroScreen(void) {
// Load the palette // Load the palette
// Palette size needs to be in 16-bit units (divide by 2) // Palette size needs to be in 16-bit units (divide by 2)
DMA3COPY(splash_8_pal_bin, BG_PALETTE, splash_8_pal_bin_size >> 1); DMA3COPY(together_8_pal_bin, BG_PALETTE, together_8_pal_bin_size >> 1);
// Copy image data to first frame buffer // Copy image data to first frame buffer
// Image size needs to be in 16-bit units (divide by 2) // Image size needs to be in 16-bit units (divide by 2)
DMA3COPY(splash_8_img_bin, (void*)VRAM, splash_8_img_bin_size >> 1); DMA3COPY(together_8_img_bin, (void*)VRAM, together_8_img_bin_size >> 1);
}
// increment the palette fade step by 1
void fadePaletteStep(void) {
if (fade_pause_frame_count > fade_pause_frames) {
++fade_pause_frame_count;
return;
}
fade_pause_frame_count = 0;
if (palette_fade_steps && palette_fade_step) {
// Calculate how much to keep of each color component in this step
// As palette_fade_step goes from palette_fade_steps down to 1,
// this ratio goes from 1.0 down to nearly 0.0
u16 keep_ratio = ((u16)palette_fade_step << 7) / (u16)palette_fade_steps;
// fade the palette to black, by iterating over the palette memory one position at a time
for (u16 i = 0; i < 256; ++i) {
u16 color = ((u16*)together_8_pal_bin)[i];
// Extract RGB components (GBA uses 5 bits per component)
u16 r = (color & 0x1F);
u16 g = (color >> 5) & 0x1F;
u16 b = (color >> 10) & 0x1F;
// Reduce each component based on current step
r = (r * keep_ratio) >> 7;
g = (g * keep_ratio) >> 7;
b = (b * keep_ratio) >> 7;
// Recombine the components
u16 new_color = (b << 10) | (g << 5) | r;
BG_PALETTE[i] = new_color;
}
--palette_fade_step;
}
} }