/// <summary> /// Ngược lại, sử dụng millisecondsPerFrame từ Constructor. /// </summary> public Enemy ( GameplayScreen gameplayScreen, Texture2D botTexture, Texture2D topTexture, Color color, AItype AItypeID, WeaponSet weaponSet, Vector2 position, float rotationAngle, Vector2 maximumSpeed, int hitPoints, Point frameSize, Point sheetSize, Point frameSizeTop, Point sheetSizeTop, int millisecondsPerFrame ) : base ( gameplayScreen, botTexture, topTexture, color, position, rotationAngle, maximumSpeed, hitPoints, frameSize, sheetSize, frameSizeTop, sheetSizeTop, millisecondsPerFrame ) { this.AItypeID = AItypeID; this.typeID = 89; this.weaponSet = weaponSet; this.typeIndex = GameplayScreen.EnemyList.Count; AIrotate = RotationAngle; AIcommingposition = CurrentMapPosition; CurrentMapPosition = PreviousMapPosition = Map.GetSquareAtPixel(CurrentWorldPosition); CurrentMapPositionIndex = PreviousMapPositionIndex = 1; Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y] [CurrentMapPositionIndex, 0] = typeID; Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y] [CurrentMapPositionIndex, 1] = typeIndex; }
// Ngược lại, sử dụng custom millisecondsPerFrame public Player ( GameplayScreen gameplayScreen, Texture2D botTexture, Texture2D topTexture, Color color, Vector2 position, float rotationAngle, Vector2 maximumSpeed, int hitPoints, Point frameSize, Point sheetSize, Point frameSizeTop, Point sheetSizeTop, int millisecondsPerFrame ) : base ( gameplayScreen, botTexture, topTexture, color, position, rotationAngle, maximumSpeed, hitPoints, frameSize, sheetSize, frameSizeTop, sheetSizeTop, millisecondsPerFrame ) { this.typeID = 88; this.typeIndex = -1; this.powerState = Power.Armor; CurrentMapPosition = PreviousMapPosition = Map.GetSquareAtPixel(CurrentWorldPosition); CurrentMapPositionIndex = PreviousMapPositionIndex = 1; Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y] [CurrentMapPositionIndex, 0] = typeID; Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y] [CurrentMapPositionIndex, 1] = typeIndex; }
public virtual void UpdateMapPosition() { if (CurrentMapPosition != Map.GetSquareAtPixel(CurrentWorldPosition)) { PreviousMapPosition = CurrentMapPosition; CurrentMapPosition = Map.GetSquareAtPixel(CurrentWorldPosition); } }
public override void UpdateMapPosition() { Map.MapSquares [CurrentMapPosition.X, CurrentMapPosition.Y] [CurrentMapPositionIndex, 0] = typeID; Map.MapSquares [CurrentMapPosition.X, CurrentMapPosition.Y] [CurrentMapPositionIndex, 1] = typeIndex; if (CurrentMapPosition != Map.GetSquareAtPixel(CurrentWorldPosition)) { PreviousMapPosition = CurrentMapPosition; CurrentMapPosition = Map.GetSquareAtPixel(CurrentWorldPosition); for (int i = 1; i < 4; i++) { if (Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y][i, 0] == 0) { Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y][i, 0] = typeID; Map.MapSquares [(int)CurrentMapPosition.X, (int)CurrentMapPosition.Y][i, 1] = typeIndex; PreviousMapPositionIndex = CurrentMapPositionIndex; CurrentMapPositionIndex = i; break; } } Map.MapSquares [(int)PreviousMapPosition.X, (int)PreviousMapPosition.Y] [PreviousMapPositionIndex, 0] = Map.MapSquares [(int)PreviousMapPosition.X, (int)PreviousMapPosition.Y] [PreviousMapPositionIndex, 1] = 0; } }
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); }