Files
PixelDefense/game/components.h
2023-12-10 11:08:40 +01:00

175 lines
3.9 KiB
C

#ifndef PIXELDEFENSE_COMPONENTS_H
#define PIXELDEFENSE_COMPONENTS_H
#include <breeze.h>
#include <flecs.h>
#include "utils/building_types.h"
#include "utils/entity_types.h"
extern ECS_TAG_DECLARE(TextureTerrain);
extern ECS_TAG_DECLARE(TextureBuildings);
extern ECS_TAG_DECLARE(TextureEntities);
typedef enum ResourceType {
RES_IRON,
RES_WOOD,
RES_GOLD,
RES_FOOD,
RES_COUNT,
} ResourceType;
static const char *getResourceTypePrettyName(ResourceType type) {
switch (type) {
case RES_IRON: return "Iron";
case RES_WOOD: return "Wood";
case RES_GOLD: return "Gold";
case RES_FOOD: return "Food";
default: return "Invalid";
}
}
typedef struct Resource {
ResourceType type;
i32 amount;
} Resource;
extern ECS_COMPONENT_DECLARE(Resource);
typedef struct TilePosition {
BzTile x;
BzTile y;
} TilePosition;
extern ECS_COMPONENT_DECLARE(TilePosition);
typedef struct TileSize {
BzTile sizeX;
BzTile sizeY;
} TileSize;
extern ECS_COMPONENT_DECLARE(TileSize);
typedef struct Owner {
BuildingType playerID;
} Owner;
extern ECS_COMPONENT_DECLARE(Owner);
/**********************************************************
* Movement components
*********************************************************/
typedef BzSpatialGridID SpatialGridID;
extern ECS_COMPONENT_DECLARE(SpatialGridID);
typedef Vector2 Position, Size, Velocity, TargetPosition, Steering;
typedef f32 Rotation;
extern ECS_COMPONENT_DECLARE(Position);
extern ECS_COMPONENT_DECLARE(Size);
extern ECS_COMPONENT_DECLARE(Velocity);
extern ECS_COMPONENT_DECLARE(Rotation);
extern ECS_COMPONENT_DECLARE(Steering);
extern ECS_COMPONENT_DECLARE(TargetPosition);
#define PATH_DATA_SIZE 8
typedef struct PathData {
Position waypoints[PATH_DATA_SIZE];
size_t numWaypoints;
struct PathData *next;
} PathData;
typedef struct Path {
PathData *paths;
i32 curWaypoint;
} Path;
extern ECS_COMPONENT_DECLARE(Path);
/**********************************************************
* Render components
*********************************************************/
typedef struct TextureRegion {
Texture2D texture;
Rectangle rec;
f32 rotation;
bool flipX : 1;
bool flipY : 1;
} TextureRegion;
extern ECS_COMPONENT_DECLARE(TextureRegion);
/**********************************************************
* Animation components
*********************************************************/
typedef struct Animation {
EntityType entityType;
AnimationType animType;
AnimationSequence sequence;
BzTileset *tileset;
i32 curFrame;
f32 frameDuration;
f32 elapsed;
} Animation;
extern ECS_COMPONENT_DECLARE(Animation);
extern ECS_COMPONENT_DECLARE(AnimationType);
typedef struct EntityArms {
ecs_entity_t left;
ecs_entity_t right;
} EntityArms;
//extern ECS_COMPONENT_DECLARE(EntityArms);
/**********************************************************
* Gameplay components
*********************************************************/
extern ECS_TAG_DECLARE(Selectable);
extern ECS_TAG_DECLARE(Selected);
// Unit can:
// - Attack
extern ECS_TAG_DECLARE(Unit);
// Worker can:
// - Harvest
// - Build
// - Work
// - Attack (since it is also a unit)
extern ECS_TAG_DECLARE(Worker);
extern ECS_TAG_DECLARE(Harvestable);
extern ECS_TAG_DECLARE(Buildable);
extern ECS_TAG_DECLARE(Workable);
extern ECS_TAG_DECLARE(Attackable);
typedef struct Storage {
int capacity[RES_COUNT];
int amount[RES_COUNT];
int reserved[RES_COUNT];
int pending[RES_COUNT];
} Storage;
extern ECS_COMPONENT_DECLARE(Storage);
typedef struct HarvestTask {
ecs_entity_t entity;
} HarvestTask;
extern ECS_COMPONENT_DECLARE(HarvestTask);
typedef struct WorkerTask {
enum {
HARVEST,
BUILD,
} type;
ecs_entity_t target;
//struct WorkerTask *next;
} WorkerTask;
void initComponentIDs(ecs_world_t *ecs);
#endif //PIXELDEFENSE_COMPONENTS_H