entity.c (939B)
1 #include <stdlib.h> 2 3 #include "entity.h" 4 #include "enemy.h" 5 #include "gate.h" 6 7 entity_t *entity_create(entity_e type) { 8 entity_t *entity = malloc(sizeof(entity_t)); 9 entity->type = type; 10 return entity; 11 } 12 13 void entity_update(entity_t *entity, game_t *game) { 14 switch (entity->type) { 15 case ENTITY_ENEMY: 16 enemy_update(entity->enemy, game); 17 break; 18 case ENTITY_GATE: 19 gate_update(entity->gate, game); 20 break; 21 } 22 } 23 24 void entity_draw(entity_t *entity, game_t *game) { 25 switch (entity->type) { 26 case ENTITY_ENEMY: 27 enemy_draw(entity->enemy, game); 28 break; 29 case ENTITY_GATE: 30 gate_draw(entity->gate, game); 31 break; 32 } 33 } 34 35 void entity_detach(entity_t *entity) { 36 switch (entity->type) { 37 case ENTITY_ENEMY: 38 enemy_free(entity->enemy); 39 break; 40 case ENTITY_GATE: 41 gate_free(entity->gate); 42 break; 43 } 44 } 45 46 void entity_free(entity_t *entity) { 47 free(entity); 48 }