override public PrefromResult Perform (float delta) { var player = PlayerModel.Instance (); IntPointVO pos = player.cellPosition; int directionIdx = player.directionIdx; NodeVO node = MazeModel.Instance ().GetNode (pos.x, pos.y); GameModel game = GameModel.Instance (); game.AddScore ((int)((float)node.score * game.timeBonus)); node.score = 0; game.movesLeft.Dec (1); if (game.state == GameModel.STATE_INITED || game.state == GameModel.STATE_STUCK) { game.state = GameModel.STATE_MOVING; game.score.Freeze(); game.timeBonus.Freeze(); } if (node.HasFlag (NodeVO.SPECIALS_EXIT)) { game.state = GameModel.STATE_ENDED; MazePaceNotifications.EXIT_REACHED.Dispatch (); } else { if (node.HasFlag (NodeVO.SPECIALS_HIDE_WALLS)) { MazePaceNotifications.TOGGLE_WALLS_VISIBILITY.Dispatch (false); } if (node.HasFlag (NodeVO.SPECIALS_SHOW_WALLS)) { MazePaceNotifications.TOGGLE_WALLS_VISIBILITY.Dispatch (true); } bool shouldRotate = node.HasWall (directionIdx) || player.moved; if (node.HasFlag (NodeVO.SPECIALS_ROTATOR_CW | NodeVO.SPECIALS_ROTATOR_CCW) && shouldRotate) { MazePaceNotifications.ROTATE_AT_NODE.Dispatch (node); player.moved = false; } else if (!node.HasWall (directionIdx)) { player.cellPosition.x += NodeVO.DIRECTIONS [player.directionIdx, 0]; player.cellPosition.y += NodeVO.DIRECTIONS [player.directionIdx, 1]; player.moved = true; MazePaceNotifications.PROCEED_FROM_NODE.Dispatch (node); } else { game.state = GameModel.STATE_STUCK; game.score.SetValue (game.score, 0, DifficultyModel.Instance ().scoreDrainTime); MazePaceNotifications.PLAYER_STUCK.Dispatch (); } } MazePaceNotifications.GAME_UPDATED.Dispatch (); return PrefromResult.COMPLETED; }
void UpdateCorrectDirection() { IntPointVO cell = PlayerModel.Instance().cellPosition; var currentNode = MazeModel.Instance().GetNode(cell.x, cell.y); int newDirection = currentNode.directionToExit; if (currentNode.HasFlag(NodeVO.SPECIALS_ROTATOR_CW)) { newDirection--; if (newDirection < 0) { newDirection = 3; } } if (currentNode.HasFlag(NodeVO.SPECIALS_ROTATOR_CCW)) { newDirection++; if (newDirection > 3) { newDirection = 0; } } if (_correctDirection == newDirection) { return; } _correctDirection = newDirection; UpdateVisibility(); DOTween.Kill(_handTransform); Vector2 start = new Vector2(0, -Camera.main.orthographicSize * 0.5f); Vector2 stop = new Vector2(0, -Camera.main.orthographicSize * 0.5f); switch (_correctDirection) { case (NodeVO.DIRECTION_UP_IDX): start.y -= 25.0f; stop.y += 25.0f; break; case (NodeVO.DIRECTION_RIGHT_IDX): start.x -= 25.0f; stop.x += 25.0f; break; case (NodeVO.DIRECTION_DOWN_IDX): start.y += 25.0f; stop.y -= 25.0f; break; case (NodeVO.DIRECTION_LEFT_IDX): start.x += 25.0f; stop.x -= 25.0f; break; } _handTransform.position = start; _handTransform.DOMove(stop, 0.5f).SetLoops(-1).SetEase(Ease.InOutCubic); }
private PlayerModel() { cellPosition = new IntPointVO(0, 0); _directionIdx = NodeVO.DIRECTION_UP_IDX; }