From 7bafc260dd9fdcaef42eb0def16037d277fce222 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 22 Sep 2025 22:04:51 -0700 Subject: [PATCH] fixed game_speed, now using fixed point and keeping game_speed static --- include/game.h | 5 ++--- source/game.c | 14 ++++++++++++-- source/sprite.c | 9 +++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/game.h b/include/game.h index 09caf9c..8a2892c 100644 --- a/include/game.h +++ b/include/game.h @@ -98,8 +98,7 @@ int get_deck_top(void); int get_num_discards_remaining(void); int get_money(void); -extern int game_speed; // had to do this use this it the sprites animations - // that were not affected by game_speed, like discard - // and draw-to-deck animations. +int get_game_speed(void); +void set_game_speed(int game_speed_); #endif // GAME_H diff --git a/source/game.c b/source/game.c index e5e53b8..5ec270b 100644 --- a/source/game.c +++ b/source/game.c @@ -32,7 +32,7 @@ static uint rng_seed = 0; static uint timer = 0; // This might already exist in libtonc but idk so i'm just making my own -int game_speed = 1; // BY DEFAULT IS ON 1, but if changed to 2, should speed up all (or most) of the game aspects that should be sped up by speed, as in the original game. +static int game_speed = 1; // BY DEFAULT IS SET TO 1, but if changed to 2 - 8, should speed up all (or most) of the game aspects that should be sped up by speed, as in the original game. static int background = 0; 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 @@ -182,6 +182,16 @@ int get_num_discards_remaining(void) { int get_money(void) { return money; } +int get_game_speed(void) +{ + return game_speed; +} + +// for the future when a menu actually lets this variable be changed. +void set_game_speed(int game_speed) +{ + game_speed = game_speed; +} // Consts @@ -1269,7 +1279,7 @@ static void game_playing_process_input_and_state() if (mult > 0) { temp_score = chips * mult; - lerped_temp_score = (float)(1.0f / game_speed) * int2fx(temp_score); // game speed affects how fast the score text increases. + lerped_temp_score = fx2int(fxdiv(int2fx(1), int2fx(game_speed)) * int2fx(temp_score)); // game speed affects how fast the score text increases. lerped_score = int2fx(score); display_temp_score(temp_score); diff --git a/source/sprite.c b/source/sprite.c index d3f2cd8..199b2ab 100644 --- a/source/sprite.c +++ b/source/sprite.c @@ -158,9 +158,14 @@ void sprite_object_reset_transform(SpriteObject* sprite_object) void sprite_object_update(SpriteObject* sprite_object) { - sprite_object->vx += (sprite_object->tx - sprite_object->x) / (8 / game_speed); // SPEED - sprite_object->vy += (sprite_object->ty - sprite_object->y) / (8 / game_speed); + sprite_object->vx += (sprite_object->tx - sprite_object->x) / (8 / get_game_speed()); // SPEED + sprite_object->vy += (sprite_object->ty - sprite_object->y) / (8 / get_game_speed()); // this makes the game_speed not be + // able to be more than 8, because of + //integer division making it a divide by 0. + // shouldn't be a problem since speed 9 or more + // is way too much lol. + sprite_object->vscale += (sprite_object->tscale - sprite_object->scale) / 8; // Scale up the card when it's played sprite_object->vrotation += (sprite_object->trotation - sprite_object->rotation) / 8; // Rotate the card when it's played