Add initial option scene

main
En Yi 2025-08-18 21:46:17 +08:00
parent c2f673f5b8
commit bc5c88beb7
6 changed files with 99 additions and 7 deletions

10
main.c
View File

@ -64,9 +64,9 @@ int main(void)
load_sfx(&engine, "snd_launch", ARROW_RELEASE_SFX); load_sfx(&engine, "snd_launch", ARROW_RELEASE_SFX);
load_sfx(&engine, "snd_launch", BOMB_RELEASE_SFX); load_sfx(&engine, "snd_launch", BOMB_RELEASE_SFX);
LevelScene_t sandbox_scene; OptionScene_t options_scene;
sandbox_scene.scene.engine = &engine; options_scene.scene.engine = &engine;
init_sandbox_scene(&sandbox_scene); init_options_scene(&options_scene);
LevelScene_t level_scene; LevelScene_t level_scene;
level_scene.scene.engine = &engine; level_scene.scene.engine = &engine;
@ -99,7 +99,7 @@ int main(void)
scenes[MAIN_MENU_SCENE] = &menu_scene.scene; scenes[MAIN_MENU_SCENE] = &menu_scene.scene;
scenes[LEVEL_SELECT_SCENE] = &level_sel_scene.scene; scenes[LEVEL_SELECT_SCENE] = &level_sel_scene.scene;
scenes[GAME_SCENE] = &level_scene.scene; scenes[GAME_SCENE] = &level_scene.scene;
scenes[SANDBOX_SCENE] = &sandbox_scene.scene; scenes[OPTIONS_SCENE] = &options_scene.scene;
change_scene(&engine, MAIN_MENU_SCENE); change_scene(&engine, MAIN_MENU_SCENE);
const float DT = 1.0f/60.0f; const float DT = 1.0f/60.0f;
@ -130,7 +130,7 @@ int main(void)
sc_queue_clear(&key_buffer); sc_queue_clear(&key_buffer);
} }
} }
free_sandbox_scene(&sandbox_scene); free_options_scene(&options_scene);
free_game_scene(&level_scene); free_game_scene(&level_scene);
free_level_select_scene(&level_sel_scene); free_level_select_scene(&level_sel_scene);
free_menu_scene(&menu_scene); free_menu_scene(&menu_scene);

View File

@ -5,6 +5,7 @@ add_library(lib_scenes STATIC
water_flow.c water_flow.c
editor_scene.c editor_scene.c
menu_scene.c menu_scene.c
options_scene.c
level_select_scene.c level_select_scene.c
game_scene.c game_scene.c
game_systems.c game_systems.c

View File

@ -44,7 +44,7 @@ typedef enum SceneType {
MAIN_MENU_SCENE = 0, MAIN_MENU_SCENE = 0,
LEVEL_SELECT_SCENE, LEVEL_SELECT_SCENE,
GAME_SCENE, GAME_SCENE,
SANDBOX_SCENE, OPTIONS_SCENE,
}SceneType_t; }SceneType_t;
#endif #endif

View File

