public override void Update() { if (waitCount > 0) { double newX = waitX + swingWidth * Utility.Sin(Game.Ticks * 8); double newY = waitY + swingHeight * Utility.Sin(Game.Ticks * 8); vx = newX - X; vy = newY - Y; X = newX; Y = newY; waitCount--; } if (waitCount == 0) { if (!attacking) { if (angle == 90) { angle += Game.Random.Next(2) == 0 ? 1 : -1; } else { int deg = Utility.NormalizeDeg(270 - angle); if (Math.Abs(deg) < 8) { angle = 270; attacking = true; } else { if (deg < 0) { angle -= 8; } else if (deg > 0) { angle += 8; } } } vx += 0.5 * Utility.Cos(angle); vy -= 0.5 * Utility.Sin(angle); Move(); } else { if (X < Game.Player.X + playerXTraceOffset) { vx += 0.25; } else if (X > Game.Player.X + playerXTraceOffset) { vx -= 0.25; } vy += 0.25; Move(); { int deg = Utility.NormalizeDeg(Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X) - angle); if (deg == -180) { angle += Game.Random.Next(2) == 0 ? 1 : -1; } else if (Math.Abs(deg) < 4) { angle = Utility.Atan2(Y - Game.Player.Y, Game.Player.X - X); } else { if (deg < 0) { angle -= 4; } else if (deg > 0) { angle += 4; } } } if (fireCount > 0) { fireCount--; } else if (!Game.Player.IsDead) { Bullet bullet = new TekiBullet(Game, X + 32 * Utility.Cos(angle), Y - 32 * Utility.Sin(angle), 8, angle); Game.AddEnemyBullet(bullet); Game.PlaySound(Sound.EnemyFire); playerXTraceOffset = Game.Random.Next(-96, 96 + 1); fireCount = Game.Random.Next(30, 60); } } } }