diff options
Diffstat (limited to 'src/entity.c')
| -rw-r--r-- | src/entity.c | 184 |
1 files changed, 49 insertions, 135 deletions
diff --git a/src/entity.c b/src/entity.c index caba91a..aff0295 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1,7 +1,22 @@ #include "entity.h" #include "game.h" +#include "entitiesInclude.h" const EntityEntry entityEntries[ENTITY_COUNT] = { + (EntityEntry){initOldMint, updateOldMint, NULL, false, true}, + (EntityEntry){initStickyNickel, updateStickyNickel, NULL, false, true}, + (EntityEntry){initTree, updateTree, NULL, false, true}, + (EntityEntry){initBush, updateBush, NULL, false, true}, + (EntityEntry){initFlower, updateFlower, NULL, false, true}, + (EntityEntry){initPond, updatePond, NULL, true, true}, + (EntityEntry){initUtilityPole, NULL, NULL, false, false}, + (EntityEntry){initSamantha, updateSamantha, NULL, false, true}, + (EntityEntry){initSamanthasSpot, updateSamanthasSpot, NULL, true, false}, + (EntityEntry){initTrashcan, updateTrashcan, NULL, false, true}, + (EntityEntry){initTrash, updateTrash, NULL, false, true}, + (EntityEntry){initMedicalTrash, updateMedicalTrash, NULL, false, true}, + (EntityEntry){initJohn, updateJohn, NULL, false, true}, + (EntityEntry){initRon, updateRon, NULL, false, true} }; Entity createEntity(EntityId id, Vector3 position) @@ -11,78 +26,12 @@ Entity createEntity(EntityId id, Vector3 position) entity.state = ENTITY_DEFAULT_STATE; entity.data = NULL; - // Bounding boxes. - switch (id) - { - case OLD_MINT: - case STICKY_NICKEL: - entity.box = entityBoxFromScale(1.0, 32.0, 32.0); - break; - case TREE: - entity.box = entityBoxFromScale(TREE_SCALE, 113.0, 250.0); - break; - case BUSH: - entity.box = entityBoxFromScale(BUSH_SCALE, 87.0, 62.0); - break; - case FLOWER: - entity.box = entityBoxFromScale(FLOWER_SCALE, 32.0, 54.0); - break; - case POND: - entity.box = (BoundingBox){ - .min = (Vector3){-POND_SIZE, -POND_HEIGHT, -POND_SIZE}, - .max = (Vector3){POND_SIZE, POND_HEIGHT, POND_SIZE} - }; - - break; - case UTILITY_POLE: - entity.box = (BoundingBox){ - .min = (Vector3){-UTILITY_POLE_RADIUS, -UTILITY_POLE_HEIGHT, - -UTILITY_POLE_RADIUS}, - .max = (Vector3){UTILITY_POLE_RADIUS, UTILITY_POLE_HEIGHT, - UTILITY_POLE_RADIUS}, - }; + // Run init callback. + InitEntityCallback initCallback = entityEntries[id].initCallback; - break; - case SAMANTHA: - entity.box = (BoundingBox){ - .min = (Vector3){-SAMANTHA_WIDTH, -SAMANTHA_HEIGHT, -SAMANTHA_THICKNESS}, - .max = (Vector3){SAMANTHA_WIDTH, SAMANTHA_HEIGHT, SAMANTHA_THICKNESS} - }; - - break; - case SAMANTHAS_SPOT: - entity.box = (BoundingBox){ - .min = (Vector3){-SAMANTHAS_SPOT_SIZE, -SAMANTHAS_SPOT_HEIGHT, - -SAMANTHAS_SPOT_SIZE}, - .max = (Vector3){SAMANTHAS_SPOT_SIZE, SAMANTHAS_SPOT_HEIGHT, - SAMANTHAS_SPOT_SIZE}, - }; - - break; - case TRASHCAN: - entity.box = entityBoxFromScale(TRASHCAN_SCALE, TRASHCAN_WIDTH, - TRASHCAN_HEIGHT); - break; - case TRASH: - entity.box = entityBoxFromScale(TRASH_SCALE, 202.0, 122.0); - break; - - case MEDICAL_TRASH: - entity.box = entityBoxFromScale(MEDICAL_TRASH_SCALE, 200.0, 132.0); - break; - // TODO: do the thing - case JOHN: - case RON: // John and Ron ARE NOT the same person. - entity.box = (BoundingBox){ - .min = (Vector3){-SHOPKEEPER_WIDTH, -SHOPKEEPER_HEIGHT, - -SHOPKEEPER_THICKNESS}, - .max = (Vector3){SHOPKEEPER_WIDTH, SHOPKEEPER_HEIGHT, - SHOPKEEPER_THICKNESS} - }; - - break; - default: - break; + if (initCallback != NULL) + { + initCallback(&entity); } entity.position = Vector3Zero(); @@ -92,65 +41,32 @@ Entity createEntity(EntityId id, Vector3 position) void updateEntity(Entity* entity, Game* game) { - //DrawBoundingBox(entity->box, RED); + //DrawBoundingBox(entity->box, BLUE); + + UpdateEntityCallback updateCallback = + entityEntries[entity->id].updateCallback; + + if (updateCallback != NULL) + { + updateCallback(entity, game); + } +} + +void closeEntity(Entity* entity) +{ + if (entity->id == ENTITY_NONE) + { + return; + } - switch (entity->id) + CloseEntityCallback closeCallback = entityEntries[entity->id].closeCallback; + + if (closeCallback != NULL) { - case OLD_MINT: - DrawBillboard(game->player.camera, game->assets.textures[MINT_TEXTURE], - entity->position, 1.0, WHITE); - break; - case STICKY_NICKEL: - DrawBillboard(game->player.camera, game->assets.textures[NICKEL_TEXTURE], - entity->position, 1.0, WHITE); - break; - case TREE: - DrawBillboard(game->player.camera, game->assets.textures[TREE_TEXTURE], - entity->position, TREE_SCALE, WHITE); - break; - case BUSH: - DrawBillboard(game->player.camera, game->assets.textures[BUSH_TEXTURE], - entity->position, BUSH_SCALE, WHITE); - break; - case FLOWER: - DrawBillboard(game->player.camera, game->assets.textures[FLOWER_TEXTURE], - entity->position, FLOWER_SCALE, WHITE); - break; - case POND: - DrawPlane( - Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT, 0.0}), - (Vector2){POND_SIZE * 2.5, POND_SIZE * 2.5}, BLUE); - break; - case SAMANTHA: - //updateSamantha(entity, game); - break; - case SAMANTHAS_SPOT: - DrawModel(game->world.samanthasSpotFloor, - Vector3Add(entity->position, - (Vector3){0.0, -SAMANTHAS_SPOT_HEIGHT + 0.01, 0.0}), - 1.0, WHITE); - break; - case TRASHCAN: - //updateTrashcan(entity, game); - break; - case TRASH: - DrawBillboard(game->player.camera, game->assets.textures[TRASH_TEXTURE], - entity->position, TRASH_SCALE, WHITE); - break; - case MEDICAL_TRASH: - DrawBillboard(game->player.camera, - game->assets.textures[MEDICAL_TRASH_TEXTURE], - entity->position, MEDICAL_TRASH_SCALE, WHITE); - break; - case JOHN: - DrawModel(game->assets.models[JOHN_MODEL], entity->position, 1.0, WHITE); - break; - case RON: - DrawModel(game->assets.models[RON_MODEL], entity->position, 1.0, WHITE); - break; - default: - break; + closeCallback(entity); } + + entity->id = ENTITY_NONE; } void setEntityPosition(Entity* entity, Vector3 position) @@ -172,15 +88,14 @@ void placeEntityOnGround(Entity* entity, const World* world) setEntityPosition(entity, position); } +bool entityIsPlace(EntityId id) +{ + return entityEntries[id].isPlace; +} + bool entityCanBeSelected(EntityId id) { - switch (id) - { - case SAMANTHAS_SPOT: - return false; - default: - return true; - } + return entityEntries[id].canBeSelected; } InteractionCommand interactWithOldMint(Entity* entity, Game* game, @@ -221,4 +136,3 @@ BoundingBox entityBoxFromScale(float scale, float width, float height) .max = (Vector3){size.x, size.y, size.x} }; } - |
