Fix restart visual bug

main
En Yi 2025-08-23 15:34:40 +08:00
parent 44a1eba4de
commit d8a84f6881
4 changed files with 22 additions and 5 deletions

1
main.c
View File

@ -44,6 +44,7 @@ int main(void)
register_keybind(&engine, KEY_SPACE, ACTION_JUMP); register_keybind(&engine, KEY_SPACE, ACTION_JUMP);
register_keybind(&engine, KEY_Q, ACTION_EXIT); register_keybind(&engine, KEY_Q, ACTION_EXIT);
register_keybind(&engine, KEY_Z, ACTION_LOOKAHEAD); register_keybind(&engine, KEY_Z, ACTION_LOOKAHEAD);
register_keybind(&engine, KEY_R, ACTION_RESTART);
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX); load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
load_sfx(&engine, "snd_land", PLAYER_LAND_SFX); load_sfx(&engine, "snd_land", PLAYER_LAND_SFX);

View File

@ -1,5 +1,6 @@
#include "tracy/TracyC.h" #include "tracy/TracyC.h"
#include "keymaps.h"
#include "scene_impl.h" #include "scene_impl.h"
#include "game_systems.h" #include "game_systems.h"
#include "water_flow.h" #include "water_flow.h"
@ -62,9 +63,10 @@ static void level_scene_render_func(Scene_t* scene)
air_pos.x -= 32; air_pos.x -= 32;
} }
} }
if (sc_map_size_64v(&scene->ent_manager.entities_map[PLAYER_ENT_TAG]) == 0) if (data->sm.state == LEVEL_STATE_DEAD)
{ {
DrawTextEx(*menu_font, "Press R to Try Again", (Vector2){32, data->game_rec.height/2 - 64}, 64, 4, WHITE); sprintf(buffer, "Press %s to Try Again", data->restart_keyname);
DrawTextEx(*menu_font, buffer, (Vector2){32, data->game_rec.height/2 - 64}, 64, 4, WHITE);
} }
// For DEBUG // For DEBUG
int gui_x = 5; int gui_x = 5;
@ -73,7 +75,7 @@ static void level_scene_render_func(Scene_t* scene)
DrawRectangle(0, 0, data->game_rec.width, 32, (Color){0,0,0,128}); DrawRectangle(0, 0, data->game_rec.width, 32, (Color){0,0,0,128});
{ {
DrawText("Z", 300, 5, 24, RED); DrawText(data->look_keyname, 300, 5, 24, RED);
Sprite_t* spr = get_sprite(&scene->engine->assets, "eye"); Sprite_t* spr = get_sprite(&scene->engine->assets, "eye");
if (data->camera.mode == CAMERA_RANGED_MOVEMENT) if (data->camera.mode == CAMERA_RANGED_MOVEMENT)
{ {
@ -527,9 +529,19 @@ static void game_action_remap_func(Scene_t* scene)
sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_RIGHT, KEY_RIGHT), ACTION_RIGHT); sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_RIGHT, KEY_RIGHT), ACTION_RIGHT);
sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_JUMP, KEY_ENTER), ACTION_JUMP); sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_JUMP, KEY_ENTER), ACTION_JUMP);
sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_EXIT, KEY_Q), ACTION_EXIT); sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_EXIT, KEY_Q), ACTION_EXIT);
sc_map_put_64(&scene->action_map, get_keybind_or_default(scene->engine, ACTION_LOOKAHEAD, KEY_Z), ACTION_LOOKAHEAD);
sc_map_put_64(&scene->action_map, KEY_R, ACTION_RESTART); LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
{
int restart_key = get_keybind_or_default(scene->engine, ACTION_RESTART, KEY_R);
data->restart_keyname = ExtGetKeyName(restart_key);
sc_map_put_64(&scene->action_map, restart_key, ACTION_RESTART);
}
{
int look_key = get_keybind_or_default(scene->engine, ACTION_LOOKAHEAD, KEY_Z);
data->look_keyname = ExtGetKeyName(look_key);
sc_map_put_64(&scene->action_map, look_key, ACTION_LOOKAHEAD);
}
} }
void init_game_scene(LevelScene_t* scene) void init_game_scene(LevelScene_t* scene)
@ -564,6 +576,7 @@ void init_game_scene(LevelScene_t* scene)
scene->data.sm.state_functions[LEVEL_STATE_RUNNING] = NULL; scene->data.sm.state_functions[LEVEL_STATE_RUNNING] = NULL;
scene->data.sm.state_functions[LEVEL_STATE_DEAD] = NULL; scene->data.sm.state_functions[LEVEL_STATE_DEAD] = NULL;
scene->data.sm.state_functions[LEVEL_STATE_COMPLETE] = at_level_complete; scene->data.sm.state_functions[LEVEL_STATE_COMPLETE] = at_level_complete;
scene->data.sm.state = LEVEL_STATE_STARTING;
scene->scene.bg_colour = LIGHTGRAY; scene->scene.bg_colour = LIGHTGRAY;
add_scene_layer( add_scene_layer(

View File

@ -72,6 +72,8 @@ typedef struct LevelSceneData {
Sprite_t* solid_tile_sprites; Sprite_t* solid_tile_sprites;
uint8_t selected_solid_tilemap; uint8_t selected_solid_tilemap;
LevelPack_t* level_pack; LevelPack_t* level_pack;
const char* restart_keyname;
const char* look_keyname;
unsigned int current_level; unsigned int current_level;
CoinCounter_t coins; CoinCounter_t coins;
bool show_grid; bool show_grid;

View File

@ -111,6 +111,7 @@ bool load_level_tilemap(LevelScene_t* scene, unsigned int level_num)
scene->data.tilemap.n_tiles = n_tiles; scene->data.tilemap.n_tiles = n_tiles;
scene->data.coins.current = 0; scene->data.coins.current = 0;
scene->data.coins.total = lvl_map.n_chests; scene->data.coins.total = lvl_map.n_chests;
scene->data.sm.state = LEVEL_STATE_STARTING;
#define N_SOLID_TILESETS 4 #define N_SOLID_TILESETS 4
static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = { static const char* SOLID_TILE_SELECTIONS[N_SOLID_TILESETS] = {