Esempio n. 1
0
    /// <summary>
    /// Called by confirmMenu when returning.
    /// If gets success value, will create save the slot at number, else will do nothing
    /// </summary>
    /// <param name="retVal"></param>
    /// <param name="retString"></param>
    public override void _RespondToConfirm(int retVal, string retString)
    {
        switch (retVal)
        {
        case 0:
            if (GameManager.settings.saveNum <= 3 && GameManager.settings.saveNum >= 1 && GameManager.saveGame != null)                         // save existing game if it exists
            {
                SaveObj.SaveGame(GameManager.settings.saveNum, GameManager.saveGame);
            }

            GameManager.saveGame         = new SaveObj(!retString.Equals("") ? retString : "Slot " + number);
            GameManager.settings.saveNum = number;
            SaveObj.SaveGame(number, GameManager.saveGame);
            SettingsObj.saveSettings(GameManager.settings);
            if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length)
            {
                LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber);
                GameManager.changeState(GameManager.gameplay, this);
            }
            else
            {
                onClick(levelSelector);
            }
            break;

        default:                        // canceled, do nothing
            break;
        }
    }
    public int index;           // changed this to use ints, so loading the levels from other scripts is easier
    // This is set when instatiating from prefab

    /*public void changeString(string s)
     * {
     * this.s = s;
     * }*/

    //This method is called on button pressed.
    public void doButtonThing()
    {
        //LevelSelector.changeLevel(s);
        //LevelSelector.changeLevel(index);
        if (index != GameManager.saveGame.levelNumber)                  // update and save the last level visited if it is different from the current last level visited.
        {
            GameManager.saveGame.levelNumber = index;
            SaveObj.SaveGame(GameManager.settings.saveNum, GameManager.saveGame);
        }
        LevelSelector.changeLevelHelper(index);                                // load level with given index number
        GameManager.changeState(GameManager.gameplay, LevelSelector.instance); // switch to game-mode
    }
Esempio n. 3
0
 /// <summary>
 /// load straight to last-visited-level if it is set to a valid number, else go to level selector
 /// </summary>
 public void resumeGame()
 {
     //Debug.Log("Resume Game does nothing right now");
     if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length)
     {
         LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber);
         GameManager.changeState(GameManager.gameplay, this);
     }
     else
     {
         onClick(levelSelector);
     }
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="num"></param>
 public void loadSlot(int num)
 {
     GameManager.saveGame = SaveObj.LoadGame(num);
     if (GameManager.saveGame == null)               // complain if save file doesn't exist/error
     // give file-doesn't exist notification here
     {
         Debug.Log("Error: Can't find save file \"" + num + "\"");
         return;
     }
     GameManager.settings.saveNum = num;                                                                                // set the last-save-used to this num, and save that change
     SettingsObj.saveSettings(GameManager.settings);
     if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length) // load straight to the last visited level if it exists
     {
         LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber);
         GameManager.changeState(GameManager.gameplay, this);
     }
     else
     {
         onClick(levelSelector);             // else, go to level selector
     }
 }
