aboutsummaryrefslogtreecommitdiff
path: root/src/entities/caporale.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/caporale.c')
-rw-r--r--src/entities/caporale.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/entities/caporale.c b/src/entities/caporale.c
index e4566dd..3b29784 100644
--- a/src/entities/caporale.c
+++ b/src/entities/caporale.c
@@ -29,6 +29,7 @@ void initCaporale(Entity * entity, Game * game) {
};
data->timeSinceLastShot = 0.0;
+ data->gunTarget = Vector3One();
}
void closeCaporale(Entity * entity) {
@@ -44,31 +45,23 @@ void updateGunsCaporale(Game * game, Entity * entity) {
Caporale * data = (Caporale*)entity->data;
Entity * player = getEntityFromWorld(game->world, 0);
+ // Update gun target.
+ Vector3 target = Vector3Normalize(Vector3Subtract(player->position, entity->position));
+ data->gunTarget = Vector3Lerp(data->gunTarget, target, GetFrameTime() * CAPORALE_GUN_TARGETING_SPEED);
+
// Cool down.
if (t - data->timeSinceLastShot < CAPORALE_COOLDOWN)
return;
data->timeSinceLastShot = t;
- // Use random number to decide if hit.
- SetRandomSeed(time(NULL));
-
- if (GetRandomValue(1, CAPORALE_CHANGE_OF_HIT) != 1)
- return;
-
- // If random thingy shoot bullet that can't miss.
-
- // Get direction.
- Vector3 direction = Vector3Subtract(player->position, entity->position);
- direction = Vector3Normalize(direction);
-
float damage = CAPORALE_BULLET_DAMAGE;
if (entity->health <= CAPORALE_LOW_HEALTH_THRESHOLD)
damage = CAPORALE_LOW_HEALTH_BULLET_DAMAGE;
// Create bullet and shoot.
- Bullet bullet = createBulletFromDirection(*entity, direction, damage);
+ Bullet bullet = createBulletFromDirection(*entity, data->gunTarget, damage);
shootBulletAtEntity(player, bullet);
}