aboutsummaryrefslogtreecommitdiffstats
path: root/src/entity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity.c')
-rw-r--r--src/entity.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/entity.c b/src/entity.c
index 23844bf..de5f7f3 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -1,6 +1,17 @@
#include "entity.h"
#include "game.h"
+BoundingBox entityBoxFromScale(float scale, float width, float height)
+{
+ Vector2 size = (Vector2){width / height * scale, scale};
+ size = Vector2Scale(size, 0.5);
+
+ return (BoundingBox){
+ .min = (Vector3){-size.x, -size.y, -size.x},
+ .max = (Vector3){size.x, size.y, size.x}
+ };
+}
+
// TODO: Entity creation system
Entity createEntity(EntityId id, Vector3 position)
{
@@ -11,29 +22,19 @@ Entity createEntity(EntityId id, Vector3 position)
{
case OLD_MINT:
case STICKY_NICKEL:
- entity.box = (BoundingBox){
- .min = (Vector3){-0.4, -0.4, -0.4},
- .max = (Vector3){0.4, 0.4, 0.4}
- };
-
+ entity.box = entityBoxFromScale(1.0, 32.0, 32.0);
break;
case TREE:
-
- {
- Vector2 size = (Vector2){225.0 / 500.0 * TREE_SCALE, TREE_SCALE};
- size = Vector2Scale(size, 0.5);
-
- entity.box = (BoundingBox){
- .min = (Vector3){-size.x, -size.y, -size.x},
- .max = (Vector3){size.x, size.y, size.x}
- };
- }
-
+ entity.box = entityBoxFromScale(TREE_SCALE, 225.0, 500.0);
+ break;
+ case BUSH:
+ entity.box = entityBoxFromScale(BUSH_SCALE, 174.0, 124.0);
break;
default:
break;
}
-
+
+ entity.position = Vector3Zero();
setEntityPosition(&entity, position);
return entity;
}
@@ -54,6 +55,10 @@ void updateEntity(Entity* entity, Game* game)
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;
default:
break;
}
@@ -61,7 +66,19 @@ void updateEntity(Entity* entity, Game* game)
void setEntityPosition(Entity* entity, Vector3 position)
{
+ Vector3 movedBy = Vector3Subtract(position, entity->position);
entity->position = position;
- entity->box.min = Vector3Add(entity->box.min, position);
- entity->box.max = Vector3Add(entity->box.max, position);
+ entity->box.min = Vector3Add(entity->box.min, movedBy);
+ entity->box.max = Vector3Add(entity->box.max, movedBy);
+}
+
+void placeEntityOnGround(Entity* entity, const World* world)
+{
+ Vector3 position = entity->position;
+
+ position.y = getWorldHeightAtLocation(
+ world, entity->position.x, entity->position.z);
+ position.y += (entity->box.max.y - entity->box.min.y) / 2.0;
+
+ setEntityPosition(entity, position);
}