diff options
Diffstat (limited to 'src/entities/soldato.c')
-rw-r--r-- | src/entities/soldato.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c index 69dd99a..f4ef912 100644 --- a/src/entities/soldato.c +++ b/src/entities/soldato.c @@ -20,6 +20,8 @@ void initSoldato(Entity * entity, Game * game) { Soldato * data = (Soldato*)entity->data; + data->timeSinceLastShot = GetTime(); + PIDConfig followingPID = (PIDConfig){ .kP = 1.0, .kI = 0.0, @@ -100,6 +102,36 @@ void handleFollower(Game * game, Entity * entity) { } } +void updateSoldatoGuns(Game * game, Entity * entity) { + double t = GetTime(); + Entity * player = getEntityFromWorld(game->world, 0); + Soldato * data = (Soldato*)entity->data; + + // Needs more time. + if (t - data->timeSinceLastShot < SOLDATO_COOLDOWN) + return; + + Bullet bullet = createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE); + shootBulletAtEntity(player, bullet); + data->timeSinceLastShot = t; + + /* + // See if ray hits player radius. + Ray ray = (Ray){ + entity->position, + Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation) + }; + + RayCollision collision = traceRayToEntityRadius(*player, ray, SOLDATO_AIM_RADIOUS); + + // Shoots bullet is ray hits. + if (collision.hit) { + shootBulletAtEntity(player, createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE)); + data->timeSinceLastShot = t; + } + */ +} + void updateSoldato(Game * game, Entity * entity) { entityUpdateLastValues(entity); @@ -108,22 +140,21 @@ void updateSoldato(Game * game, Entity * entity) { // Fly to player if no leader. if (entity->follow.leaderId == ENTITY_NONE) { - entityFlyToPoint( - entity, - player->position, - &data->flyToPointLeading - ); + entityFlyToPoint(entity, player->position, &data->flyToPointLeading); } else { soldatoFollowLeader(game, entity); handleFollower(game, entity); } + updateSoldatoGuns(game, entity); + entityCheckTransformedCollisionModel(entity); } void drawSoldato(Game * game, Entity * entity) { entityDraw(entity); + /* Entity * leader; // Debug line. @@ -135,6 +166,7 @@ void drawSoldato(Game * game, Entity * entity) { DrawLine3D(entity->position, leader->position, BLUE); } + */ } void setSoldatoLeader(Entity * entity1, Entity * entity2) { |