diff options
Diffstat (limited to 'src/entities/soldato.c')
-rw-r--r-- | src/entities/soldato.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/entities/soldato.c b/src/entities/soldato.c index 4230177..8372345 100644 --- a/src/entities/soldato.c +++ b/src/entities/soldato.c @@ -29,24 +29,26 @@ void initSoldato(Entity * entity, Game * game) { .angleMode = false, .doClamp = true, .min = 0.0, - .max = 50.0 + .max = 80.0 }; // Create fly to point. data->flyToPointLeading = (EntityFlyToPointInfo){ - .controller.bangbang.speed = 50, + .controller.bangbang.speed = 80.0, .controller.bangbang.stopAt = 0.0, .controlType = ENTITY_FLY_TO_POINT_BANG_BANG, - .rotationSpeed = 50.0, + .rotationSpeed = SOLDATO_ROTATION_SPEED, .applyRotation = true }; data->flyToPointFollowing = (EntityFlyToPointInfo){ .controller.speedPID = createPID(followingPID), .controlType = ENTITY_FLY_TO_POINT_PID, - .rotationSpeed = 50.0, + .rotationSpeed = SOLDATO_ROTATION_SPEED, .applyRotation = true }; + + data->gunTarget = Vector3One(); } void closeSoldato(Entity * entity) { @@ -108,30 +110,25 @@ void updateSoldatoGuns(Game * game, Entity * entity) { double t = GetTime(); Entity * player = getEntityFromWorld(game->world, 0); Soldato * data = (Soldato*)entity->data; + + // Gun target shit. + Vector3 target = Vector3Normalize(Vector3Subtract(player->position, entity->position)); + data->gunTarget = Vector3Lerp(data->gunTarget, target, GetFrameTime() * SOLDATO_GUN_TARGETING_SPEED); // Needs more time. if (t - data->timeSinceLastShot < SOLDATO_COOLDOWN) return; - Bullet bullet = createBulletFromEntity(*entity, SOLDATO_BULLET_DAMAGE); - shootBulletAtEntity(player, bullet); - data->timeSinceLastShot = t; + // Shoot if in range. + if (Vector3Distance(entity->position, player->position) <= SOLDATO_GUN_MAX_RANGE) { + Bullet bullet = createBulletFromDirection(*entity, data->gunTarget, SOLDATO_BULLET_DAMAGE); + BulletHitInfo hit = shootBulletAtEntity(player, bullet); - /* - // 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; + if (hit.hit) + printf("This fucker hit %lf\n", t); } - */ + + data->timeSinceLastShot = t; } void updateSoldato(Game * game, Entity * entity) { @@ -156,6 +153,16 @@ void updateSoldato(Game * game, Entity * entity) { void drawSoldato(Game * game, Entity * entity) { entityDraw(entity); + // Debug gun. + /* + Soldato * data = (Soldato*)entity->data; + DrawLine3D( + entity->position, + Vector3Add(entity->position, Vector3Scale(data->gunTarget, SOLDATO_GUN_MAX_RANGE)), + BLUE + ); + */ + /* Entity * leader; |