Add Sandbox button in main program

Changelog:
- First button now loads the levelpack
scene_man
En Yi 2023-08-14 21:54:25 +08:00
parent e670af2519
commit bba12b9b39
6 changed files with 37 additions and 21 deletions

18
main.c
View File

@ -4,12 +4,12 @@
#include "ent_impl.h"
#include "mempool.h"
#include <stdio.h>
#define N_SCENES 3
#define N_SCENES 4
Scene_t *scenes[N_SCENES];
static GameEngine_t engine = {
.scenes = scenes,
.max_scenes = 2,
.max_scenes = 3,
.curr_scene = 0,
.assets = {0}
};
@ -33,9 +33,13 @@ int main(void)
load_from_infofile("res/assets.info", &engine.assets);
init_player_creation("res/player_spr.info", &engine.assets);
LevelScene_t sandbox_scene;
sandbox_scene.scene.engine = &engine;
init_sandbox_scene(&sandbox_scene);
LevelScene_t level_scene;
level_scene.scene.engine = &engine;
init_sandbox_scene(&level_scene);
init_game_scene(&level_scene);
LevelPack_t* pack = get_level_pack(&engine.assets, "TestLevels");
if (pack != NULL)
{
@ -49,12 +53,9 @@ int main(void)
init_menu_scene(&menu_scene);
scenes[0] = &menu_scene.scene;
scenes[1] = &level_scene.scene;
scenes[2] = &sandbox_scene.scene;
change_scene(&engine, 0);
//Camera2D camera = { 0 };
//camera.offset = (Vector2){0,0};
//camera.rotation = 0.0f;
//camera.zoom = 1.0f;
while (!WindowShouldClose())
{
// This entire key processing relies on the assumption that a pressed key will
@ -99,7 +100,8 @@ int main(void)
sc_queue_clear(&key_buffer);
}
}
free_sandbox_scene(&level_scene);
free_sandbox_scene(&sandbox_scene);
free_game_scene(&level_scene);
free_menu_scene(&menu_scene);
sc_queue_term(&key_buffer);
term_assets(&engine.assets);

View File

@ -719,7 +719,7 @@ static void restart_editor_level(Scene_t* scene)
}
}
void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{
CPlayerState_t* p_playerstate;
sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate)

View File

@ -11,15 +11,15 @@ static CBBox_t bbox_buffer[MAX_COMP_POOL_SIZE];
static CTransform_t ctransform_buffer[MAX_COMP_POOL_SIZE];
static CTileCoord_t ctilecoord_buffer[MAX_COMP_POOL_SIZE];
static CMovementState_t cmstate_buffer[MAX_COMP_POOL_SIZE];
static CJump_t cjump_buffer[1]; // Only player is expected to have this
static CPlayerState_t cplayerstate_buffer[1]; // Only player is expected to have this
static CJump_t cjump_buffer[8]; // Only player is expected to have this
static CPlayerState_t cplayerstate_buffer[8]; // Only player is expected to have this
static CContainer_t ccontainer_buffer[MAX_COMP_POOL_SIZE];
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
static CSprite_t csprite_buffer[MAX_COMP_POOL_SIZE];
static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE];
static CLifeTimer_t clifetimer_buffer[MAX_COMP_POOL_SIZE];
static CWaterRunner_t cwaterrunner_buffer[4];
static CWaterRunner_t cwaterrunner_buffer[32];
typedef struct ULongCircBuffer {
unsigned long* buffer; // data buffer
@ -83,15 +83,15 @@ static MemPool_t comp_mempools[N_COMPONENTS] = {
{ctransform_buffer, MAX_COMP_POOL_SIZE, sizeof(CTransform_t), NULL, {0}},
{ctilecoord_buffer, MAX_COMP_POOL_SIZE, sizeof(CTileCoord_t), NULL, {0}},
{cmstate_buffer, MAX_COMP_POOL_SIZE, sizeof(CMovementState_t), NULL, {0}},
{cjump_buffer, 1, sizeof(CJump_t), NULL, {0}},
{cplayerstate_buffer, 1, sizeof(CPlayerState_t), NULL, {0}},
{cjump_buffer, 8, sizeof(CJump_t), NULL, {0}},
{cplayerstate_buffer, 8, sizeof(CPlayerState_t), NULL, {0}},
{ccontainer_buffer, MAX_COMP_POOL_SIZE, sizeof(CContainer_t), NULL, {0}},
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
{csprite_buffer, MAX_COMP_POOL_SIZE, sizeof(CSprite_t), NULL, {0}},
{cmoveable_buffer, MAX_COMP_POOL_SIZE, sizeof(CMoveable_t), NULL, {0}},
{clifetimer_buffer, MAX_COMP_POOL_SIZE, sizeof(CLifeTimer_t), NULL, {0}},
{cwaterrunner_buffer, 4, sizeof(CWaterRunner_t), NULL, {0}},
{cwaterrunner_buffer, 32, sizeof(CWaterRunner_t), NULL, {0}},
};
static MemPool_t ent_mempool = {
.buffer = entity_buffer,

View File

@ -315,7 +315,7 @@ static void level_scene_render_func(Scene_t* scene)
EndDrawing();
}
void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{
CPlayerState_t* p_playerstate;
sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate)
@ -356,6 +356,12 @@ void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
case ACTION_PREVLEVEL:
load_prev_level_tilemap((LevelScene_t*)scene);
break;
case ACTION_EXIT:
if(scene->engine != NULL)
{
change_scene(scene->engine, 0);
}
break;
default:
break;
}

View File

@ -10,8 +10,9 @@ static void menu_scene_render_func(Scene_t* scene)
ClearBackground(RAYWHITE);
DrawText("This is a game", 25, 220, 12, BLACK);
UI_button(data->buttons, "Start");
UI_button(data->buttons + 1, "Continue");
UI_button(data->buttons + 2, "Exit");
UI_button(data->buttons + 1, "Sandbox");
UI_button(data->buttons + 2, "Continue");
UI_button(data->buttons + 3, "Exit");
EndDrawing();
}
@ -57,6 +58,9 @@ static void menu_do_action(Scene_t* scene, ActionType_t action, bool pressed)
case 0:
change_scene(scene->engine, 1);
break;
case 1:
change_scene(scene->engine, 2);
break;
default:
break;
}
@ -128,7 +132,6 @@ void init_menu_scene(MenuScene_t* scene)
.state = STATE_NORMAL,
.alpha = 1.0
};
scene->data.buttons[1] = (UIComp_t) {
.bbox = {25,300,125,30},
.state = STATE_NORMAL,
@ -139,7 +142,12 @@ void init_menu_scene(MenuScene_t* scene)
.state = STATE_NORMAL,
.alpha = 1.0
};
scene->data.max_comp = 3;
scene->data.buttons[3] = (UIComp_t) {
.bbox = {25,390,125,30},
.state = STATE_NORMAL,
.alpha = 1.0
};
scene->data.max_comp = 4;
scene->data.selected_comp = 0;
scene->data.mode = KEYBOARD_MODE;

View File

@ -53,7 +53,7 @@ typedef enum GuiMode {
} GuiMode_t;
typedef struct MenuSceneData {
UIComp_t buttons[3];
UIComp_t buttons[4];
int selected_comp;
int max_comp;
GuiMode_t mode;