GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
blind.c File Reference

Implementation of functions relative to the behaviour and graphics of Blinds. More...

#include "blind.h"
#include "blind_gfx.h"
#include "game.h"
#include "graphic_utils.h"
#include "hand.h"
#include "list.h"
#include "random.h"
#include "stdbool.h"
#include "util.h"
#include <stdlib.h>
#include <tonc.h>
#include "../include/def_blind_gfx_table.h"

Go to the source code of this file.

Macros

#define NORMAL_BLIND_PB   2
 
#define BOSS_BLIND_PB   3
 
#define BLIND_BASE_LAYER   (MAX_HAND_SIZE + MAX_SELECTION_SIZE)
 
#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
 
#define SMALL_BLIND_REWARD   3
 
#define BIG_BLIND_REWARD   4
 
#define BOSS_BLIND_REWARD   5
 
#define SHOWDOWN_BLIND_REWARD   8
 
#define DEF_BLIND_GFX(idx)   blind_gfx##idx##Tiles,
 
#define DEF_BLIND_GFX(idx)   blind_gfx##idx##Pal,
 

Functions

void blind_init ()
 
u32 blind_get_requirement (enum BlindType type, int ante)
 Get the score required to beat a certain blind (either the Small, Big, or any Boss/Showdown blind) at a certain Ante.
 
int blind_get_reward (enum BlindType type)
 Get the amount of money gained from beating a certain Blind.
 
static void init_unbeaten_blinds_list (bool showdown)
 Fill Lists of unbeaten Boss and Showdown Blinds.
 
void init_unbeaten_blinds_lists (void)
 Initialize Boss and Showdown Blinds lists to roll from.
 
enum BlindType roll_blind_type (bool showdown)
 Choose a random Blind among the ones that haven't been beaten yet.
 
void set_blind_beaten (enum BlindType type)
 Remove the given Blind from the corresponding List so that we don't roll it again in the future.
 
static u32 get_blind_pb (enum BlindType type)
 
static u32 get_blind_spritesheet_idx (enum BlindType type)
 
u16 blind_get_color (enum BlindType type, enum BlindColorIndex index)
 Get the color associated with a given Blind.
 
void apply_blind_colors (enum BlindType type)
 Copy the palette associated with the given Blind and copy it in the right spot in the palette memory.
 
static u32 get_layer_tile_index (enum BlindTokenLayers layer)
 Get the starting tile index in tiles memory for the given BlindToken sprite layer.
 
void apply_blind_tiles (enum BlindType type, enum BlindTokenLayers layer)
 Change the tiles of the BlindToken Sprite at a given layer to that of the given BlindType.
 
Spriteblind_token_new (enum BlindType type, int x, int y, enum BlindTokenLayers layer)
 Create a new BlindToken sprite.
 

Variables

static const unsigned int * blind_gfxTiles []
 
static const unsigned short * blind_gfxPal []
 
static List s_unbeaten_boss_blinds = LIST_DEFAULT
 
static List s_unbeaten_showdown_blinds = LIST_DEFAULT
 
static const u32 ANTE_LUT [] = {100, 300, 800, 2000, 5000, 11000, 20000, 35000, 50000}
 
static Blind s_blind_type_map [BLIND_TYPE_MAX]
 Stores an instance of the Blind struct for each BlindType value, ordered in the same way. Acts the same way the Joker registry does, and may need to go in its own file depending on how Blind effects are implemented.
 

Detailed Description

Implementation of functions relative to the behaviour and graphics of Blinds.

Definition in file blind.c.

Macro Definition Documentation

◆ BIG_BLIND_REWARD

#define BIG_BLIND_REWARD   4

Definition at line 32 of file blind.c.

◆ BLIND_BASE_LAYER

#define BLIND_BASE_LAYER   (MAX_HAND_SIZE + MAX_SELECTION_SIZE)

Definition at line 23 of file blind.c.

◆ BLIND_SPRITE_COPY_SIZE

#define BLIND_SPRITE_COPY_SIZE   (BLIND_SPRITE_OFFSET * TILE_SIZE)

Definition at line 26 of file blind.c.

◆ BLIND_SPRITE_OFFSET

#define BLIND_SPRITE_OFFSET   16

Definition at line 25 of file blind.c.

◆ BLIND_TOKEN_PALETTE_SIZE

#define BLIND_TOKEN_PALETTE_SIZE   8

Definition at line 29 of file blind.c.

◆ BLIND_TOKENS_PER_SPRITESHEET

#define BLIND_TOKENS_PER_SPRITESHEET   2

Definition at line 28 of file blind.c.

◆ BOSS_BLIND_PB

#define BOSS_BLIND_PB   3

Definition at line 21 of file blind.c.

◆ BOSS_BLIND_REWARD

#define BOSS_BLIND_REWARD   5

Definition at line 33 of file blind.c.

◆ NORMAL_BLIND_PB

#define NORMAL_BLIND_PB   2

Definition at line 20 of file blind.c.

◆ SHOWDOWN_BLIND_REWARD

#define SHOWDOWN_BLIND_REWARD   8

Definition at line 34 of file blind.c.

◆ SMALL_BLIND_REWARD

#define SMALL_BLIND_REWARD   3

Definition at line 31 of file blind.c.

Function Documentation

◆ apply_blind_colors()

void apply_blind_colors ( enum BlindType  type)

