Files
PixelDefense/game/components.h

86 lines
1.8 KiB
C

#ifndef PIXELDEFENSE_COMPONENTS_H
#define PIXELDEFENSE_COMPONENTS_H
#include <breeze.h>
#include <flecs.h>
#include "utils/building_types.h"
#define ecs_set_p(world, e, T, ...) ecs_set_id(world, e, ecs_id(T), sizeof(T), (T*)__VA_ARGS__)
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);
typedef Vector2 Position, Size, TargetPosition, MoveForce;
extern ECS_COMPONENT_DECLARE(Position);
extern ECS_COMPONENT_DECLARE(Size);
extern ECS_COMPONENT_DECLARE(TargetPosition);
extern ECS_COMPONENT_DECLARE(MoveForce);
typedef BzSpatialGridID SpatialGridID;
extern ECS_COMPONENT_DECLARE(SpatialGridID);
typedef f32 Rotation;
extern ECS_COMPONENT_DECLARE(Rotation);
typedef f32 Health;
extern ECS_COMPONENT_DECLARE(Health);
typedef struct TextureRegion {
Texture2D texture;
Rectangle rec;
bool flipX;
bool flipY;
} TextureRegion;
extern ECS_COMPONENT_DECLARE(TextureRegion);
typedef enum AnimationType {
ANIMATION_IDLE,
ANIMATION_WALK,
} AnimationType;
extern ECS_COMPONENT_DECLARE(AnimationType);
typedef struct Animation {
TextureRegion firstFrame;
AnimationType currAnimation;
i32 currFrame;
i32 frameCount;
f32 frameDuration;
f32 elapsed;
} Animation;
extern ECS_COMPONENT_DECLARE(Animation);
#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);
void initComponentIDs(ecs_world_t *ecs);
#endif //PIXELDEFENSE_COMPONENTS_H