public void EnableActionCamera(AbstractPiece movingPiece, AbstractPiece dyingPiece) { // The action camera will always point towards a dying object from the initial position of the object destroying it GameKeeper gameKeeper = GameObject.Find(Constants.PieceNames.ChessBoard).GetComponent <GameKeeper>(); if (movingPiece.side == Side.White) { // Positive music this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.RebelAttack, typeof(AudioClip)); } if (movingPiece.side == Side.Black) { // Badass music this.deathAudioSource.clip = (AudioClip)Resources.Load(Constants.AudioClipNames.AudioDirectory + Constants.AudioClipNames.ImperialMarch, typeof(AudioClip)); } StartCoroutine(this.PlayDeathMusic()); Vector3 forward = gameKeeper.GetTransformFromPosition(movingPiece.GetCurrentPosition()) - gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition()); Vector3 up = new Vector3(0, 1, 0); Vector3 cameraPosition = gameKeeper.GetTransformFromPosition(dyingPiece.GetCurrentPosition()) - 2 * gameKeeper.GetSquareSpacing() * forward.normalized; cameraPosition.y = 1; this.gameObject.GetComponent <Transform>().position = cameraPosition; this.gameObject.GetComponent <Transform>().rotation = Quaternion.LookRotation(forward, up); GameObject.Find(Constants.MainCameraObject).GetComponent <Camera>().enabled = false; this.gameObject.GetComponent <Camera>().enabled = true; }
// Called by pieces whenever they need to move public void MoveTo(AbstractPiece piece, Position position) { // First, modify the relevant bitboard(s) if (piece.side == Side.Black) { this.blackPieceLocations.FlipPosition(piece.GetCurrentPosition()); this.blackPieceLocations.FlipPosition(position); } else { this.whitePieceLocations.FlipPosition(piece.GetCurrentPosition()); this.whitePieceLocations.FlipPosition(position); } // Kill anything that gets in the way this.KillPieceAtPosition(position, piece); // Now, actually move the piece piece.SetCurrentPosition(position); piece.PostMoveActions(); }
public void AddPiece(AbstractPiece newPiece) { AbstractPiece existingPiece = null; // Assuming the piece's position is already set... foreach (AbstractPiece piece in this.activePieces) { if (newPiece.GetCurrentPosition() == piece.GetCurrentPosition()) { // This handles pawn promotion existingPiece = piece; } } if (existingPiece != null) { this.activePieces.Remove(existingPiece); } this.activePieces.Add(newPiece); }
public override void PostMoveActions() { // If the pawn has moved two steps this turn, it is allowed to be captured via the en passant rule if (this.side == Side.Black) { if (this.GetCurrentPosition().Equals(new Position(this.initialPosition.GetColumn(), this.initialPosition.GetRow() - 2))) { this.allowEnPassantCapture = true; } // The attacking pawn can check behind it to see if it passed an en passant-flagged pawn AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn(), this.GetCurrentPosition().GetRow() + 1)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { this.chessBoard.KillPieceAtPosition(passedPiece.GetCurrentPosition(), this); } } else { if (this.GetCurrentPosition().Equals(new Position(this.initialPosition.GetColumn(), this.initialPosition.GetRow() + 2))) { this.allowEnPassantCapture = true; } AbstractPiece passedPiece = this.chessBoard.GetPieceAtPosition(new Position(this.GetCurrentPosition().GetColumn(), this.GetCurrentPosition().GetRow() - 1)); if (passedPiece != null && passedPiece.GetType().Name.CompareTo(this.GetType().Name) == 0 && ((Pawn)passedPiece).allowEnPassantCapture) { this.chessBoard.KillPieceAtPosition(passedPiece.GetCurrentPosition(), this); } } // Pawn Promotion if (this.side == Side.Black && this.GetCurrentPosition().GetRow() == Position.min || this.side == Side.White && this.GetCurrentPosition().GetRow() == Position.max) { Queen spawnedQueen = new Queen(this.currentPosition); spawnedQueen.side = this.side; spawnedQueen.SetChessboard(this.chessBoard); this.chessBoard.AddPiece(spawnedQueen); } }