aboutsummaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-14 00:11:04 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-14 00:11:04 -0600
commitb14a7bb1e4e2e71a8fef86fcfec4ad9501768e57 (patch)
treeb4dfb0b946c649583f4eebc8016e1d85c5984625 /src/world.c
parent3b22489413553e837a7da437b2c3cd69823095ab (diff)
Started laser and fixed world bug
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/world.c b/src/world.c
index 26ac9cd..0e7c975 100644
--- a/src/world.c
+++ b/src/world.c
@@ -203,13 +203,22 @@ KfError removeEntityFromWorld(World * world, EntityId id) {
return KFERROR;
// Move back entities.
- for (i = pos; i < world->entitiesCount - 1; ++i)
- world->entities[i] = world->entities[i + 1];
+ // for (i = pos; i < world->entitiesCount - 1; ++i)
+ // world->entities[i] = world->entities[i + 1];
// Update lookup.
- for (i = id + 1; i < world->lookUpSize; ++i)
- if (world->lookUp[i] != ENTITY_ID_NONE)
- --world->lookUp[i];
+ // for (i = id + 1; i < world->lookUpSize; ++i)
+ // if (world->lookUp[i] != ENTITY_ID_NONE)
+ // --world->lookUp[i];
+
+ // This is a replacement for the code above. It was buggy.
+ for (i = pos; i < world->entitiesCount - 1; ++i) {
+ // Move back entities
+ world->entities[i] = world->entities[i + 1];
+
+ // Update lookUp.
+ world->lookUp[world->entities[i].id] = i;
+ }
world->lookUp[id] = ENTITY_ID_NONE;
@@ -298,6 +307,8 @@ void handleCollisionInWorld(Entity * entity1, Entity * entity2) {
break;
case ENTITY_MUSSOLINI:
break;
+ case ENTITY_GUIDED_MISSILE:
+ break;
default:
break;
}
@@ -336,17 +347,19 @@ void updateWorld(World * world, Game * game) {
}
// It fucking died.
- if (entity->health <= 0.0) {
+ if (entity->health <= 0.0 && entity->type != ENTITY_ANTIFA) {
kills[killCount] = entity->id;
++killCount;
}
}
+ if (killCount != 0) {
+ printf("%ld\n", killCount);
+ debugWorld(world);
+ }
+
// "bring out your dead!"
for (i = 0; i < killCount; ++i) {
- if (kills[i] == 0) // Hack to keep player alive while debugging.
- continue;
-
removeEntityFromWorld(world, kills[i]);
}
@@ -415,6 +428,32 @@ EntityId traceRayToEntityInWorld(World * world, Ray ray, EntityFingerprint from,
return closestId;
}
+void debugWorld(World * world) {
+ int i;
+ Entity * entity;
+
+ for (i = 0; i < world->entitiesCount; ++i) {
+ entity = &world->entities[i];
+
+ bool idMatches = world->lookUp[entity->id] == i;
+
+ printf("index: %d, look up: %d, id: %d fingerprint: %x, matches: %d\n", i, world->lookUp[entity->id], entity->id, entity->fingerprint, idMatches);
+ }
+
+ // for (i = 0; i < world->lookUpSize; ++i) {
+ // if (world->lookUp[i] != ENTITY_ID_NONE)
+ // printf("%d\n", world->entities[world->lookUp[i]].id == i);
+ // }
+
+ if (world->vacantIds == NULL)
+ return;
+
+ for (i = 0; i < world->vacantIdsCount; ++i)
+ printf("v %d\n", world->vacantIds[i]);
+
+ puts("");
+}
+
KfError addEntryToWorld(World * world, Game * game, WorldEntry entry) {
// Create entity.
Entity entity = createEntity(entry.type, game);