aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-12 21:53:32 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-12 21:53:32 -0600
commit7d4d948dfa92416c802229b1c444a44785ee2a0c (patch)
tree129fcf7141640ec8b3c7647de174755d04858ce2 /src
parentc759231e1e8570ffe5fdda2f1eb5d011b1c6a29f (diff)
Guided missile worky worky
Diffstat (limited to 'src')
-rw-r--r--src/entities/guidedMissile.c16
-rw-r--r--src/entities/guidedMissile.h3
-rw-r--r--src/entities/maresciallo.c9
-rw-r--r--src/entities/maresciallo.h2
-rw-r--r--src/game.c2
-rw-r--r--src/playerCamera.c6
-rw-r--r--src/world.c49
-rw-r--r--src/world.h7
8 files changed, 86 insertions, 8 deletions
diff --git a/src/entities/guidedMissile.c b/src/entities/guidedMissile.c
index 53cbaf8..b7f6b68 100644
--- a/src/entities/guidedMissile.c
+++ b/src/entities/guidedMissile.c
@@ -18,6 +18,8 @@ void initGuidedMissile(Entity * entity, Game * game) {
GuidedMissile * data = (GuidedMissile*)entity->data;
+ data->beenBorn = false; // NOT EVEN BORN YET! HA HA!!!
+
data->flyToPoint = (EntityFlyToPointInfo){
.controller.bangbang.speed = 80,
.controller.bangbang.stopAt = 0.0,
@@ -41,12 +43,24 @@ void updateGuidedMissile(Game * game, Entity * entity) {
Entity * player = getEntityFromWorld(game->world, 0);
GuidedMissile * data = (GuidedMissile*)entity->data;
+ // Life begins.
+ if (!data->beenBorn) {
+ data->beenBorn = true;
+ data->birthDay = GetTime();
+ }
+
entityFlyToPoint(entity, player->position, &data->flyToPoint);
// boom boom time
if (Vector3Distance(player->position, entity->position) <= GUIDED_MISSILE_BOOM_BOOM_AT)
guidedMissileGoBoomBoom(game, entity);
+ // Death countdown.
+ if (GetTime() - data->birthDay >= GUIDED_MISSILE_DEATH_DAY) {
+ guidedMissileGoBoomBoom(game, entity);
+ puts("Me is fucking dead!!!!");
+ }
+
entityCheckTransformedCollisionModel(entity);
}
@@ -67,5 +81,5 @@ void guidedMissileGoBoomBoom(Game * game, Entity * entity) {
// Remove its self from the world. I have thought of doing the same for years ):
entity->health = 0.0;
- printf("This fucker did %f damage\n", damage);
+ printf("This fucker died %f damage\n", damage);
}
diff --git a/src/entities/guidedMissile.h b/src/entities/guidedMissile.h
index b184775..8d33e86 100644
--- a/src/entities/guidedMissile.h
+++ b/src/entities/guidedMissile.h
@@ -9,8 +9,11 @@
#define GUIDED_MISSILE_DAMAGE 2.0
#define GUIDED_MISSILE_BOOM_BOOM_AT 5.0
+#define GUIDED_MISSILE_DEATH_DAY 5.0 // Its like a birth day but sad.
typedef struct GuidedMissile {
+ bool beenBorn;
+ double birthDay; // Even missiles have birth days.
EntityFlyToPointInfo flyToPoint;
} GuidedMissile;
diff --git a/src/entities/maresciallo.c b/src/entities/maresciallo.c
index 34d3377..52c5d96 100644
--- a/src/entities/maresciallo.c
+++ b/src/entities/maresciallo.c
@@ -105,6 +105,11 @@ void updateGunMaresciallo(Game * game, Entity * entity) {
Bullet bullet = createBulletFromEntity(*entity, MARESCIALLO_BULLET_DAMAGE);
BulletHitInfo hit = shootBulletAtEntity(player, bullet);
+ // Testing missile.
+ Entity missile = createEntity(ENTITY_GUIDED_MISSILE, game);
+ missile.position = entity->position;
+ scheduleEntityToAdd(&game->world, missile);
+
data->timeSinceLastBulletShot = t;
}
@@ -123,14 +128,14 @@ void updateMaresciallo(Game * game, Entity * entity) {
circlePlayerMaresciallo(game, entity);
}
+ updateGunMaresciallo(game, entity);
+
entityCheckTransformedCollisionModel(entity);
}
void drawMaresciallo(Game * game, Entity * entity) {
entityDraw(entity);
- updateGunMaresciallo(game, entity);
-
// Entity * player = getEntityFromWorld(game->world, 0);
// DrawLine3D(entity->position, player->position, BLUE);
}
diff --git a/src/entities/maresciallo.h b/src/entities/maresciallo.h
index 7624f8f..a88910c 100644
--- a/src/entities/maresciallo.h
+++ b/src/entities/maresciallo.h
@@ -9,7 +9,7 @@
#define MARESCIALLO_ROTATION_SPEED 20.0
#define MARESCIALLO_CIRCLE_PLAYER_SPEED 1.0
-#define MARESCIALLO_COOLDOWN 1.0
+#define MARESCIALLO_COOLDOWN 3.0
#define MARESCIALLO_BULLET_DAMAGE 0.01
typedef struct Maresciallo {
diff --git a/src/game.c b/src/game.c
index 3ad72b8..c820fef 100644
--- a/src/game.c
+++ b/src/game.c
@@ -35,7 +35,7 @@ void initGame(Game * game) {
WorldEntry entries[2] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_GUIDED_MISSILE, (Vector3){0.0, 0.0, 100.0}, QuaternionIdentity()}
+ (WorldEntry){ENTITY_MARESCIALLO, (Vector3){0.0, 0.0, 100.0}, QuaternionIdentity()}
};
addEntriesToWorld(
diff --git a/src/playerCamera.c b/src/playerCamera.c
index f759166..096ee36 100644
--- a/src/playerCamera.c
+++ b/src/playerCamera.c
@@ -23,7 +23,7 @@ void updatePlayerCamera(Camera3D * camera, Game * game) {
// Up.
camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
- camera->target = player->position;
- camera->position = (Vector3){10.0, 10.0, 10.0};
- camera->up = (Vector3){0.0, 1.0, 0.0};
+ // camera->target = player->position;
+ // camera->position = (Vector3){10.0, 10.0, 10.0};
+ // camera->up = (Vector3){0.0, 1.0, 0.0};
}
diff --git a/src/world.c b/src/world.c
index ebfc7ed..26ac9cd 100644
--- a/src/world.c
+++ b/src/world.c
@@ -13,6 +13,9 @@ void initWorld(World * world) {
world->vacantIds = NULL;
world->vacantIdsCount = 0;
+ world->entitiesToAdd = NULL;
+ world->entitiesToAddCount = 0;
+
// Set current fingerprint.
SetRandomSeed(time(NULL));
@@ -227,6 +230,49 @@ KfError removeEntityFromWorld(World * world, EntityId id) {
return KFSUCCESS;
}
+KfError scheduleEntityToAdd(World * world, Entity entity) {
+ ++world->entitiesToAddCount;
+
+ // Allocate shit.
+ if (world->entitiesToAdd == NULL)
+ world->entitiesToAdd = (Entity*)KF_CALLOC(world->entitiesToAddCount, sizeof(Entity));
+ else
+ world->entitiesToAdd = (Entity*)KF_REALLOCARRAY(
+ world->entitiesToAdd,
+ world->entitiesToAddCount,
+ sizeof(Entity)
+ );
+
+ if (world->entitiesToAdd == NULL) {
+ ALLOCATION_ERROR;
+ return KFERROR;
+ }
+
+ world->entitiesToAdd[world->entitiesToAddCount - 1] = entity;
+ return KFSUCCESS;
+}
+
+KfError handleScheduledEntities(World * world) {
+ int i;
+
+ // No entities to add.
+ if (world->entitiesToAdd == NULL)
+ return KFSUCCESS;
+
+ for (i = 0; i < world->entitiesToAddCount; ++i) {
+ // Add entity indeed.
+ if (addEntityToWorld(world, world->entitiesToAdd[i]) == ENTITY_NONE)
+ return KFERROR;
+ }
+
+ // Clean up this shit.
+ KF_FREE(world->entitiesToAdd);
+ world->entitiesToAdd = NULL;
+ world->entitiesToAddCount = 0;
+
+ return KFSUCCESS;
+}
+
void handleCollisionInWorld(Entity * entity1, Entity * entity2) {
//if (entity1->id != 0)
// entity1->health = 0.0;
@@ -303,6 +349,9 @@ void updateWorld(World * world, Game * game) {
removeEntityFromWorld(world, kills[i]);
}
+
+ // Handle some shit.
+ handleScheduledEntities(world);
}
void drawWorld(World * world, Game * game) {
diff --git a/src/world.h b/src/world.h
index 9e36dc7..d714649 100644
--- a/src/world.h
+++ b/src/world.h
@@ -18,6 +18,9 @@ typedef struct World {
EntityId * vacantIds;
size_t vacantIdsCount;
+ Entity * entitiesToAdd;
+ size_t entitiesToAddCount;
+
// Used for making fingerprints for entities.
EntityFingerprint currentFingerprint;
} World;
@@ -32,6 +35,10 @@ Entity * getEntityFromWorld(World world, EntityId id);
EntityId addEntityToWorld(World * world, Entity entity);
KfError removeEntityFromWorld(World * world, EntityId id);
+// Entities can't be added to world during update loop so we schedule the mother fuckers.
+KfError scheduleEntityToAdd(World * world, Entity entity);
+KfError handleScheduledEntities(World * world);
+
void updateWorld(World * world, Game * game);
void drawWorld(World * world, Game * game);