void GetVertical() { myVM = new VerticalMovement(); myVM.player = gameObject; myVM.groundChecker = groundChecker; myVM.airControlMult = airControlMult; }
void Start() { if (moveComponent == null) { moveComponent = GetComponent <VerticalMovement>(); } }
public IChessGame Create() { var piecesFactory = new PiecesFactory(); var movementHistory = new MovementHistory(); var piecePromoter = new PiecePromoter(movementHistory); var castlingMover = new CastlingMover(movementHistory); var enPassantMover = new EnPassantMover(movementHistory); var pieceMover = new PieceMover(movementHistory, piecePromoter, castlingMover, enPassantMover); var chessBoard = new ChessBoard(piecesFactory, pieceMover); List <IMovement> movements = new(); var pawnMovement = new PawnMovement(chessBoard); var enPassantMovement = new EnPassantMovement(chessBoard); var kingMovement = new KingMovement(chessBoard); var horizontalMovement = new HorizontalMovement(chessBoard); var verticalMovement = new VerticalMovement(chessBoard); var pdiagonalMovement = new PositiveDiagonalMovement(chessBoard); var ndiagonalMovement = new NegativeDiagonalMovement(chessBoard); var knightMovement = new KnightMovement(chessBoard); movements.Add(pawnMovement); movements.Add(enPassantMovement); movements.Add(kingMovement); movements.Add(horizontalMovement); movements.Add(verticalMovement); movements.Add(pdiagonalMovement); movements.Add(ndiagonalMovement); movements.Add(knightMovement); var movementComposite = new MovementComposite(movements); List <IMovement> movementsWithCastling = new(); var queensideCastlingMovement = new QueensideCastlingMovement(chessBoard, movementComposite); var kingsideCastlingMovement = new KingsideCastlingMovement(chessBoard, movementComposite); movementsWithCastling.Add(movementComposite); movementsWithCastling.Add(queensideCastlingMovement); movementsWithCastling.Add(kingsideCastlingMovement); var movementCompositeWithCastling = new MovementComposite(movementsWithCastling); var promotionDetector = new PromotionDetector(chessBoard); var checkDetector = new CheckDetector(chessBoard, movementCompositeWithCastling); var legalMovement = new LegalMovement(chessBoard, movementCompositeWithCastling, checkDetector); var moveValidator = new MoveValidator(chessBoard, legalMovement, promotionDetector); var gameFinishedDetector = new GameFinishedDetector(checkDetector, legalMovement); return(new ChessGame(chessBoard, moveValidator, promotionDetector, gameFinishedDetector, legalMovement)); }
void Update() { ApostleCollisionHandler.StartCollisions(HorizontalMovement.HorizontalMovementState, ApostleStatusVariables.facingDirection); HorizontalMovement.StartMovement(); HorizontalMovement.PressMovementHandler(); VerticalMovement.StartMovement(); VerticalMovement.PressMovementHandler(); }
private void InitializeInputs() { Inputs.Player.Jump.performed += _ => PlayerInputs.JumpInput = true; Inputs.Player.CancelJump.performed += _ => PlayerInputs.JumpInput = false; Inputs.Player.Dash.performed += _ => PlayerInputs.DashInput = true; Inputs.Player.Dash.canceled += _ => PlayerInputs.DashInput = false; Inputs.Player.CancelJump.performed += (ctx) => { PlayerInputs.CanWallJump = true; PlayerInputs.JumpInputBuffer = 0; }; HorizontalMovement.Subscribe(HorizontalState.WallSticked, OnStateEnter, () => PlayerInputs.WallStickBuffer = 0); HorizontalMovement.Subscribe(HorizontalState.WallSticked, OnUpdate, () => { var wallDirection = Collisions.Left ? -1 : 1; // Sticks the player to wall for a short amount of time allowing him to perform easier wall jump var isLeavingWall = PlayerInputs.RunInput != 0 && Mathf.Sign(PlayerInputs.RunInput) != wallDirection; PlayerInputs.WallStickBuffer = isLeavingWall ? PlayerInputs.WallStickBuffer + Time.deltaTime : 0; }); VerticalMovement.Subscribe(VerticalState.Grounded, OnStateEnter, () => { PlayerInputs.CanWallJump = false; PlayerInputs.CanDash = true; }); VerticalMovement.Subscribe(VerticalState.Falling, OnUpdate, () => PlayerInputs.FallBuffer += Time.deltaTime); VerticalMovement.Subscribe(VerticalState.Falling, OnStateExit, () => PlayerInputs.FallBuffer = 0); Dash.Subscribe(DashState.Rest, OnStateEnter, () => { HorizontalMovement.IsLocked = false; VerticalMovement.IsLocked = false; }); Dash.Subscribe(DashState.Rest, OnStateExit, () => PlayerInputs.CanDash = false); Dash.Subscribe(DashState.Casting, OnStateEnter, () => { HorizontalMovement.IsLocked = true; VerticalMovement.IsLocked = true; }); Dash.Subscribe(DashState.Casting, OnUpdate, () => PlayerInputs.DashDirection = Inputs.Player.DashDirection.ReadValue <Vector2>()); Dash.Subscribe(DashState.Recovering, OnStateEnter, () => { VerticalMovement.IsLocked = false; HorizontalMovement.IsLocked = false; PlayerInputs.IsInDashRecovery = true; }); Dash.Subscribe(DashState.Recovering, OnStateExit, () => PlayerInputs.IsInDashRecovery = false); }
void Update() { PlayerCollisionHandler.StartCollisions(HorizontalMovement.HorizontalMovementState, PlayerStatusVariables.facingDirection); HorizontalMovement.StartMovement(); HorizontalMovement.PressMovementHandler(); VerticalMovement.StartMovement(); VerticalMovement.PressMovementHandler(); MiscellaneousMovement.StartMovement(); MiscellaneousMovement.PressMovementHandler(); CombatMovement.StartMovement(); CombatMovement.PressMovementHandler(); }
private void Start() { VerticalMovement = GetComponentInParent <VerticalMovement>(); Dash = GetComponentInParent <DashMovement>(); Shaker = GameObject.Find("Main Camera").GetComponent <CameraShaker>(); Fragments = fragments.Select(f => new Fragment() { Renderer = f.GetComponent <SpriteRenderer>(), Light = f.GetComponent <Light2D>() }) .ToArray(); foreach (var fragment in Fragments) { fragment.Light.enabled = false; fragment.Renderer.color = unActiveFragmentColor; } VerticalMovement.Subscribe(VerticalState.Rising, OnStateEnter, () => { Reset(); bool isSquash = VerticalMovement.PreviousState != VerticalState.WallSliding; JumpStretch = Stretch(isSquash); StartCoroutine(JumpStretch); }); VerticalMovement.Subscribe(VerticalState.Grounded, OnStateEnter, () => { Reset(); LandSquash = Stretch(false); StartCoroutine(LandSquash); }); Dash.Subscribe(DashState.Dashing, OnStateEnter, () => { Reset(); bool isSquash = Mathf.Abs(Inputs.DashDirection.y) == 1; DashStretch = Stretch(isSquash); StartCoroutine(DashStretch); if (CameraShake != null) { StopCoroutine(CameraShake); } CameraShake = Shaker.Shake(shakeDuration, shakeIntensity); StartCoroutine(CameraShake); }); }
private void HandleMovements() { float horizontalVelocity; float verticalVelocity; float LimitSpeed(float speed) { return(Mathf.Min(Mathf.Max(speed, -MaxRunSpeed), MaxRunSpeed)); } _inputHorizontalDirection = (HorizontalMovement)Convert.ToInt32(Input.IsActionPressed(Inputs.MoveRight)) - Convert.ToInt32(Input.IsActionPressed(Inputs.MoveLeft)); _inputVerticalDirection = (VerticalMovement)Convert.ToInt32(Input.IsActionPressed(Inputs.MoveDown)) - Convert.ToInt32(Input.IsActionPressed(Inputs.MoveUp)); if (_inputHorizontalDirection == HorizontalMovement.Left && Velocity.x > -MaxRunSpeed) { horizontalVelocity = LimitSpeed(Velocity.x - Acceleration); SetPlayerDirection(HorizontalMovement.Left); } else if (_inputHorizontalDirection == HorizontalMovement.Right && Velocity.x < MaxRunSpeed) { horizontalVelocity = LimitSpeed(Velocity.x + Acceleration); SetPlayerDirection(HorizontalMovement.Right); } else { horizontalVelocity = Mathf.Abs(Velocity.x) <= 1 ? 0 : Mathf.Lerp(Velocity.x, 0, Inertia); } if (_inputVerticalDirection == VerticalMovement.Up && Velocity.y > -MaxRunSpeed) { verticalVelocity = LimitSpeed(Velocity.y - Acceleration); } else if (_inputVerticalDirection == VerticalMovement.Down && Velocity.y < MaxRunSpeed) { verticalVelocity = LimitSpeed(Velocity.y + Acceleration); } else { verticalVelocity = Mathf.Abs(Velocity.y) <= 1 ? 0 : Mathf.Lerp(Velocity.y, 0, Inertia); } Velocity = new Vector2(horizontalVelocity, verticalVelocity); }
public void RookCanMoveVertically() { //WR - white rook //PM - possible move //7 PM //6 PM //5 PM //4 PM //3 PM //2 PM //1 WR //0 PM // 0 1 2 3 4 5 6 7 var boardMock = new Mock <IChessBoard>(MockBehavior.Strict); var rookMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var rookPosition = new Position(1, 1); var availableFinishPosition01 = new Position(1, 0); var availableFinishPosition02 = new Position(1, 2); var availableFinishPosition03 = new Position(1, 3); var availableFinishPosition04 = new Position(1, 4); var availableFinishPosition05 = new Position(1, 5); var availableFinishPosition06 = new Position(1, 6); var availableFinishPosition07 = new Position(1, 7); rookMock .SetupGet(p => p.Color) .Returns(ChessColor.White); rookMock .SetupGet(p => p.PieceType) .Returns(ChessPieceType.Rook); rookMock .SetupGet(p => p.Position) .Returns(rookPosition); rookMock .SetupGet(p => p.HasMoved) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(It.IsAny <Position>())) .Returns(false); boardMock .Setup(b => b.IsEnemyOnPosition(It.IsAny <Position>(), It.IsAny <ChessColor>())) .Returns(false); var movement = new VerticalMovement(boardMock.Object); var availableMoves = movement.GetAvailableMoves(rookMock.Object); Assert.AreEqual(7, availableMoves.Count()); Assert.IsTrue(availableMoves.All(m => m.StartingPosition == rookPosition)); var finishedPositions = availableMoves .Select(m => m.FinishedPosition) .ToList(); Assert.Contains(availableFinishPosition01, finishedPositions); Assert.Contains(availableFinishPosition02, finishedPositions); Assert.Contains(availableFinishPosition03, finishedPositions); Assert.Contains(availableFinishPosition04, finishedPositions); Assert.Contains(availableFinishPosition05, finishedPositions); Assert.Contains(availableFinishPosition06, finishedPositions); Assert.Contains(availableFinishPosition07, finishedPositions); }
public List <ItemMovementDetails> MoveVertical(VerticalMovement verticalMovement) { ResetWasJustDuplicatedValues(); var movementDetails = new List <ItemMovementDetails>(); int relativeRow = verticalMovement == VerticalMovement.Bottom ? -1 : 1; var rowNumbers = Enumerable.Range(0, Globals.Rows); if (verticalMovement == VerticalMovement.Top) { rowNumbers = rowNumbers.Reverse(); } for (int column = 0; column < Globals.Columns; column++) { foreach (int row in rowNumbers) { //if the item is null, continue checking for non-null items if (matrix[row, column] == null) { continue; } //we have a non-null item //first we check if this item has the same value as the next one ItemMovementDetails imd = AreTheseTwoItemsSame(row, column, row + relativeRow, column); if (imd != null) { movementDetails.Add(imd); continue; } //matrix[row,column] is the first not null item //move it to the first null item int rowFirstNullItem = -1; int numberOfItemsToTake = verticalMovement == VerticalMovement.Bottom ? row : Globals.Rows - row; bool emptyItemFound = false; foreach (var tempRowFirstNullItem in rowNumbers.Take(numberOfItemsToTake)) { rowFirstNullItem = tempRowFirstNullItem; if (matrix[rowFirstNullItem, column] == null) { emptyItemFound = true; break; } } if (!emptyItemFound) { continue; } ItemMovementDetails newImd = MoveItemToNullPositionAndCheckIfSameWithNextOne(row, rowFirstNullItem, rowFirstNullItem + relativeRow, column, column, column); movementDetails.Add(newImd); } } return(movementDetails); }
private void LateUpdate() { VerticalMovement.ResolvePendencies(); }
void Start() { PlayerAim = this.gameObject.GetComponent <AimAndShoot>(); PlayerMovement = this.gameObject.GetComponent <VerticalMovement>(); }
void FixedUpdate() { HorizontalMovement.HoldMovementHandler(); VerticalMovement.HoldMovementHandler(); }
public void QueenCantJumpThroughFriendlyPieces() { //WQ - white queen //PM - possible move //WP - white piece //7 //6 //5 WP //4 PM //3 WQ //2 WP //1 //0 // 0 1 2 3 4 5 6 7 var boardMock = new Mock <IChessBoard>(MockBehavior.Strict); var queenMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var queenPosition = new Position(3, 3); var pawn1Position = new Position(3, 2); var pawn2Position = new Position(3, 5); var availableFinishPosition = new Position(3, 4); queenMock .SetupGet(p => p.Color) .Returns(ChessColor.White); queenMock .SetupGet(p => p.PieceType) .Returns(ChessPieceType.Queen); queenMock .SetupGet(p => p.Position) .Returns(queenPosition); queenMock .SetupGet(p => p.HasMoved) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(pawn1Position)) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(pawn2Position)) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(availableFinishPosition)) .Returns(false); boardMock .Setup(b => b.IsEnemyOnPosition(It.IsAny <Position>(), ChessColor.Black)) .Returns(false); var movement = new VerticalMovement(boardMock.Object); var availableMoves = movement.GetAvailableMoves(queenMock.Object); Assert.AreEqual(1, availableMoves.Count()); Assert.IsTrue(availableMoves.All(m => m.StartingPosition == queenPosition)); var finishedPositions = availableMoves .Select(m => m.FinishedPosition) .ToList(); Assert.Contains(availableFinishPosition, finishedPositions); }
public void QueenCanCaptureEnemiesButCantJumpThroughThem() { //BQ - black queen //PM - possible move //EP - enemy piece //7 PM //6 PM //5 BQ //4 PM //3 EP //2 //1 //0 // 0 1 2 3 4 5 6 7 var boardMock = new Mock <IChessBoard>(MockBehavior.Strict); var queenMock = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict); var queenPosition = new Position(6, 5); var enemyPosition = new Position(6, 3); var availableFinishPosition1 = new Position(6, 4); var availableFinishPosition2 = new Position(6, 6); var availableFinishPosition3 = new Position(6, 7); var availableFinishPositions = new List <Position>() { availableFinishPosition1, availableFinishPosition2, availableFinishPosition3 }; queenMock .SetupGet(p => p.Color) .Returns(ChessColor.Black); queenMock .SetupGet(p => p.PieceType) .Returns(ChessPieceType.Queen); queenMock .SetupGet(p => p.Position) .Returns(queenPosition); queenMock .SetupGet(p => p.HasMoved) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(enemyPosition)) .Returns(true); boardMock .Setup(b => b.IsPositionTaken(It.IsIn <Position>(availableFinishPositions))) .Returns(false); boardMock .Setup(b => b.IsEnemyOnPosition(enemyPosition, ChessColor.White)) .Returns(true); boardMock .Setup(b => b.IsEnemyOnPosition(It.IsIn <Position>(availableFinishPositions), ChessColor.White)) .Returns(false); var movement = new VerticalMovement(boardMock.Object); var availableMoves = movement.GetAvailableMoves(queenMock.Object); Assert.AreEqual(4, availableMoves.Count()); Assert.IsTrue(availableMoves.All(m => m.StartingPosition == queenPosition)); var finishedPositions = availableMoves .Select(m => m.FinishedPosition) .ToList(); Assert.Contains(availableFinishPosition1, finishedPositions); Assert.Contains(availableFinishPosition2, finishedPositions); Assert.Contains(availableFinishPosition3, finishedPositions); Assert.Contains(enemyPosition, finishedPositions); }
public List<ItemMovementDetails> MoveVertical(VerticalMovement verticalMovement) { ResetWasJustDuplicatedValues(); var movementDetails = new List<ItemMovementDetails>(); int relativeRow = verticalMovement == VerticalMovement.Bottom ? -1 : 1; var rowNumbers = Enumerable.Range(0, Globals.Rows); if (verticalMovement == VerticalMovement.Top) { rowNumbers = rowNumbers.Reverse(); } for (int column = 0; column < Globals.Columns; column++) { foreach (int row in rowNumbers) { //if the item is null, continue checking for non-null items if (matrix[row, column] == null) continue; //we have a non-null item //first we check if this item has the same value as the next one ItemMovementDetails imd = AreTheseTwoItemsSame(row, column, row + relativeRow, column); if (imd != null) { movementDetails.Add(imd); continue; } //matrix[row,column] is the first not null item //move it to the first null item int rowFirstNullItem = -1; int numberOfItemsToTake = verticalMovement == VerticalMovement.Bottom ? row : Globals.Rows - row; bool emptyItemFound = false; foreach (var tempRowFirstNullItem in rowNumbers.Take(numberOfItemsToTake)) { rowFirstNullItem = tempRowFirstNullItem; if (matrix[rowFirstNullItem, column] == null) { emptyItemFound = true; break; } } if (!emptyItemFound) { continue; } ItemMovementDetails newImd = MoveItemToNullPositionAndCheckIfSameWithNextOne(row, rowFirstNullItem, rowFirstNullItem + relativeRow, column, column, column); movementDetails.Add(newImd); } } return movementDetails; }
public Movement(HorizontalMovement horizontal, VerticalMovement vertical) { Horizontal = horizontal; Vertical = vertical; }