Add path debug drawing, resources fields

This commit is contained in:
2023-11-14 16:21:14 +01:00
parent 8825b9e01f
commit 274612b035
6 changed files with 82 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ bool bzMain(BzAppDesc *appDesc, int argc, const char **argv) {
}
bool init(Game *game) {
SetExitKey(-1);
initComponentIDs(ECS);
int screenWidth = 1280;
@@ -87,9 +88,11 @@ bool init(Game *game) {
bzTileMapOverrideObjectGroup(&game->map, OBJECTS_GAME, initGameObjectsLayer);
bzTileMapOverrideObjectGroup(&game->map, OBJECTS_ENTITIES, initEntityObjectsLayer);
ECS_SYSTEM(ECS, uiTask, EcsOnUpdate, 0);
ECS_SYSTEM(ECS, updateAnimations, EcsOnUpdate, Animation, TextureRegion);
ECS_SYSTEM(ECS, renderEntities, EcsOnUpdate, Position, Size, Rotation, TextureRegion);
ECS_SYSTEM(ECS, updatePos, EcsOnUpdate, Position, TargetPosition, TextureRegion);
ECS_SYSTEM(ECS, drawDebugPath, EcsOnUpdate, Path);
ECS_SYSTEM(ECS, renderEntities, EcsOnUpdate, Position, Size, Rotation, TextureRegion);
ECS_OBSERVER(ECS, targetFinish, EcsOnRemove, TargetPosition);
ECS_OBSERVER(ECS, startPath, EcsOnSet, Path);
return true;
@@ -122,17 +125,21 @@ void update(float dt, Game *game) {
if (IsKeyDown(KEY_Q)) game->camera.rotation--;
if (IsKeyDown(KEY_E)) game->camera.rotation++;
game->camera.zoom += ((float) GetMouseWheelMove() * 0.05f);
BzTileMap *map = &game->map;
Vector2 worldPos = GetScreenToWorld2D(GetMousePosition(), game->camera);
int tileX = (int) worldPos.x / 16;
int tileY = (int) worldPos.y / 16;
int tileX = (int) worldPos.x / map->tileWidth;
int tileY = (int) worldPos.y / map->tileHeight;
if (game->selectedBuilding) {
if (IsKeyPressed(KEY_ESCAPE) || IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
game->input.building = 0;
if (game->input.building) {
BzTile sizeX = 0, sizeY = 0;
getBuildingSize(game->selectedBuilding, &sizeX, &sizeY);
getBuildingSize(game->input.building, &sizeX, &sizeY);
bool canPlace = canPlaceBuilding(&game->map, game->selectedBuilding, tileX, tileY);
bool canPlace = canPlaceBuilding(&game->map, game->input.building, tileX, tileY);
/*
Color placeColor = canPlace ?
(Color) {0, 255, 0, 200} :
@@ -142,9 +149,20 @@ void update(float dt, Game *game) {
*/
if (canPlace && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
placeBuilding(&game->map, game->selectedBuilding, tileX, tileY);
placeBuilding(&game->map, game->input.building, tileX, tileY);
}
return;
}
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
game->input.mouseDown = GetMousePosition();
game->input.mouseDownElapsed = 0;
bzLogInfo("Pressed");
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
game->input.mouseDownElapsed += dt;
bzLogInfo("Down: %.2f", game->input.mouseDownElapsed);
} else if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
bzLogInfo("Released");
}
}
@@ -173,10 +191,6 @@ void render(float dt, Game *game) {
.heap=heap,
.outPath=&game->path
});
for (i32 i = 0; i < game->path.numWaypoints; i++) {
Position pos = game->path.waypoints[i];
DrawCircle(pos.x, pos.y, 3.0f, RED);
}
if (game->path.numWaypoints > 0 && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
ecs_entity_t e = game->entity;
bzLogInfo("%d", ecs_is_alive(ECS, e));
@@ -193,10 +207,17 @@ void render(float dt, Game *game) {
void imguiRender(float dt, Game *game) {
igSetNextWindowSize((ImVec2){300, 400}, ImGuiCond_FirstUseEver);
igBegin("Debug Menu", NULL, 0);
if (igCollapsingHeader_TreeNodeFlags("Resources", 0)) {
igText("Wood: %lld", game->resources.wood);
igText("Iron: %lld", game->resources.iron);
igText("Food: %lld", game->resources.food);
igText("Gold: %lld", game->resources.gold);
igText("Population: %lld", game->resources.pop);
}
if (igCollapsingHeader_TreeNodeFlags("BuildMenu", 0)) {
for (int i = 0; i < BUILDINGS_COUNT; i++) {
if (igSelectable_Bool(getBuildingStr(i), game->selectedBuilding == i, 0, (ImVec2){0,0}))
game->selectedBuilding = i;
if (igSelectable_Bool(getBuildingStr(i), game->input.building == i, 0, (ImVec2){0, 0}))
game->input.building = i;
}
}