void HandleMovementDown(int stepNumber)
        {
            if (!m_state.door.IsClosed)
            {
                m_state.door.IsClosed = true;
                return;
            }

            int nextHeight = m_state.height - m_elevator.distancePerStep;
            int minHeight  = building.minFloor * building.heightPerFloor;

            if (m_action.terminalHeight < minHeight)
            {
                m_action.terminalHeight = minHeight;
            }

            if (nextHeight <= m_action.terminalHeight)
            {
                m_action = new ElevatorAction(ElevatorAction.Opening,
                                              m_action.terminalHeight);

                m_state.height   = m_action.terminalHeight;
                m_state.movement = ElevatorMovement.Stopped();
                return;
            }

            int nextFloor = 0;

            if (WillElevatorPassFloor(m_state.height,
                                      m_state.movement,
                                      m_elevator.distancePerStep,
                                      building.heightPerFloor,
                                      nextFloor))
            {
                foreach (ElevatorRequest request in m_openRequests)
                {
                    if ((request.floorNumber == nextFloor) &&
                        (request.requestedInsideElevator ||
                         request.direction))
                    {
                        nextHeight = nextFloor * building.heightPerFloor;
                        m_action   = new ElevatorAction(
                            ElevatorAction.Opening,
                            nextHeight);

                        m_state.height   = nextHeight;
                        m_state.movement = ElevatorMovement.Stopped();

                        return;
                    }
                }
            }

            m_state.height = nextHeight;
        }
        WillElevatorPassFloor(int currentHeight,
                              ElevatorMovement direction,
                              int stepLength,
                              int heightPerFloor,
                              int nextFloorNum)
        {
            int nextHeight = (direction.isAscending) ?
                             currentHeight + stepLength :
                             currentHeight - stepLength;

            if (direction.isAscending)
            {
                if ((currentHeight < 0) && (nextHeight >= 0))
                {
                    nextFloorNum = 0;
                    return(true);
                }

                if ((currentHeight / heightPerFloor) < (nextHeight / heightPerFloor))
                {
                    nextFloorNum = nextHeight / heightPerFloor;
                    return(true);
                }

                return(false);
            }

            if (direction.isDescending)
            {
                if ((nextHeight <= 0) && (currentHeight > 0))
                {
                    nextFloorNum = 0;
                    return(true);
                }

                if ((nextHeight / heightPerFloor) < (currentHeight / heightPerFloor))
                {
                    nextFloorNum = nextHeight / heightPerFloor;
                    return(true);
                }

                return(false);
            }

            return(false);
        }
        public ElevatorDriver(ElevatorConfiguration _elevator,
                              BuildingConfiguration _building)
        {
            m_elevator = _elevator;
            building   = _building;

            m_state = new ElevatorState(
                0,
                DoorState.Open(),
                ElevatorMovement.Stopped(),
                ElevatorMovement.Stopped());

            m_action = new ElevatorAction(ElevatorAction.Opening, 0);

            m_stepAction = new StepAction("ElevatorDriver Action",
                                          (stepNumber) =>
                                          proceedToNextState(stepNumber));
        }
Example #4
0
    // Use this for initialization
    void Start()
    {
        floormanager = GameObject.FindGameObjectWithTag("HotelManager").GetComponent <FloorManager>();
        em           = GameObject.FindGameObjectWithTag("ElevatorManager").GetComponent <ElevatorMovement>();

        hj  = GetComponent <HingeJoint>();
        js  = GetComponent <HingeJoint>().spring;
        max = hj.limits.max;
        min = hj.limits.min;
        // leverRotation = GetComponent<HingeJoint>().angle;

        // starting lever rotation
        leverRotation = floors[(int)em.GetComponent <ElevatorMovement>().floorPos];

        leverVRTK = GetComponent <VRTK_InteractableObject>();

        section = (Mathf.Abs(max - min) / floorNum);
        setFloors();
    }