Esempio n. 5
0
    public override void _Update()
    {
        //Player interaction objects
        //if (InputManager.instance.OnInputDown(InputManager.Action.action)) {
        if (Input.GetButtonDown("Action"))
        {
            //if (currentPosition.hasSign/* && curdir == 0*/) {
            if (currentPosition.type == Node.TileType.sign /* && curdir == 0*/)
            {
                //Player reads a sign
                ///////// make sign visible/not visible
                signText.text = currentPosition.signMessage;
                signImage.gameObject.SetActive(!signImage.gameObject.activeInHierarchy);
                //Debug.Log(currentPosition.signMessage);
            }
            else
            {
                if (hasBall)
                {
                    //Player drops the ball
                    hasBall = false;
                    //} else if ((currentPosition.data.hasEnter && !currentPosition.data.hasLeave) || stringLeft == map.stringleft && currentPosition.type == Node.TileType.source) {
                }
                else if (
                    (currentPosition.hasEnter && !currentPosition.hasLeave) ||
                    stringLeft >= map.stringleft && currentPosition.type == Node.TileType.source)
                {
                    //Player pick up the ball
                    hasBall = true;
                }
            }
        }

        //Shows pause menu
        //if (InputManager.instance.OnInputDown(InputManager.Action.back)) {
        if (Input.GetButtonDown("Back"))
        {
            GameManager.changeState(pauseMenu, this);
        }

        //Dont do anything past here if we are doing an animation
        if (animLockout)
        {
            return;
        }
        else if (winTrigger)
        {
            youWinScreenTimeout -= Time.deltaTime;
            if (youWinScreenTimeout < 0.0f)
            {
                winTrigger = false;
                // load the next level if it exists, else return to level selector
                if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length)
                {
                    LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber);
                }
                else
                {
                    GameManager.changeState(levelSelector, this);
                }
            }
            return;
        }
        //This for loop deals with inputs and moves the player around.

        //for (int i = 0; i < 4; i++) {
        //Direction lines up with input manager so we can directly convert to an action from a direction.
        //GameManager.Direction dir = (GameManager.Direction)i;
        bool directionInput = false;

        GameManager.Direction dir = GameManager.Direction.North;
        float ver = Input.GetAxisRaw("Vertical");
        float hor = Input.GetAxisRaw("Horizontal");

        if (!Mathf.Approximately(ver, 0.0f) && ver > 0)                 // if multiple axis are active, choose only one, with priority N > E > S > W
        {
            directionInput = true;
        }
        else if (!Mathf.Approximately(hor, 0.0f) && hor > 0)
        {
            dir            = GameManager.Direction.East;
            directionInput = true;
        }
        else if (!Mathf.Approximately(ver, 0.0f) && ver < 0)
        {
            dir            = GameManager.Direction.South;
            directionInput = true;
        }
        else if (!Mathf.Approximately(hor, 0.0f) && hor < 0)
        {
            dir            = GameManager.Direction.West;
            directionInput = true;
        }

        //if (InputManager.instance.OnInput((InputManager.Action)i)) {
        if (directionInput)             // only go into if a direction input occured
        {
            bool canMove   = false;
            Node otherNode = null;
            if (signImage.gameObject.activeInHierarchy)
            {
                signImage.gameObject.SetActive(false);
            }
            //curdir = i;
            //curdir = (int)dir;
            if (hasBall && (currentPosition.hasLeave || (currentPosition.type != Node.TileType.source && !currentPosition.hasLeave && !currentPosition.hasEnter)))
            {
                hasBall = false;
            }
            if (currentPosition[(int)dir] >= 0)
            {
                otherNode = map[currentPosition[(int)dir]];
                //See if the other node has a leave
                canMove = (
                    (
                        (!otherNode.hasLeave && !otherNode.hasEnter && stringLeft > 0) || ( // can't carry string onto tiles if it already has string on it
                            otherNode.hasLeave && otherNode.leave.inverse() == dir &&       // unless you are rolling up the string
                            currentPosition.hasEnter && currentPosition.enter == dir) ||
                        !hasBall) &&                                                        // this stuff about string doesn't matter if you are not carrying string
                    !map.disjoint(currentPosition, dir) &&                                  // can't walk through one-ways if it would sever the string
                    (otherNode.type != Node.TileType.unwalkable || pitWalk)                 // can't walk over pits, unless leveleditor "walk over pits" setting is set
                    );
            }
            if (cinimaticMode && Input.GetKey(KeyCode.Space))
            {
                canMove = false;
            }
            animLockout = true;
            StartCoroutine(CharacterAnimator.instance.AnimateMovement(
                               (bool flag) => { onArrive(canMove, otherNode, dir); },
                               dir, moveAnimSpeed, canMove
                               ));

            //break;
        }
        //}
    }