From 4740fe22c3fa9f9b029fc1f965d7240f9be40ccb Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Thu, 31 Jul 2025 12:35:53 +0300 Subject: Further Refactoring --- src/game.c | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 8f9bb9f..3df67df 100644 --- a/src/game.c +++ b/src/game.c @@ -1,9 +1,9 @@ #include #include -#include "game.h" -#include "assets.h" #include "stdio.h" +#include "game.h" +#include "assets.h" #include "player.h" #include "background.h" @@ -27,43 +27,46 @@ static inline Rectangle GetDrawDestinationRectGlobal(const Entity* e) { void AddEntity(Entity* e) { static int nextId = 0; - e->id = nextId++; - e->flags |= ENTITY_ALLOCATED; - for(int i = 0; i < MAX_ENTITY_COUNT; i++) { if (!EntityAllocated(&game.entities[i])) { + e->id = nextId++; + e->flags |= ENTITY_ALLOCATED; game.entities[i] = *e; break; } } + +#ifdef BEATEMUP_DEBUG + TraceLog(LOG_WARNING, "Entity pool full, cannot add new entity!"); +#endif } void InitGame() { game.paused = false; - #ifdef BEATEMUP_DEBUG - game.enableDebugOverlay = false; - #endif +#ifdef BEATEMUP_DEBUG + game.enableDebugOverlay = false; +#endif memset(game.entities, 0, sizeof(game.entities)); } void UpdateEntity(Entity* e, float deltaTime) { switch (e->type) { - case Player_Entity: - UpdatePlayer(e, deltaTime); - break; + case Player_Entity: + UpdatePlayer(e, deltaTime); + break; - default: - break; + default: + break; } } void UpdateGame(float deltaTime) { - #ifdef BEATEMUP_DEBUG - if (IsKeyPressed(KEY_D) && IsKeyDown(KEY_ENTER)) { - game.enableDebugOverlay = !game.enableDebugOverlay; - } - #endif +#ifdef BEATEMUP_DEBUG + if (IsKeyPressed(KEY_F3)) { + game.enableDebugOverlay = !game.enableDebugOverlay; + } +#endif for (int i = 0; i < MAX_ENTITY_COUNT; i++) { Entity* e = &game.entities[i]; @@ -85,8 +88,8 @@ void DefaultDrawEntity(const Entity* e) { void DrawEntity(const Entity* e) { switch (e->type) { - default: - DefaultDrawEntity(e); + default: + DefaultDrawEntity(e); } } @@ -103,12 +106,13 @@ void DrawGame() { } } - #ifdef BEATEMUP_DEBUG - for (int i = 0; i < MAX_ENTITY_COUNT; i++) { - if (game.enableDebugOverlay) +#ifdef BEATEMUP_DEBUG + if (game.enableDebugOverlay) { + for (int i = 0; i < MAX_ENTITY_COUNT; i++) { DebugHighlights(&game.entities[i]); + } } - #endif +#endif EndDrawing(); } @@ -122,9 +126,9 @@ void AddWall(float xpos, float ypos, float width, float height) { wall.position = (Vector2) {xpos, ypos}; wall.physicsCollider = (Rectangle) {0, 0, width, height}; - #ifdef BEATEMUP_DEBUG - wall.physicsColliderColor = BLUE; - #endif +#ifdef BEATEMUP_DEBUG + wall.physicsColliderColor = BLUE; +#endif AddEntity(&wall); } -- cgit v1.2.3