@ -23,7 +23,7 @@ static void menu_scene_render_func(Scene_t* scene)
}; };
DrawTextEx(*menu_font, "Bunny's Spelunking Adventure", title_pos, 56, 0, BLACK); DrawTextEx(*menu_font, "Bunny's Spelunking Adventure", title_pos, 56, 0, BLACK);
const char* OPTIONS[3] = {"Start", "Credits", "Exit"}; const char* OPTIONS[3] = {"Start", "Options", "Exit"};
for (uint8_t i = 0; i < 3; ++i) for (uint8_t i = 0; i < 3; ++i)
{ {
Vector2 pos = (Vector2){data->buttons[i].bbox.x, data->buttons[i].bbox.y}; Vector2 pos = (Vector2){data->buttons[i].bbox.x, data->buttons[i].bbox.y};
@ -55,6 +55,9 @@ static void exec_component_function(Scene_t* scene, int sel)
case 0: case 0:
change_scene(scene->engine, LEVEL_SELECT_SCENE); change_scene(scene->engine, LEVEL_SELECT_SCENE);
break; break;
case 1:
change_scene(scene->engine, OPTIONS_SCENE);
break;
case 2: case 2:
scene->state = 0; scene->state = 0;
break; break;

View File

@ -0,0 +1,72 @@
#include "scene_impl.h"
#include "assets_tag.h"
#include <stdio.h>
static void options_scene_render_func(Scene_t* scene)
{
//OptionSceneData_t* data = &(CONTAINER_OF(scene, OptionScene_t, scene)->data);
int key;
ActionType_t action;
char buffer[16];
int y_offset = 16;
BeginTextureMode(scene->layers.render_layers[0].layer_tex);
sc_map_foreach(&scene->engine->keybinds, action, key) {
sprintf(buffer, "Action %d : %d", action, key);
DrawText(buffer, 32, y_offset, 12, WHITE);
y_offset += 12;
}
float vol = GetMasterVolume();
sprintf(buffer, "Volume : %.1f", vol);
DrawText(buffer, 32, y_offset, 12, WHITE);
EndTextureMode();
}
static void options_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{
switch(action)
{
case ACTION_EXIT:
if (!pressed)
{
if(scene->engine != NULL)
{
change_scene(scene->engine, MAIN_MENU_SCENE);
}
}
break;
default:
break;
}
}
void init_options_scene(OptionScene_t* scene)
{
init_scene(&scene->scene, &options_do_action, 0);
scene->scene.bg_colour = BLACK;
add_scene_layer(
&scene->scene, scene->scene.engine->intended_window_size.x,
scene->scene.engine->intended_window_size.y,
(Rectangle){
0, 0,
scene->scene.engine->intended_window_size.x,
scene->scene.engine->intended_window_size.y
}
);
sc_array_add(&scene->scene.systems, &options_scene_render_func);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_UP, KEY_UP), ACTION_UP);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_DOWN, KEY_DOWN), ACTION_DOWN);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_LEFT, KEY_LEFT), ACTION_LEFT);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_RIGHT, KEY_RIGHT), ACTION_RIGHT);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_JUMP, KEY_ENTER), ACTION_CONFIRM);
sc_map_put_64(&scene->scene.action_map, get_keybind_or_default(scene->scene.engine, ACTION_EXIT, KEY_Q), ACTION_EXIT);
sc_map_put_64(&scene->scene.action_map, KEY_BACKSPACE, ACTION_EXIT);
}
void free_options_scene(OptionScene_t* scene)
{
free_scene(&scene->scene);
}

View File

@ -134,9 +134,25 @@ typedef struct LevelSelectScene {
Scene_t scene; Scene_t scene;
LevelSelectSceneData_t data; LevelSelectSceneData_t data;
} LevelSelectScene_t; } LevelSelectScene_t;
enum OptionSceneMode {
OPTIONS_NORMAL_MODE,
OPTIONS_KEYBIND_MODE,
};
typedef struct OptionSceneData {
}OptionSceneData_t;
typedef struct OptionScene {
Scene_t scene;
OptionSceneData_t data;
}OptionScene_t;
void init_menu_scene(MenuScene_t* scene); void init_menu_scene(MenuScene_t* scene);
void free_menu_scene(MenuScene_t* scene); void free_menu_scene(MenuScene_t* scene);
void init_level_select_scene(LevelSelectScene_t* scene); void init_level_select_scene(LevelSelectScene_t* scene);
void free_level_select_scene(LevelSelectScene_t* scene); void free_level_select_scene(LevelSelectScene_t* scene);
void init_options_scene(OptionScene_t* scene);
void free_options_scene(OptionScene_t* scene);
#endif // __SCENE_IMPL_H #endif // __SCENE_IMPL_H