add a palette fade to black.
This commit is contained in:
parent
51ae799d93
commit
18fea6f139
8
Makefile
8
Makefile
|
@ -153,7 +153,13 @@ process-images: $(GRAPHICSFILES)
|
|||
# Rule for 8-bit images
|
||||
%_8.bin %_8.h: %.png
|
||||
@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
|
||||
@rm $(GENERATED)/$*_8.temp.png
|
||||
|
||||
|
|
Binary file not shown.
|
@ -9,8 +9,8 @@
|
|||
#include <maxmod.h>
|
||||
#include <mm_types.h>
|
||||
|
||||
#include "splash_8_img_bin.h"
|
||||
#include "splash_8_pal_bin.h"
|
||||
#include "together_8_img_bin.h"
|
||||
#include "together_8_pal_bin.h"
|
||||
|
||||
// Define any soundbank includes here
|
||||
#include "soundbank.h"
|
||||
|
@ -19,9 +19,20 @@
|
|||
// Global mixing buffer for maxmod
|
||||
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
|
||||
void initializeSystem(void);
|
||||
void loadIntroScreen(void);
|
||||
void fadePaletteStep(void);
|
||||
|
||||
int main(void) {
|
||||
// Initialize GBA system and maxmod
|
||||
|
@ -32,7 +43,7 @@ int main(void) {
|
|||
|
||||
// Wait for VBlank before starting music
|
||||
VBlankIntrWait();
|
||||
mmStart(MOD_EYETIGER, MM_PLAY_LOOP);
|
||||
mmStart(MOD_MOZARTSONATA, MM_PLAY_LOOP);
|
||||
|
||||
// Main game loop
|
||||
while(1) {
|
||||
|
@ -42,12 +53,24 @@ int main(void) {
|
|||
mmFrame();
|
||||
|
||||
// Game logic goes here
|
||||
|
||||
// Wait for vertical blank
|
||||
scanKeys();
|
||||
if (keysDown() & KEY_A) {
|
||||
u16 keys = keysDown();
|
||||
|
||||
// Check for key presses
|
||||
if (keys & KEY_A) {
|
||||
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;
|
||||
|
@ -71,9 +94,47 @@ void loadIntroScreen(void) {
|
|||
|
||||
// Load the palette
|
||||
// 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
|
||||
// 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue