// AI sẽ move đến ô destinationSquare kế cận. private void MoveTo(Point destinationSquare) { if (destinationSquare.X <= 0 || destinationSquare.Y <= 0) { return; } //1234AI bug: if (!Map.IsOccupiedByTank(destinationSquare)) if (!Map.IsOccupiedByTank(destinationSquare) || destinationSquare == CurrentMapPosition) { Vector2 destination = Map.GetSquareCenter (destinationSquare.X, destinationSquare.Y); float newRotationAngle = (float)GetAngle (this.CurrentWorldPosition.X, this.CurrentWorldPosition.Y, destination.X, destination.Y); RotationAngle = Rotate(RotationAngle, newRotationAngle, 0.05f); MovingSpeed += new Vector2(0.5f, 0.0f); CurrentWorldPosition += MovingOffset; } }
private void RandomMovableEnemy() { MovableEnemiesCount = 0; ImmovableEnemiesCount = 0; foreach (Enemy enemy in EnemyList) { if (enemy.AItypeID != AItype.StationaryAI) { MovableEnemiesCount++; } } ImmovableEnemiesCount = EnemyList.Count - MovableEnemiesCount; Random random = new Random(); if (ImmovableEnemiesCount > 0 && MovableEnemiesCount < MaximumMovableEnemies) { Start: int A = random.Next(0, Map.MapWidth - 1); int B = random.Next(0, Map.MapHeight - 1); if (Map.IsWallTile(A, B) || Camera.ObjectIsVisible(new Rectangle(A * 64, B * 64, 64, 64))) { goto Start; } for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (Map.IsOccupiedByTank(A + i, B + j)) { goto Start; } } } if (random.NextDouble() > 0.5) { EnemyList.Add ( new Enemy ( this, Content.Texture.TankBot, Content.Texture.TankTop, new Color(150, 200, 200), AItype.ForcedOffensiveAI, WeaponSet.StandardSet, Map.GetSquareCenter(new Point(A, B)), 0, new Vector2(2, 2), 300, new Point(45, 45), new Point(1, 1), new Point(70, 70), new Point(1, 1) ) ); } else { EnemyList.Add ( new Enemy ( this, Content.Texture.HumveeBot, Content.Texture.HumveeTop, new Color(255, 230, 180), AItype.ForcedOffensiveAI, WeaponSet.MachineGunOnly, Map.GetSquareCenter(new Point(A, B)), 0, new Vector2(4, 4), 100, new Point(45, 45), new Point(1, 1), new Point(45, 45), new Point(1, 1) ) ); } } }
private void InitializeTanks() { Vector2 playerStartingPoint = Map.GetSpawningLocation(); float playerStartingRotation = Map.GetSpawningRotation(); Player = new Player ( this, Content.Texture.TankBot, Content.Texture.TankTop, new Color(200, 180, 140), playerStartingPoint, playerStartingRotation, new Vector2(3, 3), 3000, new Point(45, 45), new Point(1, 1), new Point(70, 70), new Point(1, 1) ); if (CurrentGameMode == GameMode.Campaign) { for (int i = 0; i < Map.MapWidth; i++) { for (int j = 0; j < Map.MapHeight; j++) { if (Map.IsEliteSpawnTile(i, j)) { EnemyList.Add (new Enemy ( this, Content.Texture.TankBot, Content.Texture.TankTop, Color.GhostWhite, AItype.StationaryAI, WeaponSet.CannonOnly, Map.GetSquareCenter(new Point(i, j)), 0, Vector2.Zero, 500, new Point(45, 45), new Point(1, 1), new Point(70, 70), new Point(1, 1) ) ); } } } } else if (CurrentGameMode == GameMode.LaserTorture) { Random random = new Random(); while (EnemyList.Count < MaximumMovableEnemies) { Start: int A = random.Next(0, Map.MapWidth - 1); int B = random.Next(0, Map.MapHeight - 1); if (Map.IsWallTile(A, B) || Camera.ObjectIsVisible(new Rectangle(A * 64, B * 64, 64, 64))) { goto Start; } for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { if (Map.IsOccupiedByTank(A + i, B + j)) { goto Start; } } } if (random.NextDouble() > 0.5) { EnemyList.Add ( new Enemy ( this, Content.Texture.TankBot, Content.Texture.TankTop, new Color(150, 200, 200), AItype.ForcedOffensiveAI, WeaponSet.LaserSet, Map.GetSquareCenter(new Point(A, B)), 0, new Vector2(2, 2), 300, new Point(45, 45), new Point(1, 1), new Point(70, 70), new Point(1, 1) ) ); } else { EnemyList.Add ( new Enemy ( this, Content.Texture.HumveeBot, Content.Texture.HumveeTop, new Color(255, 230, 180), AItype.ForcedOffensiveAI, WeaponSet.GatlingLaserOnly, Map.GetSquareCenter(new Point(A, B)), 0, new Vector2(4, 4), 100, new Point(45, 45), new Point(1, 1), new Point(45, 45), new Point(1, 1) ) ); } } } }