Copy the palette associated with the given Blind and copy it in the right spot in the palette memory.

Parameters
typeof the Blind whose palette we need

Definition at line 232 of file blind.c.

◆ apply_blind_tiles()

void apply_blind_tiles ( enum BlindType  type,
enum BlindTokenLayers  layer 
)

Change the tiles of the BlindToken Sprite at a given layer to that of the given BlindType.

Parameters
typeof the Blind we want to apply the tiles of.
layerthe Sprite will be located at.
See also
BlindTokenLayers

Definition at line 268 of file blind.c.

◆ blind_get_color()

u16 blind_get_color ( enum BlindType  type,
enum BlindColorIndex  index 
)

Get the color associated with a given Blind.

Parameters
typethe BlindType whose palette will be used
indexof the color within the Blind's palette
Returns
the BGR555 value of the requested color

Definition at line 218 of file blind.c.

◆ blind_get_requirement()

u32 blind_get_requirement ( enum BlindType  type,
int  ante 
)

Get the score required to beat a certain blind (either the Small, Big, or any Boss/Showdown blind) at a certain Ante.

Parameters
typethe BlindType value of the blind we need the score requirement of
antethe Ante at which the blind type is encountered
Returns
the required score to beat the requested blind

Definition at line 106 of file blind.c.

◆ blind_get_reward()

int blind_get_reward ( enum BlindType  type)

Get the amount of money gained from beating a certain Blind.

Parameters
typethe BlindType of the beaten Blind
Returns
3 for the Small Blind, 4 for the Big one, 5 for Bosses and 8 for Showdowns

Definition at line 115 of file blind.c.

◆ blind_init()

void blind_init ( )

Definition at line 97 of file blind.c.

◆ blind_token_new()

Sprite * blind_token_new ( enum BlindType  type,
int  x,
int  y,
enum BlindTokenLayers  sprite_index 
)

Create a new BlindToken sprite.

Parameters
typeof the Blind the token needs to represent
xinitial position of the new Sprite on the horizontal axis
yinitial position of the new Sprite on the vertical axis
sprite_indexlayer of the new Sprite
See also
BlindTokenLayers

Definition at line 281 of file blind.c.

◆ get_blind_pb()

static u32 get_blind_pb ( enum BlindType  type)
static

Definition at line 205 of file blind.c.

◆ get_blind_spritesheet_idx()

static u32 get_blind_spritesheet_idx ( enum BlindType  type)
static

Definition at line 210 of file blind.c.

◆ get_layer_tile_index()

static u32 get_layer_tile_index ( enum BlindTokenLayers  layer)
static

Get the starting tile index in tiles memory for the given BlindToken sprite layer.

Parameters
layerof the BlindToken, as an offset relative to BLIND_BASE_LAYER
Returns
the starting tile index of the BlindToken sprite at requested layer
See also
BLIND_BASE_LAYER

Definition at line 262 of file blind.c.

◆ init_unbeaten_blinds_list()

static void init_unbeaten_blinds_list ( bool  showdown)
static

Fill Lists of unbeaten Boss and Showdown Blinds.

    By keeping track of what Blind we have beaten or not, we can ensure that until we've
    beaten all the Blinds in a single Run, we won't encounter the same one twice.

This must be called at the beginning of a run.

Parameters
showdowntoggle between the List for Showdown and regular Boss Blinds

Definition at line 140 of file blind.c.

◆ init_unbeaten_blinds_lists()

void init_unbeaten_blinds_lists ( void  )

Initialize Boss and Showdown Blinds lists to roll from.

Definition at line 156 of file blind.c.

◆ roll_blind_type()

enum BlindType roll_blind_type ( bool  showdown)

Choose a random Blind among the ones that haven't been beaten yet.

Parameters
showdownwhether we want to roll a Showdown or a regular Boss Blind.
Returns
a BlindType value chosen at random

Definition at line 162 of file blind.c.

◆ set_blind_beaten()

void set_blind_beaten ( enum BlindType  type)

Remove the given Blind from the corresponding List so that we don't roll it again in the future.

Parameters
typethe BlindType of the Boss/Showdown Blind we've just beaten.

Definition at line 180 of file blind.c.

Variable Documentation

◆ ANTE_LUT

const u32 ANTE_LUT[] = {100, 300, 800, 2000, 5000, 11000, 20000, 35000, 50000}
static

Definition at line 55 of file blind.c.

◆ blind_gfxPal

const unsigned short* blind_gfxPal[]
static
Initial value:
= {
#define DEF_BLIND_GFX(idx)
}

Definition at line 42 of file blind.c.

◆ blind_gfxTiles

const unsigned int* blind_gfxTiles[]
static
Initial value:
= {
#define DEF_BLIND_GFX(idx)
}

Definition at line 36 of file blind.c.

◆ s_blind_type_map

Blind s_blind_type_map[BLIND_TYPE_MAX]
static

Stores an instance of the Blind struct for each BlindType value, ordered in the same way. Acts the same way the Joker registry does, and may need to go in its own file depending on how Blind effects are implemented.

Definition at line 63 of file blind.c.

◆ s_unbeaten_boss_blinds

List s_unbeaten_boss_blinds = LIST_DEFAULT
static

Definition at line 49 of file blind.c.

◆ s_unbeaten_showdown_blinds

List s_unbeaten_showdown_blinds = LIST_DEFAULT
static

Definition at line 50 of file blind.c.