From d3a1bb552e9efc4e516841158aaaea3d8ab9202d Mon Sep 17 00:00:00 2001 From: Leander Scherer Date: Wed, 11 Mar 2026 23:16:49 +0100 Subject: refactor(entity): replace EntityManager with typed Entities struct --- include/entities.h | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 include/entities.h (limited to 'include/entities.h') 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); -- cgit v1.3.1