public override void Logic() { SearchTarget(); if (target != null) { if (!target.IsAlive || !TargetInArea(target)) { SetTarget(null); } else { float targetDir = TKMath.GetAngle(TurretPosition, target.Position); float dif = targetDir - aimDir; while (dif > 180) { dif -= 360; } while (dif < -180) { dif += 360; } aimDir += dif * TurnSpeed * Game.delta; aimDir = TKMath.Mod(aimDir, -180, 180); if (ammo <= 0) { reloadTimer.Logic(); if (reloadTimer.IsDone) { ammo = MaxAmmo; reloadTimer.Reset(); } } else { shootTimer.Logic(); if (shootTimer.IsDone) { if (!Map.RayTraceCollision(TurretPosition, target.Position, Vector2.Zero)) { Shoot(); shootTimer.Reset(); } } } } } else { aimDir += 25f * Game.delta; } }
public override void Logic() { if (target != null) { float targetDir = TKMath.GetAngle(TurretPosition, target.Position); float dif = targetDir - aimDir; while (dif > 180) { dif -= 360; } while (dif < -180) { dif += 360; } aimDir += dif * TurnSpeed * Game.delta; aimDir = TKMath.Mod(aimDir, -180, 180); if (ammo <= 0) { reloadTimer.Logic(); if (reloadTimer.IsDone) { ammo = 5; } } } else { aimDir += 25f * Game.delta; } barrelPosition -= barrelPosition * 5f * Game.delta; headSprite.Rotation = aimDir; }