Add splash screen functionality and update game state management

- Introduced GAME_SPLASH_SCREEN state in game.h
- Implemented splash_screen_init and splash_screen_update functions in splash_screen.c
- Updated game.c to initialize with GAME_SPLASH_SCREEN and handle splash screen updates
- Removed old splash screen code from main.c
This commit is contained in:
cellos51
2025-08-24 15:44:45 -04:00
parent da6248036c
commit 4f1f7cb347
6 changed files with 59 additions and 29 deletions
+2
View File
@@ -28,6 +28,7 @@
enum GameState
{
GAME_SPLASH_SCREEN,
GAME_MAIN_MENU,
GAME_PLAYING,
GAME_ROUND_END,
@@ -77,6 +78,7 @@ enum HandType
// Game functions
void game_init();
void game_update();
void game_set_state(enum GameState new_game_state);
// Forward declaration
struct List;
+13
View File
@@ -0,0 +1,13 @@
#ifndef SPLASH_SCREEN_H
#define SPLASH_SCREEN_H
#include <tonc.h>
#define SPLASH_FPS 60
#define SPLASH_DURATION_SECONDS 10
#define SPLASH_DURATION_FRAMES (SPLASH_FPS * SPLASH_DURATION_SECONDS)
void splash_screen_init();
void splash_screen_update(uint timer);
#endif // SPLASH_SCREEN_H
-1
View File
@@ -11,7 +11,6 @@ enum AffineBackgroundID background = AFFINE_BG_MAIN_MENU;
void affine_background_init()
{
affine_background_change_background(background);
affine_background_update();
bgaff = bg_aff_default;
+14 -7
View File
@@ -16,6 +16,7 @@
#include "tonc_video.h"
#include "audio_utils.h"
#include "selection_grid.h"
#include "splash_screen.h"
#include "background_gfx.h"
#include "background_shop_gfx.h"
@@ -34,7 +35,7 @@ static uint timer = 0; // This might already exist in libtonc but idk so i'm jus
static int game_speed = 1;
static int background = 0;
static enum GameState game_state = GAME_MAIN_MENU; // The current game state, this is used to determine what the game is doing at any given time
static enum GameState game_state = GAME_SPLASH_SCREEN; // The current game state, this is used to determine what the game is doing at any given time
static enum HandState hand_state = HAND_DRAW;
static enum PlayState play_state = PLAY_PLAYING;
static int state = 0; // General state variable, used for switch statements in each game state related function
@@ -252,6 +253,7 @@ static const BG_POINT JOKER_DISCARD_TARGET = {240, 30};
#define ITEM_SHOP_Y 71 // TODO: Needs to be a rect?
#define MAIN_MENU_BUTTONS 4
#define MAIN_MENU_IMPLEMENTED_BUTTONS 1 // Remove this once all buttons are implemented
//TODO: Properly define and use
#define MENU_POP_OUT_ANIM_FRAMES 20
@@ -993,9 +995,10 @@ static void game_round_init()
deck_shuffle(); // Shuffle the deck at the start of the round
}
void game_main_menu_init()
static void game_main_menu_init()
{
affine_background_change_background(AFFINE_BG_MAIN_MENU);
change_background(BG_ID_MAIN_MENU);
main_menu_ace = card_object_new(card_new(SPADES, ACE));
card_object_set_sprite(main_menu_ace, 0); // Set the sprite for the ace of spades
main_menu_ace->sprite_object->sprite->obj->attr0 |= ATTR0_AFF_DBL; // Make the sprite double sized
@@ -1033,6 +1036,9 @@ static void init_game_state(enum GameState game_state_to_init)
// Switch written out, add init for states as needed
switch (game_state_to_init)
{
case GAME_SPLASH_SCREEN:
splash_screen_init();
break;
case GAME_MAIN_MENU:
game_main_menu_init();
break;
@@ -1057,7 +1063,7 @@ static void init_game_state(enum GameState game_state_to_init)
}
// Game functions
static void game_set_state(enum GameState new_game_state)
void game_set_state(enum GameState new_game_state)
{
timer = 0; // Reset the timer
init_game_state(new_game_state);
@@ -1077,7 +1083,7 @@ void jokers_available_to_shop_init()
void game_init()
{
change_background(BG_ID_MAIN_MENU);
//change_background(BG_ID_MAIN_MENU);
jokers_available_to_shop_init();
// Initialize jokers list
@@ -2660,7 +2666,6 @@ void game_shop()
}
}
}
if (timer % 20 == 0)
{
@@ -2895,7 +2900,7 @@ void game_main_menu()
}
else if (key_hit(KEY_RIGHT))
{
if (selection_x < MAIN_MENU_BUTTONS)
if (selection_x < MAIN_MENU_IMPLEMENTED_BUTTONS)
{
selection_x++;
}
@@ -2936,7 +2941,6 @@ static void discarded_jokers_update_loop()
joker_object_destroy(&joker_object);
}
}
}
static void held_jokers_update_loop()
@@ -3005,6 +3009,9 @@ void game_update()
switch (game_state)
{
case GAME_SPLASH_SCREEN:
splash_screen_update(timer);
break;
case GAME_MAIN_MENU:
game_main_menu();
break;
-21
View File
@@ -18,10 +18,6 @@
#include "soundbank.h"
#include "soundbank_bin.h"
#define SPLASH_FPS 60
#define SPLASH_DURATION_SECONDS 10
#define SPLASH_DURATION_FRAMES (SPLASH_FPS * SPLASH_DURATION_SECONDS)
void init()
{
irq_init(NULL);
@@ -71,23 +67,6 @@ void init()
REG_DISPCNT = DCNT_MODE1 | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ | DCNT_WIN0 | DCNT_WIN1;
// Splash screen
tte_printf("#{P:72,8; cx:0xF000}DISCLAIMER");
tte_printf("#{P:8,24; cx:0xF000}This project is NOT endorsed \n by or affiliated with \n Playstack or LocalThunk.\n\n If you have paid for this, \n you have been scammed \n and should request a refund \n IMMEDIATELY. \n\n The only official place \n to obtain this is from: \n\n 'github.com/\n cellos51/balatro-gba'");
tte_printf("#{P:8,144; cx:0xF000}(Press any key to skip)");
for (int i = 0; i < SPLASH_DURATION_FRAMES; i++)
{
VBlankIntrWait();
key_poll();
if (key_hit(KEY_A | KEY_B | KEY_START | KEY_SELECT)) // Skip intro
{
break;
}
tte_erase_rect_wrapper((Rect){208, 144, 240, 152});
tte_printf("#{P:208,144; cx:0xF000}%d", 1 + (SPLASH_DURATION_FRAMES - i) / SPLASH_FPS);
}
tte_erase_screen();
// Initialize subsystems
mmInitDefault((mm_addr)soundbank_bin, 12);
mmStart(MOD_MAIN_THEME, MM_PLAY_LOOP);
+30
View File
@@ -0,0 +1,30 @@
#include "splash_screen.h"
#include <tonc.h>
#include "graphic_utils.h"
#include "game.h"
void splash_screen_init()
{
tte_printf("#{P:72,8; cx:0xF000}DISCLAIMER");
tte_printf("#{P:8,24; cx:0xF000}This project is NOT endorsed \n by or affiliated with \n Playstack or LocalThunk.\n\n If you have paid for this, \n you have been scammed \n and should request a refund \n IMMEDIATELY. \n\n The only official place \n to obtain this is from: \n\n 'github.com/\n cellos51/balatro-gba'");
tte_printf("#{P:8,144; cx:0xF000}(Press any key to skip)");
}
void splash_screen_update(uint timer)
{
if (timer < SPLASH_DURATION_FRAMES)
{
tte_erase_rect_wrapper((Rect){208, 144, 240, 152});
tte_printf("#{P:208,144; cx:0xF000}%d", 1 + (SPLASH_DURATION_FRAMES - timer) / SPLASH_FPS);
if (!key_hit(KEY_ANY))
{
return;
}
}
game_set_state(GAME_MAIN_MENU);
tte_erase_screen();
}