summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/game.c b/src/game.c
index 05713e8..66fd8e4 100644
--- a/src/game.c
+++ b/src/game.c
@@ -2,6 +2,7 @@
#include <string.h>
#include "stdio.h"
+#include "constants.h"
#include "game.h"
#include "assets.h"
#include "player.h"
@@ -32,7 +33,7 @@ void AddEntity(Entity* e) {
e->id = nextId++;
e->flags |= ENTITY_ALLOCATED;
game.entities[i] = *e;
- break;
+ return;
}
}
@@ -42,12 +43,13 @@ void AddEntity(Entity* e) {
}
void InitGame() {
- game.paused = false;
-#ifdef BEATEMUP_DEBUG
- game.enableDebugOverlay = false;
-#endif
+ memset(&game, 0, sizeof(Game));
- memset(game.entities, 0, sizeof(game.entities));
+ game.camera = (Camera2D) {
+ .offset = (Vector2) {WINDOW_WIDTH / 2.0f, 0.0f},
+ .rotation = 0.0f,
+ .zoom = 1.0f
+ };
}
void UpdateEntity(Entity* e, float deltaTime) {
@@ -93,26 +95,38 @@ void DrawEntity(const Entity* e) {
}
}
+void DrawEntitiesInLayer(int layer) {
+ for (int i = 0; i < MAX_ENTITY_COUNT; i++) {
+ Entity* currentEntity = &game.entities[i];
+
+ if (ShouldDrawEntity(currentEntity, layer))
+ DrawEntity(currentEntity);
+ }
+}
+
void DrawGame() {
BeginDrawing();
ClearBackground(RAYWHITE);
- for (DrawLayer layer = Background_Layer; layer <= Foreground_Layer; layer++) {
- for (int j = 0; j < MAX_ENTITY_COUNT; j++) {
- Entity* currentEntity = &game.entities[j];
+ BeginMode2D(game.camera);
- if (ShouldDrawEntity(currentEntity, layer))
- DrawEntity(currentEntity);
- }
- }
+ for (DrawLayer layer = Background_Layer; layer <= Foreground_Layer; layer++)
+ DrawEntitiesInLayer(layer);
#ifdef BEATEMUP_DEBUG
if (game.enableDebugOverlay) {
for (int i = 0; i < MAX_ENTITY_COUNT; i++) {
DebugHighlights(&game.entities[i]);
}
+ }
+#endif
- DrawFPS(10, 10);
+ EndMode2D();
+
+#ifdef BEATEMUP_DEBUG
+ if (game.enableDebugOverlay) {
+ const int posX = 10, posY = 10;
+ DrawFPS(posX, posY);
}
#endif