aboutsummaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-07-20 03:08:57 -0600
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-07-20 03:08:57 -0600
commit43e31b6e124da754ef928d22fbb9a1d7640aab4b (patch)
tree698f723866bd99982a6c606c63cfa0387863e2db /src/world.c
parentf3f5fedbf591c10fa675a32103bab9480b42abe8 (diff)
New bullet system
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c
index 3bc02cd..553f2ed 100644
--- a/src/world.c
+++ b/src/world.c
@@ -225,17 +225,69 @@ KfError removeEntityFromWorld(World * world, EntityId id) {
return KFSUCCESS;
}
+void checkCollisionWithWorld(World * world, Entity * entity) {
+ int i, j;
+ Entity * entity2;
+ BoundingBox box1, box2;
+
+ Mesh mesh = entity->model->meshes[0];
+
+ Vector3 triangle[3];
+
+ for (i = 0; i < mesh.triangleCount; ++i) {
+
+ for (j = 0; j < 3; ++j)
+ triangle[j] = (Vector3){
+ mesh.vertices[(i * 9) + (j * 3)],
+ mesh.vertices[(i * 9) + (j * 3) + 1],
+ mesh.vertices[(i * 9) + (j * 3) + 2],
+ };
+
+ DrawLine3D(triangle[0], triangle[1], BLUE);
+ DrawLine3D(triangle[1], triangle[2], BLUE);
+ DrawLine3D(triangle[2], triangle[0], BLUE);
+ }
+
+ // Check for collision.
+ //for (i = 0; i < world->entitiesCount; ++i) {
+ // entity2 = &world->entities[i];
+
+ // if (entity->fingerprint == entity2->fingerprint)
+ // continue;
+
+ // // These fuckers collided.
+ // if (CheckCollisionBoxes(box1, box2)) {
+ // printf("hi %ld\n", clock());
+ // break;
+ // }
+ //}
+}
+
void updateWorld(World * world, Game * game) {
int i;
Entity * entity;
+ // People are fucking dying.
+ EntityId kills[world->entitiesCount];
+ size_t killCount = 0;
+
for (i = 0; i < world->entitiesCount; ++i) {
entity = &world->entities[i];
// Call update callback.
if (entity->updateCb != NULL)
entity->updateCb(game, entity);
+
+ // It fucking died.
+ if (entity->health <= 0.0) {
+ kills[killCount] = entity->id;
+ ++killCount;
+ }
}
+
+ // "bring out your dead!"
+ for (i = 0; i < killCount; ++i)
+ removeEntityFromWorld(world, kills[i]);
}
void drawWorld(World * world, Game * game) {
@@ -245,6 +297,8 @@ void drawWorld(World * world, Game * game) {
for (i = 0; i < world->entitiesCount; ++i) {
entity = &world->entities[i];
+ //checkCollisionWithWorld(world, entity);
+
// Call draw callback.
if (entity->drawCb != NULL)
entity->drawCb(game, entity);