GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
joker_row.c
1#include "game/joker_row.h"
2
3#include "game.h"
4#include "game_variables.h"
5#include "joker.h"
6#include "layout.h"
7#include "list.h"
8#include "sprite.h"
9#include "util.h"
10
12{
13 return list_get_len(get_jokers_list());
14}
15
17 SelectionGrid* selection_grid,
18 int row_idx,
19 const Selection* prev_selection,
20 const Selection* new_selection
21)
22{
23 List* owned_jokers_list = get_jokers_list();
24
25 // swap Jokers if the A button is held down and all Jokers are on the same row
26 bool swapping =
27 key_is_down(SELECT_CARD) && new_selection->y == row_idx && prev_selection->y == row_idx;
28
29 if (prev_selection->y == row_idx)
30 {
31 JokerObject* joker_object =
32 (JokerObject*)list_get_at_idx(owned_jokers_list, prev_selection->x);
33 // Don't change focus from current Joker if swapping
34 if (joker_object != NULL && !swapping)
35 {
37 sprite_object_set_focus((SpriteObject*)joker_object, false);
38 }
39 }
40
41 if (new_selection->y == row_idx)
42 {
43 JokerObject* joker_object =
44 (JokerObject*)list_get_at_idx(owned_jokers_list, new_selection->x);
45 if (joker_object != NULL)
46 {
47 if (!swapping)
48 {
49 sprite_object_set_focus((SpriteObject*)joker_object, true);
50 }
51 // If we land on this row while the A button is being held, we are in swapping mode
52 // This means that we need to hide the price, whether we were already
53 // on this row or if we come from another
54 if (!key_is_down(SELECT_CARD))
55 {
57 (SpriteObject*)joker_object,
58 joker_get_sell_value(joker_object->joker)
59 );
60 }
61 }
62 }
63
64 if (swapping)
65 {
67 owned_jokers_list,
68 (unsigned int)prev_selection->x,
69 (unsigned int)new_selection->x
70 );
71 }
72
73 return true;
74}
75
76static inline void joker_start_discard_animation(JokerObject* joker_object)
77{
78 joker_object->tx = int2fx(JOKER_DISCARD_TARGET.x);
79 joker_object->ty = int2fx(JOKER_DISCARD_TARGET.y);
80 list_push_back(get_discarded_jokers_list(), joker_object);
81}
82
83static inline void game_sell_joker(int joker_idx)
84{
85 List* owned_jokers_list = get_jokers_list();
86
87 if (joker_idx < 0 || joker_idx >= list_get_len(owned_jokers_list))
88 return;
89
90 JokerObject* joker_object = (JokerObject*)list_get_at_idx(owned_jokers_list, joker_idx);
91 g_game_vars.money += joker_get_sell_value(joker_object->joker);
92 display_money();
94
95 remove_owned_joker(joker_idx);
96
97 joker_start_discard_animation(joker_object);
98}
99
100void jokers_sel_row_on_key_transit(SelectionGrid* selection_grid, Selection* selection)
101{
102 JokerObject* joker_object = (JokerObject*)list_get_at_idx(get_jokers_list(), selection->x);
103 if (joker_object != NULL)
104 {
105 if (key_hit(SELECT_CARD))
106 {
108 }
109 else if (key_released(SELECT_CARD))
110 {
112 (SpriteObject*)joker_object,
113 joker_get_sell_value(joker_object->joker)
114 );
115 }
116 }
117
118 if (key_hit(SELL_KEY))
119 {
120 int sold_joker_idx = selection->x;
121
122 // Move the selection away from the jokers so it doesn't point to an invalid place
123 // Do this before selling the joker so valid row sizes are used
124 selection_grid_move_selection_vert(selection_grid, SCREEN_DOWN);
125
126 game_sell_joker(sold_joker_idx);
127 }
128}
Game global game variables struct definition.
Functions relative to the handling of Jokers.
All the functions used specifically to interact with Jokers. This includes browsing,...
bool jokers_sel_row_on_selection_changed(SelectionGrid *selection_grid, int row_idx, const Selection *prev_selection, const Selection *new_selection)
Handle directional inputs on the Jokers' row at the top of the game screen.
Definition joker_row.c:16
void jokers_sel_row_on_key_transit(SelectionGrid *selection_grid, Selection *selection)
Handle button inputs on the Jokers' row at the top of the game screen.
Definition joker_row.c:100
int jokers_sel_row_get_size(void)
Returns the size of the Jokers' row at the top of the game screen. Is equal to the number of Jokers o...
Definition joker_row.c:11
Header of shared rects and points needed for ui.
A doubly-linked list.
bool list_swap(List *list, unsigned int idx_a, unsigned int idx_b)
Definition list.c:148
void * list_get_at_idx(List *list, unsigned int idx)
Definition list.c:219
int list_get_len(const List *list)
Definition list.c:214
void list_push_back(List *list, void *data)
Definition list.c:89
void selection_grid_move_selection_vert(SelectionGrid *selection_grid, int direction_tribool)
Moves the selection vertically within the selection grid.
Sprite system for Gbalatro.
void sprite_object_set_focus(SpriteObject *sprite_object, bool focus)
Set the focus for SpriteObject Raises the object by SPRITE_FOCUS_RAISE_PX.
Definition sprite.c:370
void sprite_object_print_price_under(SpriteObject *sprite_object, int price)
Print the price string directly beneath a SpriteObject. More specialized version of sprite_object_pri...
Definition sprite.c:447
void sprite_object_erase_text_under(SpriteObject *sprite_object)
Erase the text within the Rect directly beneath a SpriteObject. This is used only for Cards for now.
Definition sprite.c:457
A doubly-linked list.
Definition list.h:61
The core selection grid struct, represents the grid itself and its state.
A sprite object is a sprite that is focusable and movable in animation.
Definition sprite.h:61
Utilities relating around number string representation and protected arithmatic helper functions.