Refactor/shop (#475)
* initial commit, DOES NOT COMPILE * Rename joker interactions file to `joker_row` * IT'S WORKIIING (now to make it pretty lol) * fixed rebase issues * fix rebase + undo state machine changes * Document shop state functions * clang format * fix reroll cost not appearing on shop init * Move generic SpriteObject text/price printing functions to sprite.c + some minor fixes * Resolve weird defines/include order issue * clang format * Implement suggestions from @ricfehr3 * clang format * clang format * fix rebase * Implement sugegstions from @ricfehr3 * Refactored shop to use the Button struct * missed some memsets --------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
+2
-11
@@ -1,29 +1,20 @@
|
||||
#ifndef BLIND_H
|
||||
#define BLIND_H
|
||||
|
||||
#include "game.h"
|
||||
#include "sprite.h"
|
||||
|
||||
// The GBA's max uint value is around 4 billion, so we're going to not add endless mode for
|
||||
// simplicity's sake
|
||||
#define MAX_ANTE 8
|
||||
|
||||
#define NORMAL_BLIND_PB 1
|
||||
#define BOSS_BLIND_PB 2
|
||||
|
||||
#define BLIND_BASE_LAYER (MAX_HAND_SIZE + MAX_SELECTION_SIZE)
|
||||
// Sprite IDs of the various Blind Tokens used in the game, expressed as an offset
|
||||
// relative to `BLIND_BASE_LAYER`
|
||||
#define PLAYING_BLIND_TOKEN_LAYER 0
|
||||
#define ROUND_END_BLIND_TOKEN_LAYER 1
|
||||
#define SMALL_BLIND_TOKEN_LAYER 2
|
||||
#define BIG_BLIND_TOKEN_LAYER 3
|
||||
#define BOSS_BLIND_TOKEN_LAYER 4
|
||||
|
||||
#define BLIND_SPRITE_OFFSET 16
|
||||
#define BLIND_SPRITE_COPY_SIZE (BLIND_SPRITE_OFFSET * TILE_SIZE)
|
||||
|
||||
#define BLIND_TOKENS_PER_SPRITESHEET 2
|
||||
#define BLIND_TOKEN_PALETTE_SIZE 8
|
||||
|
||||
// The sprites that display the blinds when in "GAME_BLIND_SELECT" state
|
||||
// There are only 3 blinds per Ante, so we don't need more sprites than that
|
||||
enum BlindTokens
|
||||
|
||||
@@ -6,7 +6,7 @@ DEF_STATE_INFO(GAME_STATE_OPTIONS_MENU, game_options_menu_on_init, game_options
|
||||
DEF_STATE_INFO(GAME_STATE_GAME_START, noop, game_start, noop )
|
||||
DEF_STATE_INFO(GAME_STATE_PLAYING, game_round_on_init, game_playing_on_update, noop )
|
||||
DEF_STATE_INFO(GAME_STATE_ROUND_END, game_round_end_on_init, game_round_end_on_update, game_round_end_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_SHOP, noop, game_shop_on_update, game_shop_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_SHOP, game_shop_on_init, game_shop_on_update, game_shop_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_BLIND_SELECT, game_blind_select_on_init, game_blind_select_on_update, game_blind_select_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_LOSE, game_lose_on_init, game_over_on_update, game_over_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_WIN, game_win_on_init, game_over_on_update, game_over_on_exit )
|
||||
|
||||
+11
-12
@@ -1,7 +1,9 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include "bitset.h"
|
||||
#include "game/common_ui.h"
|
||||
#include "game_variables.h"
|
||||
#include "graphic_utils.h"
|
||||
|
||||
#include <tonc.h>
|
||||
@@ -39,6 +41,9 @@ typedef struct CardObject CardObject;
|
||||
typedef struct Card Card;
|
||||
typedef struct JokerObject JokerObject;
|
||||
|
||||
typedef void (*GameStateCallback)(void);
|
||||
typedef void (*SubStateActionFn)(void);
|
||||
|
||||
// Enum value names in ../include/def_state_info_table.h
|
||||
enum GameState
|
||||
{
|
||||
@@ -121,17 +126,6 @@ typedef struct ContainedHandTypes
|
||||
} ContainedHandTypes;
|
||||
// clang-format on
|
||||
|
||||
typedef void (*GameStateCallback)(void);
|
||||
typedef void (*SubStateActionFn)(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int substate;
|
||||
GameStateCallback on_init;
|
||||
GameStateCallback on_update;
|
||||
GameStateCallback on_exit;
|
||||
} StateInfo;
|
||||
|
||||
// Game functions
|
||||
void game_init();
|
||||
|
||||
@@ -156,8 +150,14 @@ int get_played_top(void);
|
||||
int get_scored_card_index(void);
|
||||
bool is_joker_owned(int joker_id);
|
||||
bool card_is_face(Card* card);
|
||||
void add_joker(JokerObject* joker_object);
|
||||
void remove_owned_joker(int owned_joker_idx);
|
||||
List* get_jokers_list(void);
|
||||
List* get_expired_jokers_list(void);
|
||||
List* get_discarded_jokers_list(void);
|
||||
List* get_shop_jokers_list(void);
|
||||
Bitset* get_avail_jokers_bitset(void);
|
||||
void set_shop_joker_avail(int joker_id, bool avail);
|
||||
|
||||
ContainedHandTypes* get_contained_hands(void);
|
||||
enum HandType* get_hand_type(void);
|
||||
@@ -189,7 +189,6 @@ void game_start(void);
|
||||
void change_background_legacy(enum BackgroundId id);
|
||||
|
||||
void display_round(void);
|
||||
void reset_top_left_panel_bottom_row(void);
|
||||
|
||||
void reset_background(void);
|
||||
void display_hands(void);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file joker_row.h
|
||||
*
|
||||
* @brief All the functions used specifically to interact with Jokers.
|
||||
* This includes browsing, swapping, selling, etc.
|
||||
*/
|
||||
#ifndef GAME_JOKER_ROW_H
|
||||
#define GAME_JOKER_ROW_H
|
||||
|
||||
#include "selection_grid.h"
|
||||
|
||||
/**
|
||||
* @brief Returns the size of the Jokers' row at the top of the game screen.
|
||||
* Is equal to the number of Jokers owned.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int jokers_sel_row_get_size(void);
|
||||
|
||||
/**
|
||||
* @brief Handle directional inputs on the Jokers' row at the top of the game screen.
|
||||
*
|
||||
* @param selection_grid pointer to the SelectionGrid the row is a part of.
|
||||
* @param row_idx index of the row this function is called on.
|
||||
* @param prev_selection pointer to the coordinates of the previously selected button
|
||||
* in `selection_grid`
|
||||
* @param new_selection pointer to the coordinates of the newly selected button in
|
||||
* `selection_grid`
|
||||
* @return bool
|
||||
*/
|
||||
bool jokers_sel_row_on_selection_changed(
|
||||
SelectionGrid* selection_grid,
|
||||
int row_idx,
|
||||
const Selection* prev_selection,
|
||||
const Selection* new_selection
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Handle button inputs on the Jokers' row at the top of the game screen.
|
||||
*
|
||||
* @param selection_grid pointer to the SelectionGrid the row is a part of.
|
||||
* @param selection pointer to the coordinates of the currently selected button in
|
||||
* `selection_grid`
|
||||
*/
|
||||
void jokers_sel_row_on_key_transit(SelectionGrid* selection_grid, Selection* selection);
|
||||
|
||||
#endif // GAME_JOKER_ROW_H
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file shop.h
|
||||
*
|
||||
* @brief Shop state functions.
|
||||
*/
|
||||
#ifndef GAME_SHOP_H
|
||||
#define GAME_SHOP_H
|
||||
|
||||
/**
|
||||
* @brief Change to the shop background
|
||||
*/
|
||||
void game_shop_change_background(void);
|
||||
|
||||
/**
|
||||
* @brief Shop state initialization
|
||||
*/
|
||||
void game_shop_on_init(void);
|
||||
|
||||
/**
|
||||
* @brief Shop state update
|
||||
*/
|
||||
void game_shop_on_update(void);
|
||||
|
||||
/**
|
||||
* @brief Shop cleanup
|
||||
*/
|
||||
void game_shop_on_exit(void);
|
||||
|
||||
#endif // GAME_SHOP_H
|
||||
@@ -13,6 +13,8 @@
|
||||
static const BG_POINT CUR_BLIND_TOKEN_POS = {8, 18};
|
||||
static const BG_POINT TOP_LEFT_PANEL_POINT = {0, 0};
|
||||
static const BG_POINT ROUND_END_REWARDS_ELLIPSIS_POS = {10, 13};
|
||||
static const BG_POINT JOKER_DISCARD_TARGET = {240, 30};
|
||||
static const BG_POINT HELD_JOKERS_POS = {108, 10};
|
||||
// Rects left top right bottom
|
||||
static const Rect TOP_LEFT_PANEL_ANIM_RECT = {0, 0, 8, 4};
|
||||
static const Rect POP_MENU_ANIM_RECT = {9, 7, 24, 31};
|
||||
|
||||
@@ -317,6 +317,37 @@ bool sprite_object_get_width(SpriteObject* sprite_object, int* width);
|
||||
*/
|
||||
bool sprite_object_is_focused(SpriteObject* sprite_object);
|
||||
|
||||
/**
|
||||
* @brief Print the given string directly beneath a SpriteObject.
|
||||
* This is used only for Cards for now.
|
||||
*
|
||||
* @param sprite_object valid pointer to SpriteObject to check
|
||||
* @param text the string to be printed below the sprite
|
||||
*/
|
||||
void sprite_object_print_text_under(SpriteObject* sprite_object, const char text[]);
|
||||
|
||||
/**
|
||||
* @brief Print the price string directly beneath a SpriteObject.
|
||||
* More specialized version of sprite_object_print_text_under,
|
||||
* automatically formats the price to `$%d`.
|
||||
*
|
||||
* @param sprite_object valid pointer to SpriteObject to check
|
||||
* @param price the price of the card to be printed
|
||||
*
|
||||
* @sa sprite_object_print_text_under
|
||||
*/
|
||||
void sprite_object_print_price_under(SpriteObject* sprite_object, int price);
|
||||
|
||||
/**
|
||||
* @brief Erase the text within the Rect directly beneath a SpriteObject.
|
||||
* This is used only for Cards for now.
|
||||
*
|
||||
* @param sprite_object valid pointer to SpriteObject to check
|
||||
*
|
||||
* @sa sprite_object_print_text_under
|
||||
*/
|
||||
void sprite_object_erase_text_under(SpriteObject* sprite_object);
|
||||
|
||||
/**
|
||||
* @brief Set sprite position. Inlined for efficiency
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user