Add main menu
This commit is contained in:
104
game/main.c
104
game/main.c
@@ -1,4 +1,5 @@
|
||||
#include <rlImGui.h>
|
||||
#include <raygui.h>
|
||||
|
||||
#include "systems.h"
|
||||
#include "components.h"
|
||||
@@ -8,6 +9,7 @@
|
||||
#include "map_init.h"
|
||||
#include "map_layers.h"
|
||||
#include "buildings.h"
|
||||
#include "ui_widgets.h"
|
||||
#include "unit_ai.h"
|
||||
#include "unit_actions.h"
|
||||
|
||||
@@ -19,6 +21,7 @@
|
||||
ECS_COMPONENT_DECLARE(Game);
|
||||
ECS_COMPONENT_DECLARE(InputState);
|
||||
|
||||
BzUI *UI = NULL;
|
||||
ecs_world_t *ECS = NULL;
|
||||
|
||||
static ecs_entity_t renderCollidersSystem;
|
||||
@@ -45,6 +48,9 @@ bool bzMain(BzAppDesc *appDesc, int argc, const char **argv) {
|
||||
appDesc->imguiRender = (BzAppRenderFunc) imguiRender;
|
||||
|
||||
appDesc->userData = NULL;
|
||||
|
||||
//SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,6 +88,8 @@ bool init(void *userData) {
|
||||
BZ_UNUSED(userData);
|
||||
SetExitKey(0);
|
||||
|
||||
UI = bzUICreate();
|
||||
|
||||
ECS = ecs_init();
|
||||
|
||||
initComponentIDs(ECS);
|
||||
@@ -93,6 +101,7 @@ bool init(void *userData) {
|
||||
ECS_COMPONENT_DEFINE(ECS, Game);
|
||||
ecs_singleton_set(ECS, Game, {});
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
game->screen = SCREEN_MAIN_MENU;
|
||||
|
||||
ECS_COMPONENT_DEFINE(ECS, InputState);
|
||||
ecs_singleton_set(ECS, InputState, {});
|
||||
@@ -225,6 +234,9 @@ void deinit(void *userData) {
|
||||
bzObjectPoolDestroy(gameCopy.pools.pathData);
|
||||
bzObjectPoolDestroy(gameCopy.pools.actions);
|
||||
bzSpatialGridDestroy(gameCopy.entityGrid);
|
||||
|
||||
bzUIDestroy(UI);
|
||||
UI = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -243,32 +255,92 @@ void update(float dt, void *userData) {
|
||||
|
||||
updateInputState(input, game->camera, dt);
|
||||
|
||||
updatePlayerInput();
|
||||
switch (game->screen) {
|
||||
case SCREEN_MAIN_MENU:
|
||||
break;
|
||||
case SCREEN_GAME:
|
||||
updatePlayerInput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void renderMainMenu(Game *game, float dt) {
|
||||
i32 width = GetScreenWidth();
|
||||
i32 height = GetScreenHeight();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
bzUIBegin(UI, width, height);
|
||||
bzUISetParentLayout(UI, (BzUILayout) {
|
||||
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
||||
.flags = BZ_UI_FLEX_DIR_COLUMN
|
||||
});
|
||||
|
||||
uiPushDivParentPercentage(1.0f, 0.4f);
|
||||
bzUISetParentLayout(UI, (BzUILayout) {
|
||||
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
||||
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_JUSTIFY_CENTER | BZ_UI_FLEX_ALIGN_CENTER
|
||||
});
|
||||
uiLargeLabel("PixelDefense");
|
||||
bzUIPopParent(UI);
|
||||
|
||||
uiPushDivParentPercentage(1.0f, 0.6f);
|
||||
bzUISetParentLayout(UI, (BzUILayout) {
|
||||
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
||||
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER
|
||||
});
|
||||
if (uiLargeTextButton("Play")) {
|
||||
bzLogInfo("Play");
|
||||
}
|
||||
if (uiLargeTextButton("Settings")) {
|
||||
bzLogInfo("Settings");
|
||||
}
|
||||
if (uiLargeTextButton("Exit")) {
|
||||
bzLogInfo("Bye");
|
||||
bzGameExit();
|
||||
}
|
||||
bzUIPopParent(UI);
|
||||
bzUIEnd(UI);
|
||||
|
||||
}
|
||||
|
||||
static void renderSettings(Game *game, float dt) {
|
||||
}
|
||||
|
||||
void render(float dt, void *userData) {
|
||||
BZ_UNUSED(userData);
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
InputState *input = ecs_singleton_get_mut(ECS, InputState);
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode2D(game->camera);
|
||||
switch (game->screen) {
|
||||
case SCREEN_MAIN_MENU:
|
||||
renderMainMenu(game, dt);
|
||||
break;
|
||||
case SCREEN_SETTINGS:
|
||||
renderSettings(game, dt);
|
||||
break;
|
||||
case SCREEN_GAME:
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode2D(game->camera);
|
||||
|
||||
bzTileMapDraw(&game->map);
|
||||
bzTileMapDraw(&game->map);
|
||||
|
||||
drawPlayerInputUIGround();
|
||||
drawPlayerInputUIGround();
|
||||
|
||||
ecs_progress(ECS, dt);
|
||||
ecs_enable(ECS, renderDebugPathSystem, game->debugDraw.path);
|
||||
ecs_enable(ECS, renderCollidersSystem, game->debugDraw.entityColliders);
|
||||
if (game->debugDraw.mapColliders)
|
||||
bzTileMapDrawCollisions(&game->map);
|
||||
if (game->debugDraw.spatialGrid)
|
||||
bzSpatialGridDrawDebugGrid(game->entityGrid);
|
||||
ecs_progress(ECS, dt);
|
||||
ecs_enable(ECS, renderDebugPathSystem, game->debugDraw.path);
|
||||
ecs_enable(ECS, renderCollidersSystem, game->debugDraw.entityColliders);
|
||||
if (game->debugDraw.mapColliders)
|
||||
bzTileMapDrawCollisions(&game->map);
|
||||
if (game->debugDraw.spatialGrid)
|
||||
bzSpatialGridDrawDebugGrid(game->entityGrid);
|
||||
|
||||
drawPlayerInputUI();
|
||||
|
||||
EndMode2D();
|
||||
break;
|
||||
}
|
||||
|
||||
drawPlayerInputUI();
|
||||
|
||||
EndMode2D();
|
||||
}
|
||||
|
||||
void imguiRender(float dt, void *userData) {
|
||||
@@ -276,6 +348,8 @@ void imguiRender(float dt, void *userData) {
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
InputState *input = ecs_singleton_get_mut(ECS, InputState);
|
||||
|
||||
if (game->screen != SCREEN_GAME) return;
|
||||
|
||||
igSetNextWindowSize((ImVec2){300, 400}, ImGuiCond_FirstUseEver);
|
||||
igBegin("Debug Menu", NULL, 0);
|
||||
if (igSmallButton("Recruit worker [50 food]")) {
|
||||
|
||||
Reference in New Issue
Block a user