aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLeander Scherer <leander@schererleander.de>2026-03-11 23:16:49 +0100
committerLeander Scherer <leander@schererleander.de>2026-03-11 23:16:49 +0100
commitd3a1bb552e9efc4e516841158aaaea3d8ab9202d (patch)
tree16957aab86a6fdfd6c6aae0873babe359bf386a9 /include
parent9fb384552cb0a036a5978dfc40cddbbe2d29727c (diff)
refactor(entity): replace EntityManager with typed Entities struct
Diffstat (limited to 'include')
-rw-r--r--include/entities.h126
-rw-r--r--include/entity.h61
-rw-r--r--include/game.h11
-rw-r--r--include/globals.h13
4 files changed, 126 insertions, 85 deletions
diff --git a/include/entities.h b/include/entities.h
new file mode 100644
index 0000000..7bd38f3
--- /dev/null
+++ b/include/entities.h
@@ -0,0 +1,126 @@
+#pragma once
+
+#include "raylib.h"
+#include "raytmx.h"
+
+#include "map.h"
+#include "player.h"
+
+#define MAX_ENTITIES 120
+
+typedef enum {
+ PICKUP_COIN,
+ PICKUP_POTION,
+ PICKUP_BOMB,
+ PICKUP_FULL_HEART,
+ PICKUP_HALF_HEART,
+ PICKUP_GOLD_BAR,
+ PICKUP_GOLD_NUGGET
+} PickupType;
+
+static const int PICKUP_TILE_ID[] = {0, 4, 8, 12, 16, 20, 24};
+
+typedef enum { STATE_IDLE, STATE_PATROL, STATE_CHASE, STATE_ATTACK } EnemyState;
+
+typedef struct {
+ PickupType type;
+ Vector2 position;
+ Rectangle bounds;
+ int value;
+ bool active;
+ uint32_t gid;
+} Pickup;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ int uniqueId;
+ bool active;
+ uint32_t gid;
+} Key;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ int health;
+ EnemyState state;
+
+ TmxTileset tileset;
+ int currentFrame;
+ float frameTime;
+ bool facingRight;
+
+ bool active;
+} Bat;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ int health;
+ EnemyState state;
+
+ TmxTileset tileset;
+ int currentFrame;
+ float frameTime;
+ bool facingRight;
+
+ bool active;
+} Slime;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ int health;
+ EnemyState state;
+
+ TmxTileset tileset;
+ int currentFrame;
+ float frameTime;
+ bool facingRight;
+
+ bool active;
+} FlyingSkull;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ bool active;
+} Vase;
+
+typedef struct {
+ Vector2 position;
+ Rectangle bounds;
+ bool active;
+} Crate;
+
+struct Entities {
+ Pickup pickups[MAX_ENTITIES];
+ int pickupsCount;
+
+ Key keys[MAX_ENTITIES];
+ int keysCount;
+
+ Bat bats[MAX_ENTITIES];
+ int batsCount;
+
+ Slime slimes[MAX_ENTITIES];
+ int slimesCount;
+
+ FlyingSkull flyingSkulls[MAX_ENTITIES];
+ int flyingSkullsCount;
+
+ Vase vases[MAX_ENTITIES];
+ int vasesCount;
+
+ Crate crates[MAX_ENTITIES];
+ int cratesCount;
+};
+
+void UpdateBat(Bat *bat, Player *player, Map *map);
+void DrawBat(Bat *bat);
+
+void UpdateSlime(Slime *slime, Player *player, Map *map);
+void DrawSlime(Slime *slime);
+
+void UpdateFlyingSkull(FlyingSkull *skull, Player *player, Map *map);
+void DrawFlyingSkull(FlyingSkull *skull);
diff --git a/include/entity.h b/include/entity.h
deleted file mode 100644
index 60467ab..0000000
--- a/include/entity.h
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef ENTITY_H
-#define ENTITY_H
-
-#include "raylib.h"
-#include "raytmx.h"
-
-#include "player.h"
-#include "map_manager.h"
-
-typedef struct Enemy {
- Vector2 position;
- Rectangle bounds;
- uint32_t gid;
- int health;
- bool active;
-} Enemy;
-
-typedef struct Static {
- Vector2 position;
- Rectangle bounds;
- uint32_t gid;
- bool active;
-} Static;
-
-typedef struct Collectible {
- Vector2 position;
- Rectangle bounds;
- uint32_t gid;
- bool active;
- int tileX;
- int tileY;
-} Collectible;
-
-typedef struct Movable {
- Vector2 position;
- Rectangle bounds;
- uint32_t gid;
- bool active;
-} Movable;
-
-typedef struct EntityManager {
- Enemy *enemies;
- int enemiesCount;
-
- Collectible *collectibles;
- int collectiblesCount;
-
- Static *statics;
- int staticsCount;
-
- Movable *movables;
- int movablesCount;
-} EntityManager;
-
-EntityManager InitEntityManager(uint32_t capacity);
-void SpawnEntitiesFromMap(EntityManager *mgr, TmxMap *map);
-void UpdateEntities(EntityManager *mgr, Player *player, MapManager *mapMgr);
-void DrawEntities(EntityManager *mgr, TmxMap *map);
-void UnloadEntityManager(EntityManager *mgr);
-
-#endif // ENTITY_H
diff --git a/include/game.h b/include/game.h
deleted file mode 100644
index 6b37293..0000000
--- a/include/game.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef GAME_H
-#define GAME_H
-
-typedef enum GameScreen {
- SCREEN_TITLE,
- SCREEN_PLAYING,
- SCREEN_PAUSED,
- SCREEN_GAME_OVER
-} GameScreen;
-
-#endif // GAME_H
diff --git a/include/globals.h b/include/globals.h
deleted file mode 100644
index e7830de..0000000
--- a/include/globals.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef GLOBALS_H
-#define GLOBALS_H
-
-#include "raylib.h"
-
-#define TILE_SIZE 16
-#define SCREEN_WIDTH 1280
-#define SCREEN_HEIGHT 720
-#define BACKGROUND_COLOR (Color){ 88, 68, 34, 255 }
-
-extern bool debugMode;
-
-#endif