entity.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include "game_engine.h"
  3. #include "director.h"
  4. #include <stdlib.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct Entity Entity;
  9. typedef struct {
  10. float x;
  11. float y;
  12. } Vector;
  13. #define VECTOR_ZERO ((Vector){0, 0})
  14. typedef union {
  15. uint32_t value;
  16. void* pointer;
  17. } EntityEventValue;
  18. typedef struct {
  19. uint32_t type;
  20. Entity* sender;
  21. EntityEventValue value;
  22. } EntityEvent;
  23. typedef struct {
  24. void (*start)(Entity* self, Level* level, void* context);
  25. void (*stop)(Entity* self, Level* level, void* context);
  26. void (*update)(Entity* self, Director* director, void* context);
  27. void (*render)(Entity* self, Director* director, Canvas* canvas, void* context);
  28. void (*collision)(Entity* self, Entity* other, Director* director, void* context);
  29. void (*event)(Entity* self, Director* director, EntityEvent event, void* context);
  30. size_t context_size;
  31. } EntityDescription;
  32. const EntityDescription* entity_description_get(Entity* entity);
  33. Vector entity_pos_get(Entity* entity);
  34. void entity_pos_set(Entity* entity, Vector position);
  35. void* entity_context_get(Entity* entity);
  36. void entity_collider_add_circle(Entity* entity, float radius);
  37. void entity_collider_add_rect(Entity* entity, float width, float height);
  38. void entity_send_event(Entity* entity, uint32_t type, EntityEventValue value);
  39. #ifdef __cplusplus
  40. }
  41. #endif