void defend() { var center = GetCenter(); var data = properties.UpgradeData; if (lockOnEnemy != null) { if (lockOnEnemy.IsRemoved) { lockOnEnemy = null; return; } var distance = Vector2.DistanceSquared(center, lockOnEnemy.Position); var min = properties.MinRange * properties.MinRange; var max = data.Range * data.Range; if (distance < min || distance > max) { lockOnEnemy = null; return; } var barrel = position + properties.GridOffset + properties.BarrelOffset; var enemy = lockOnEnemy.GetAttackOffset(); var angle = (float)Math.Atan2(barrel.Y - enemy.Y, barrel.X - enemy.X) + MathHelper.ToRadians(90); setTowerAngle(angle); shootBullet(enemy); } else { var enemies = world.GetEntitiesInRange( center, data.Range, EntityType.AI); if (enemies.Count == 0) { return; } lockOnEnemy = (EnemyEntity)enemies[0]; } }