Example #5
0
 // Use this for initialization
 void Start()
 {
     elevatorManager = GameObject.FindGameObjectWithTag("ElevatorManager").GetComponent <ElevatorMovement>();
 }
    // Update is called once per frame
    void Update()
    {
        //Make it so the player can't move too fast or too slow
        if (currentMoveSpeed < minMoveSpeed)
        {
            currentMoveSpeed = minMoveSpeed;
        }
        if (currentMoveSpeed > maxMoveSpeed)
        {
            currentMoveSpeed = maxMoveSpeed;
        }

        if (moving)
        {
            //Moves Player Character
            transform.position = new Vector3(transform.position.x + (currentMoveSpeed * direction * Time.deltaTime), transform.position.y, 0);

            //Only Increases Player Speed If Gameobject is moving
            currentMoveSpeed *= (acceleration);
        }

        if (!dodging)
        {
            //Swiping Right
            if (Input.GetKeyDown(KeyCode.D) || swipeRight)
            {
                if (moving && direction != 1)
                {
                    currentMoveSpeed /= 2;
                }
                direction = 1;

                if (canMove)
                {
                    moving = true;
                    LevelManager.timerStart = true;
                }
            }
            //Swiping Left
            if (Input.GetKeyDown(KeyCode.A) || swipeLeft)
            {
                if (moving && direction != -1)
                {
                    currentMoveSpeed /= 2;
                }
                direction = -1;

                if (canMove)
                {
                    moving = true;
                    LevelManager.timerStart = true;
                }
            }
        }

        if (elevatorTrigger)
        {
            ElevatorMovement elevatorController = elevator.gameObject.GetComponent <ElevatorMovement>();

            if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || swipeUp)
            {
                elevatorController.ActivateElevator(1);

                if (Time.timeScale != 1)
                {
                    Time.timeScale = 1;

                    foreach (GameObject tut in tutorials)
                    {
                        tut.SetActive(false);
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow) || swipeDown)
            {
                elevatorController.ActivateElevator(-1);
            }
        }

        //Swiping Up
        if ((Input.GetKeyDown(KeyCode.W) || swipeUp) && !dodging && moving)
        {
            StartCoroutine(PlayerDodging());
        }

        //Updates The AnimatorController's Paramaters To Match The Class's Variables
        playerAnimator.SetBool("Moving", moving);
        playerAnimator.SetInteger("Direction", direction);
        playerAnimator.SetBool("Jumping", dodging);
    }
 bool compatibleDirection(ElevatorMovement elevatorMovement)
 {
     return(elevatorMovement.isStopped ||
            requestedInsideElevator ||
            (elevatorMovement.isAscending == direction));
 }
Example #8
0
    /// <summary>
    /// Creates an instantites the tiles.
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary <TileSetType, TileLevel> availiableTile)
    {
        List <Vector2> leftEnds  = new List <Vector2>();
        List <Vector2> rightEnds = new List <Vector2>();

        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx];

                if (type == TileType.LeftEnd)
                {
                    leftEnds.Add(new Vector2(xdx, ydx));
                }
                else if (type == TileType.RightEnd)
                {
                    rightEnds.Add(new Vector2(xdx, ydx));
                }
            }
        }

        DualStore <Vector2, Vector2> veritcal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int xdx = (int)vec.x + 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (Vector2 vec in leftEnds)
        {
            int xdx = (int)vec.x - 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in veritcal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.updown;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

        DualStore <Vector2, Vector2> horizontal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int ydx = (int)vec.y;

            for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx));
                    xdx = map.GetLength(0);
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in horizontal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.leftright;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }
    }
        // The
        void proceedToNextState(int stepNumber)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("Elevator: "
                                                   + m_elevator.name

                                                   + " At height: "
                                                   + m_state.height.ToString()
                                                   + " action: "
                                                   + m_action.actionName);

                if (m_action.actionName == ElevatorAction.Opening)
                {
                    m_state.door = DoorState.Open();
                    int floorNumber = m_state.height / building.heightPerFloor;

                    m_goals.RemoveAll((request) =>
                                      request.floorNumber == floorNumber);

                    m_action.duration -= 1;
                    if (m_action.duration <= 0)
                    {
                        m_action = new ElevatorAction(ElevatorAction.Stopped, 2);
                    }
                    return;
                }
                if (m_action.actionName == ElevatorAction.Stopping)
                {
                    ElevatorState nextState = m_state;
                    nextState.movement = ElevatorMovement.Stopped();
                    nextState.height   = m_action.terminalHeight;
                    m_state            = nextState;
                    m_action           = new ElevatorAction(ElevatorAction.Opening,
                                                            m_state.height);
                    return;
                }

                if (m_action.actionName == ElevatorAction.Move_Up)
                {
                    HandleMovementUp(stepNumber);
                    return;
                }

                if (m_action.actionName == ElevatorAction.Move_Down)
                {
                    HandleMovementUp(stepNumber);
                    return;
                }

                //Fallback: Act as if the elevator is stopped.
                ElevatorRequest toExecute = getNextGoal();
                if (toExecute != null)
                {
                    int targetHeight = toExecute.floorNumber * building.heightPerFloor;
                    if (targetHeight == m_state.height)
                    {
                        m_action = new ElevatorAction(ElevatorAction.Opening, targetHeight);
                    }
                    else if (targetHeight > m_state.height)
                    {
                        m_action = new ElevatorAction(ElevatorAction.Move_Up,
                                                      targetHeight);
                    }
                    else
                    {
                        m_action = new ElevatorAction(ElevatorAction.Move_Down,
                                                      targetHeight);
                    }
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.ToString());
            }
        }