Esempio n. 1
0
    List <PathfindingBall> getPathToStairs(PathfindingBall currentLocation)
    {
        string nextRoomID = "";

        if (currentLocation.StairwayDir == "Left")
        {
            nextRoomID = currentLocation.RoomLeft;
        }
        else
        {
            nextRoomID = currentLocation.RoomRight;
        }

        Room nextRoom = GameController.getRoomFromID(nextRoomID);

        if (nextRoom.stairs)
        {
            //We found the stairs, yay!
            List <PathfindingBall> result = new List <PathfindingBall>();
            result.Add(currentLocation);
            return(result);
        }

        //We still have somt trecking to do to find the stairs!
        List <PathfindingBall> nextRoomPFBalls = GameController.getPathfindingBallsForRoom(nextRoom);

        foreach (PathfindingBall pfb in nextRoomPFBalls)
        {
            if (pfb != currentLocation)
            {
                List <PathfindingBall> result = getPathToStairs(pfb);
                result.Add(currentLocation);
                return(result);
            }
        }

        Debug.Log("Error in pathfinding - getPathToStairs()");
        return(new List <PathfindingBall>());
    }
Esempio n. 2
0
    List <PathfindingBall> getPathOnSameFloor(PathfindingBall current, Room target, string direction)
    {
        if (direction == "Right")
        {
            if (current.RoomRight == target.roomID)
            {
                List <PathfindingBall> result = new List <PathfindingBall> ();
                result.Add(current);
                return(result);
            }
            if (current.RoomRight == "")
            {
                return(null);
            }
        }
        if (direction == "Left")
        {
            if (current.RoomLeft == target.roomID)
            {
                List <PathfindingBall> result = new List <PathfindingBall> ();
                result.Add(current);
                return(result);
            }
            if (current.RoomLeft == "")
            {
                return(null);
            }
        }

        if (direction == "Right")
        {
            string nextRoomID = current.RoomRight;
            Room   nextRoom   = GameController.getRoomFromID(nextRoomID);
            List <PathfindingBall> nextRoomPFBalls = GameController.getPathfindingBallsForRoom(nextRoom);
            foreach (PathfindingBall pfbs in nextRoomPFBalls)
            {
                if (nextRoomID == pfbs.RoomLeft)
                {
                    //Moving right
                    List <PathfindingBall> result = getPathOnSameFloor(pfbs, target, direction);
                    if (result != null)
                    {
                        result.Add(current);
                    }
                    return(result);
                }
            }
            //Debug.Log("Something's gone wrong in getPathOnSameFloor() - right");
            return(null);
        }

        if (direction == "Left")
        {
            string nextRoomID = current.RoomLeft;
            Room   nextRoom   = GameController.getRoomFromID(nextRoomID);
            List <PathfindingBall> nextRoomPFBalls = GameController.getPathfindingBallsForRoom(nextRoom);
            foreach (PathfindingBall pfbs in nextRoomPFBalls)
            {
                if (nextRoomID == pfbs.RoomRight)
                {
                    //Moving left
                    List <PathfindingBall> result = getPathOnSameFloor(pfbs, target, direction);
                    if (result != null)
                    {
                        result.Add(current);
                    }
                    return(result);
                }
            }
            //Debug.Log("Something's gone wrong in getPathOnSameFloor() - left");
            return(null);
        }

        return(null);
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        statSleep     -= 0.5f * Time.deltaTime;
        statCuriosity -= 0.5f * Time.deltaTime;
        statFun       -= 0.5f * Time.deltaTime;
        statHealth    -= 0.5f * Time.deltaTime;
        statWaste     -= 0.5f * Time.deltaTime;
        statHunger    -= 0.5f * Time.deltaTime;

        statSleep     = Mathf.Clamp(statSleep, 0f, 100f);
        statCuriosity = Mathf.Clamp(statCuriosity, 0f, 100f);
        statFun       = Mathf.Clamp(statFun, 0f, 100f);
        statHealth    = Mathf.Clamp(statHealth, 0f, 100f);
        statWaste     = Mathf.Clamp(statWaste, 0f, 100f);
        statHunger    = Mathf.Clamp(statHunger, 0f, 100f);

        if (usingStairs)
        {
            usingObject = null;
            //Debug.Log("STAIRSTAIRSTAIR: "+stairMovingFromFloor+" -> "+stairMovingToFloor+" at stage "+nextStairState);
            PathfindingBallStairs nextBall;
            if (stairMovingFromFloor > stairMovingToFloor)
            {
                //going down
                nextBall = GameController.getStairFromFloorsAndStage(stairMovingToFloor, stairMovingFromFloor, nextStairState);
            }
            else
            {
                //going up
                nextBall = GameController.getStairFromFloorsAndStage(stairMovingFromFloor, stairMovingToFloor, nextStairState);
            }
            this.transform.position = Vector3.MoveTowards(this.transform.position, nextBall.transform.position, movementSpeed);
            this.transform.LookAt(nextBall.transform);
            Vector3 v = this.transform.localRotation.eulerAngles;
            v.x = 0;
            this.transform.localRotation = Quaternion.Euler(v);

            if (Vector3.Distance(this.transform.position, nextBall.transform.position) < movementSpeed)
            {
                if (stairMovingFromFloor > stairMovingToFloor)
                {
                    //going down
                    nextStairState--;
                }
                else
                {
                    //going up
                    nextStairState++;
                }
                if (nextStairState == 0)
                {
                    currentFloor--;
                    usingStairs = false;
                }
                else if (nextStairState == 5)
                {
                    currentFloor++;
                    usingStairs = false;
                }
            }
            return;
        }

        if (path.Count > 0)
        {
            PathfindingBall pfb = path[0];
            if (Vector3.Distance(this.transform.position, pfb.transform.position) < movementSpeed)
            {
                if (pfb.RoomLeft != this.currentRoom)
                {
                    this.currentRoom = pfb.RoomLeft;
                }
                if (pfb.RoomRight != this.currentRoom)
                {
                    this.currentRoom = pfb.RoomRight;
                }
                path.RemoveAt(0);
                if (path.Count == 0)
                {
                    return;
                }
            }

            pfb         = path[0];
            usingObject = null;
            if (pfb.Floor == this.currentFloor)
            {
                //Move normally
                this.transform.position = Vector3.MoveTowards(this.transform.position, pfb.transform.position, movementSpeed);

                this.transform.LookAt(pfb.transform);
                Vector3 v = this.transform.localRotation.eulerAngles;
                v.x = 0;
                this.transform.localRotation = Quaternion.Euler(v);
            }
            else
            {
                //Stairs
                usingStairs          = true;
                stairMovingFromFloor = this.currentFloor;
                if (pfb.Floor > this.currentFloor)
                {
                    //Moving up
                    stairMovingToFloor = this.currentFloor + 1;
                    nextStairState     = 1;
                }
                else
                {
                    //Moving down
                    stairMovingToFloor = this.currentFloor - 1;
                    nextStairState     = 4;
                }
            }
        }
        else if (targetObjectPFBall != null)
        {
            this.transform.position = Vector3.MoveTowards(this.transform.position, targetObjectPFBall.transform.position, movementSpeed);

            this.transform.LookAt(targetObjectPFBall.transform);
            Vector3 v = this.transform.localRotation.eulerAngles;
            v.x = 0;
            this.transform.localRotation = Quaternion.Euler(v);

            if (Vector3.Distance(this.transform.position, targetObjectPFBall.transform.position) < movementSpeed)
            {
                targetObjectPFBall = null;
                this.transform.LookAt(targetObject.transform);
                v   = this.transform.localRotation.eulerAngles;
                v.x = 0;
                this.transform.localRotation = Quaternion.Euler(v);
                targetObject.Interact(this);
                targetObject = null;
                Debug.Log("ARRIVED YAY");
            }
        }
    }