public Vector2 NodePosition(MatrixNode2D node) { var pieceOrigin = node.piece.origin; var pieceSize = node.piece.Size; var topLeftCellPosition = CellPositionAt(pieceOrigin); var bottomRightCellPosition = CellPositionAt(pieceOrigin + new Vector2Int(pieceSize.x - 1, pieceSize.y - 1)); var x = topLeftCellPosition.x + (bottomRightCellPosition.x - topLeftCellPosition.x) / 2.0f; var y = topLeftCellPosition.y + Mathf.Abs((bottomRightCellPosition.y - topLeftCellPosition.y) / 2.0f) * Vector2.down.y; return(new Vector2(x, y)); }
public void Start() { node = GetComponent <MatrixNode2D>(); if (null == node) { Debug.Log("Error. Matrix Control Scheme requires a MatrixNode2D"); return; } boardRunner = GetComponentInParent <MatrixBoardRunner2D>(); if (null == boardRunner) { Debug.Log("Error. Matrix Control Scheme requires a Board Runner"); return; } }
public MoveResult MovePiece(MatrixPiece piece, MapDirection direction, float duration) { if (null == piece) { return(MoveResult.Fail); } if (null == piece.owner || !piece.owner.TryGetTarget(out object pieceOwner)) { Debug.Log("Error. Piece owner is missing"); return(MoveResult.Fail); } MatrixNode2D node = pieceOwner as MatrixNode2D; if (null == node) { Debug.Log("Error. Need MatrixNode2D for Matrix board"); return(MoveResult.Fail); } if (node.IsAnimating) { return(MoveResult.Animating); } var oldOrigin = piece.origin; var newOrigin = oldOrigin + direction.Offset(); if (newOrigin == oldOrigin) { return(MoveResult.Fail); } var excludeList = new HashSet <MatrixPiece>(); excludeList.Add(piece); if (board.IsPieceBlockedAt(newOrigin, piece, excludeList)) { return(MoveResult.Blocked); } board.RemovePiece(piece); board.PutPiece(piece, newOrigin); var endPosition = NodePosition(node); if (duration > 0) { node.moveAnimationCurve = new Optional <AnimationCurve <Vector2> >(new AnimationCurve <Vector2>()); node.moveAnimationCurve.value.start = node.transform.localPosition; node.moveAnimationCurve.value.end = endPosition; node.moveAnimationTimer.duration = duration; node.moveAnimationTimer.Reset(); } else { node.transform.localPosition = endPosition; } return(MoveResult.Success); }
protected virtual void OnMoveResult(MatrixNode2D node, MapDirection direction, MatrixBoardRunner2D.MoveResult moveResult) { }