private void InitializeAIMap() { Enemy.Mmap = Map.MapWidth; Enemy.Nmap = Map.MapHeight; Enemy.AImap = new double[Enemy.Nmap, Enemy.Mmap]; for (int y = 0; y < Map.MapHeight; y++) { for (int x = 0; x < Map.MapWidth; x++) { if (Map.IsWallTile(x, y)) { Enemy.AImap[y, x] = -1; } else if (Map.IsWaterTile(x, y)) { Enemy.AImap[y, x] = 2; } else { Enemy.AImap[y, x] = 1; } } } Enemy.preProcessMap(); }
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) ) ); } } } }
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) ) ); } } }
public int AIshootcheck(double fromX, double fromY, double toX, double toY) { // Lấy góc địa điểm hiện tại của tank so với tọa độ (x, y). double angle = GetAngle(fromX, fromY, toX, toY); if (angle.Equals(double.NaN)) { return(2); } // Độ chính xác trong khi check. const int checkingAccuracy = 64; Point checkingSquare = Point.Zero; Vector2 offset = Vector2.Zero; int i = 1; int Allyflag = 0, Enemyflag = 0, Wallflag = 0; // Check cho đến khi ô đang check trùng với ô đích. while (checkingSquare != Map.GetSquareAtPixel(new Vector2((float)toX, (float)toY)) && checkingSquare.X >= 0 && checkingSquare.Y >= 0 && checkingSquare.X < Map.MapWidth && checkingSquare.Y < Map.MapHeight) { // Tính tọa độ của ô sắp check offset.X = i * checkingAccuracy * (float)Math.Cos(angle); offset.Y = i * checkingAccuracy * (float)Math.Sin(angle); i++; checkingSquare = Map.GetSquareAtPixel(this.CurrentWorldPosition + offset); // Đọc dữ liệu của ô. // [0,0] chứa thông tin địa hình. // [1,0] chứa sự tồn tại của người chơi. // [2,0] và [3,0] chứa sự tồn tại của Enemy. ([3,0] để dự // phòng trường hợp xấu nhất có 2 Enemy Tanks trong cùng // một ô) if (Map.IsWallTile(checkingSquare)) { // Return sự hiện diện của người chơi, tránh trường hợp // người chơi lợi dụng đứng trong tường và bắn ra. if (Map.IsOccupiedByPlayer(checkingSquare)) { Enemyflag = 1; break; } Wallflag = 1; break; } if (Map.IsOccupiedByEnemy(checkingSquare)) { Allyflag = 1; } if (Map.IsOccupiedByPlayer(checkingSquare)) { Enemyflag = 1; break; } } if (Wallflag == 1) { return(1); } else if (Enemyflag == 1) { if (Allyflag == 1) { return(3); } else { return(2); } } return(0); }