diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-11 22:00:33 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-11 22:00:33 -0600 |
commit | c759231e1e8570ffe5fdda2f1eb5d011b1c6a29f (patch) | |
tree | 698f507b15e4fcb7dc25aa61c445ffbc3b604ac5 /src/entities/guidedMissile.c | |
parent | dc23e1b7eafb595808ba161a4b91c8ce49af279f (diff) |
Guided missile somewhat worky
Diffstat (limited to 'src/entities/guidedMissile.c')
-rw-r--r-- | src/entities/guidedMissile.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/entities/guidedMissile.c b/src/entities/guidedMissile.c index 744e1cb..53cbaf8 100644 --- a/src/entities/guidedMissile.c +++ b/src/entities/guidedMissile.c @@ -3,10 +3,28 @@ #include "game.h" void initGuidedMissile(Entity * entity, Game * game) { - entity->model = &game->assets.models[MARESCIALLO_ASSET]; + entity->model = &game->assets.models[GUIDED_MISSILE_ASSET]; entity->collisionModel = entityCreateCollisionModel(*entity->model); entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model); setEntityRadius(entity); + + // Allocate data. + entity->data = KF_MALLOC(sizeof(GuidedMissile)); + + if (entity->data == NULL) { + ALLOCATION_ERROR; + return; + } + + GuidedMissile * data = (GuidedMissile*)entity->data; + + data->flyToPoint = (EntityFlyToPointInfo){ + .controller.bangbang.speed = 80, + .controller.bangbang.stopAt = 0.0, + .controlType = ENTITY_FLY_TO_POINT_BANG_BANG, + .rotationSpeed = 20.0, + .applyRotation = true + }; } void closeGuidedMissile(Entity * entity) { @@ -19,11 +37,35 @@ void closeGuidedMissile(Entity * entity) { void updateGuidedMissile(Game * game, Entity * entity) { entityUpdateLastValues(entity); - // hi + + Entity * player = getEntityFromWorld(game->world, 0); + GuidedMissile * data = (GuidedMissile*)entity->data; + + entityFlyToPoint(entity, player->position, &data->flyToPoint); + + // boom boom time + if (Vector3Distance(player->position, entity->position) <= GUIDED_MISSILE_BOOM_BOOM_AT) + guidedMissileGoBoomBoom(game, entity); entityCheckTransformedCollisionModel(entity); } void drawGuidedMissile(Game * game, Entity * entity) { entityDraw(entity); -}
\ No newline at end of file +} + +void guidedMissileGoBoomBoom(Game * game, Entity * entity) { + Entity * player = getEntityFromWorld(game->world, 0); + + // Get player distance and get the damage the missile will do. + float distance = Vector3Distance(player->position, entity->position); + float damage = distance * GUIDED_MISSILE_DAMAGE; + + // Hurt this mother fucker. + player->health -= damage; + + // 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); +} |