Esempio n. 1
0
        public GameManager() : base("GameManager")
        {
            SetupState   setupState = new SetupState(this);
            MenuState    menuState  = new MenuState(this);
            SinglePlayer singleMode = new SinglePlayer(this);
            PauseState   pauseState = new PauseState(this);
            LoseState    loseState  = new LoseState(this);
            WinState     winState   = new WinState(this);
            MultiPlayer  multiMode  = new MultiPlayer(this);
            LobbySetup   lobby      = new LobbySetup(this);

            //Link State
            setupState.MenuState = menuState;

            menuState.SinglePlayerMode = singleMode;
            menuState.Lobby            = lobby;

            singleMode.NextWin   = winState;
            singleMode.NextLose  = loseState;
            singleMode.NextPause = pauseState;

            lobby.Menu      = menuState;
            lobby.MultiMode = multiMode;

            multiMode.NextLose  = loseState;
            multiMode.NextPause = pauseState;
            multiMode.NextWin   = winState;

            loseState.Retry = menuState;

            setupState.OnStateEnter();
            currentState = setupState;

            AddComponent(new FSMUpdater(currentState));
        }
Esempio n. 2
0
        private void Reset()
        {
            ResetRocket();
            ResetLivingLetter();

            loseState = LoseState.None;

            myCollider.enabled = true;

            GetComponent <CapsuleCollider>().enabled = true;
        }
    // Start is called before the first frame update
    protected override void Start()
    {
        // Find Lose State script
        loseState = GameObject.FindWithTag("GameManager").GetComponent <LoseState>();
        if (loseState == null)
        {
            throw new System.ArgumentException("Couldn't find reference to the lose state script");
        }

        base.Start();
        healthbar.SetMaxHealth(health);
        animalList.Add(gameObject);
    }
Esempio n. 4
0
    void Update()
    {
        if (people.value <= 0)
        {
            LoseState lose = new LoseState();
            lose.GameAction();
            GameManager gameManager = GameManager.getInstance();
            gameManager.getState().ChangeScene();

            Endscreen.ds = "people";
        }
        else if (defense.value <= 0)
        {
            LoseState lose = new LoseState();
            lose.GameAction();
            GameManager gameManager = GameManager.getInstance();
            gameManager.getState().ChangeScene();

            Endscreen.ds = "defense";
        }
        else if (faith.value <= 0)
        {
            LoseState lose = new LoseState();
            lose.GameAction();
            GameManager gameManager = GameManager.getInstance();
            gameManager.getState().ChangeScene();

            Endscreen.ds = "faith";
        }
        else if (food.value <= 0)
        {
            LoseState lose = new LoseState();
            lose.GameAction();
            GameManager gameManager = GameManager.getInstance();
            gameManager.getState().ChangeScene();

            Endscreen.ds = "food";
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (staticNoise == null)
        {
            staticNoise = gameObject.GetComponent <AudioSource>();
        }
        //Todays date but 100 years in the future is put in timetext
        DateTime tempDateTime = System.DateTime.Now.AddYears(100);

        timeText.text = tempDateTime.ToString();

        //Pause toggle
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            if (isGamePaused == false)
            {
                pauseMenu.SetActive(true);
                isGamePaused = true;
            }
            else if (isGamePaused == true)
            {
                optionsMenu.SetActive(false);
                pauseMenu.SetActive(false);
                isGamePaused = false;
            }
        }
        //get rid of fade (Not in currently)
        if (currentGameState == GameState.levelPlaying)
        {
            if (fade.GetComponent <Image>().color.a > 0.0f)
            {
                alpha -= Time.deltaTime / 2;
                fade.GetComponent <Image>().color = new Color(0, 0, 0, alpha);
            }
        }

        if (currentGameState == GameState.levelWin)   //When the player wins
        {
            //set all player doubles to disable
            if (TurretTurner.playerList != null)
            {
                if (TurretTurner.playerList.Count > 0)
                {
                    foreach (GameObject player in TurretTurner.playerList)
                    {
                        if (player != null)
                        {
                            if (player.GetComponent <playerDouble>() != null)
                            {
                                player.GetComponent <playerDouble>().Disable();
                            }
                        }
                    }
                }
            }


            //open the door
            door.GetComponent <doorControl>().doorOpen = true;
            timer -= Time.deltaTime;
            if (timer < 0)  //timer to load the next scene
            {
                currentGameState = GameState.levelEnd;
            }
        }

        if (currentGameState == GameState.levelEnd)          // if the level ending
        {
            if (fade.GetComponent <Image>().color.a < 0.99f) //fade to black
            {
                if (fade.activeSelf == false)
                {
                    fade.SetActive(true);
                    fade.GetComponent <Image>().color = new Color(0, 0, 0, 0);
                }
                Debug.Log("darkening fade");
                alpha += Time.deltaTime / 2;
                fade.GetComponent <Image>().color = new Color(0, 0, 0, alpha);
            }
            else
            {
                //show the noise and cycle through different sprites of it
                if (noiseObject.activeSelf == false)
                {
                    staticNoise.clip   = staticSound;
                    staticNoise.volume = 0.015f;
                    staticNoise.Play();
                    noiseObject.SetActive(true);
                }

                if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise1)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise2;
                }
                else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise2)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise3;
                }
                else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise3)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise4;
                }
                else
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise1;
                }

                noiseBar.GetComponent <RectTransform>().Translate(0, -barMoveSpeed * Time.deltaTime, 0);

                noiseTimer -= Time.deltaTime;
                if (noiseTimer < 0)    //after 1 sec load next levels, increment how many levels completed on keeper or go back to main menu if theres no more levels
                {
                    if (winText != null)
                    {
                        winText.text = "End of demo \nThanks For Playing! \nPlease Rate! < 3";
                    }

                    if (completionKeeper.howManyLevelsCompleted <= SceneManager.GetActiveScene().buildIndex - 1)
                    {
                        completionKeeper.howManyLevelsCompleted += 1;

                        PlayerPrefs.SetInt("levelsCompleted", completionKeeper.howManyLevelsCompleted);
                    }
                    else if (SceneManager.GetActiveScene().buildIndex == 1 && completionKeeper.howManyLevelsCompleted == 0)
                    {
                        // completionKeeper.howManyLevelsCompleted++;
                        // PlayerPrefs.SetInt("levelsCompleted", completionKeeper.howManyLevelsCompleted);
                    }
                    //Debug.Log(SceneManager.GetActiveScene().buildIndex);
                    if (SceneManager.GetActiveScene().buildIndex == 21)
                    {
                        SceneManager.LoadScene("MenuScene");
                    }
                    else
                    if (SceneManager.sceneCountInBuildSettings != SceneManager.GetActiveScene().buildIndex + 1)
                    {
                        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
                    }
                    else
                    {
                        SceneManager.LoadScene("MenuScene");
                    }
                }
            }
        }

        if (currentGameState == GameState.levelLose)    //if the player dies
        {
            if (currentLoseState == LoseState.grabPass) //distort using the grab pass object
            {
                if (grabPassObject.activeSelf == false)
                {
                    grabPassObject.SetActive(true);
                }
                else
                {
                    grabPassObject.SetActive(false);
                }
                grabPassIntensity += 3 * Time.deltaTime;
                grabPassObject.GetComponent <Renderer>().material.SetFloat("_Intensity", grabPassIntensity);
                if (grabPassIntensity >= 3)
                {
                    currentLoseState = LoseState.tvNoise;
                }
            }
            else if (currentLoseState == LoseState.tvNoise)      //show the tv static noise and cycle through sprite variations for it to animate
            {
                if (noiseObject.activeSelf == false)
                {
                    staticNoise.clip   = staticSound;
                    staticNoise.volume = 0.03f;
                    staticNoise.Play();
                    noiseObject.SetActive(true);
                }

                if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise1)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise2;
                }
                else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise2)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise3;
                }
                else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise3)
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise4;
                }
                else
                {
                    noiseObject.GetComponent <Image>().sprite = noiseSprites.noise1;
                }

                noiseBar.GetComponent <RectTransform>().Translate(0, -barMoveSpeed * Time.deltaTime, 0);

                noiseTimer -= Time.deltaTime;
                if (noiseTimer < 0)
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);    //reload scene
                }
            }


            /*
             * if (fade.GetComponent<Image>().color.a <0.99f)
             * {
             *  alpha += Time.deltaTime / 2;
             *  fade.GetComponent<Image>().color = new Color(0, 0, 0, alpha);
             * }
             * else
             * {
             *  SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
             * }*/
        }

        if (currentGameState == GameState.levelDialogue)
        {
            dialogueController.Trigger();
        }

        if (loadingToMainMenu == true)
        {
            if (noiseObject.activeSelf == false)
            {
                staticNoise.clip   = staticSound;
                staticNoise.volume = 0.015f;
                staticNoise.Play();
                noiseObject.SetActive(true);
            }

            if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise1)
            {
                noiseObject.GetComponent <Image>().sprite = noiseSprites.noise2;
            }
            else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise2)
            {
                noiseObject.GetComponent <Image>().sprite = noiseSprites.noise3;
            }
            else if (noiseObject.GetComponent <Image>().sprite == noiseSprites.noise3)
            {
                noiseObject.GetComponent <Image>().sprite = noiseSprites.noise4;
            }
            else
            {
                noiseObject.GetComponent <Image>().sprite = noiseSprites.noise1;
            }

            noiseBar.GetComponent <RectTransform>().Translate(0, -barMoveSpeed * Time.deltaTime, 0);

            noiseTimer -= Time.deltaTime;
            if (noiseTimer < 0)
            {
                SceneManager.LoadScene("MenuScene");
            }
        }

        if (currentGameState == GameState.levelDialogue)
        {
        }
    }
Esempio n. 6
0
        private void pathMoveComplete()
        {
            finishedRound = true;

            transform.parent.Find("MazeLetter").GetComponent <MazeLetter>().isDrawing = false;

            //arrived!
            //transform.rotation = initialRotation;
            if (currentFruitIndex == _fruits.Count)
            {
                print("Won");
                // if (particles) particles.SetActive(false);
                foreach (GameObject particle in particles)
                {
                    particle.SetActive(false);
                }
                GetComponent <Collider>().enabled = false;
                characterIsMoving = false;
                toggleVisibility(false);
                transform.DOKill(false);
                MazeGame.instance.moveToNext(true);

                if (currentFruitList == Fruits.Count - 1)
                {
                    if (dot != null)
                    {
                        dot.GetComponent <BoxCollider>().enabled = true;
                    }
                }
            }
            else
            {
                if (loseState != LoseState.OutOfBounds)
                {
                    for (int i = currentFruitIndex; i < _fruits.Count; i++)
                    {
                        _fruits[i].GetComponent <MazeArrow>().MarkAsUnreached(i == currentFruitIndex);
                    }

                    Vector3 direction     = _fruits[currentFruitIndex].transform.position - rocket.transform.position;
                    Vector3 rotatedVector = direction;
                    var     piOverTwo     = Mathf.PI / 2;
                    rotatedVector.x = direction.x * Mathf.Cos(piOverTwo) - direction.z * Mathf.Sin(piOverTwo);
                    rotatedVector.z = direction.x * Mathf.Sin(piOverTwo) + direction.z * Mathf.Cos(piOverTwo);
                    rotatedVector.y = 0f;
                    rotatedVector.Normalize();
                    rotatedVector  *= 1.5f;
                    rotatedVector.y = 2f;

                    Tutorial.TutorialUI.MarkNo((_fruits[currentFruitIndex].transform.position + rocket.transform.position) / 2 + rotatedVector, Tutorial.TutorialUI.MarkSize.Normal);

                    rocketMoveSFX.Stop();

                    MazeConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.KO);

                    if (!MazeGame.instance.isTutorialMode)
                    {
                        MazeConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.Lose);
                    }

                    loseState = LoseState.Incomplete;
                }
                else
                {
                    OnRocketImpactedWithBorder();
                }

                waitAndRestartScene();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load textures and fonts
            _font          = Content.Load <SpriteFont>("BlackChancery");
            _buttonTexture = Content.Load <Texture2D>("WoodButton");
            var squirrel1 = Content.Load <Texture2D>("squirrel1");
            var gateLevel = Content.Load <Texture2D>("gate_level");

            var upgradeBar = new Texture2D(GraphicsDevice, GraphicsDevice.PresentationParameters.Bounds.Width, 100);

            var colorData = new Color[100 * GraphicsDevice.PresentationParameters.Bounds.Width];

            for (int i = 0; i < 100 * GraphicsDevice.PresentationParameters.Bounds.Width; i++)
            {
                colorData[i] = Color.DarkSlateGray;
            }
            upgradeBar.SetData(colorData);

            var stone       = new Texture2D(GraphicsDevice, 10, 10);
            var stoneColors = new Color[100];

            for (int i = 0; i < 100; i++)
            {
                stoneColors[i] = Color.Black;
            }

            stone.SetData(stoneColors);

            // Create Objects
            var gate = new Gate();

            // Create factories
            var buttonFactory   = new ButtonFactory(_buttonTexture, _font, _postOffice);
            var textFactory     = new TextFactory(_font);
            var squirrelFactory = new SquirrelFactory(squirrel1, gate);


            // Create Managers
            var leaderboardManager    = new LeaderboardManager();
            var playerMetaDataManager = new PlayerMetaDataManager(_postOffice);

            var moneyManager = new MoneyManager(_postOffice);
            var statsManager = new StatsManager(_postOffice, moneyManager);

            // Register states to the state manager
            _stateManager.RegisterState(new MenuState(buttonFactory, textFactory));

            var nameInputState = new NameInputState(buttonFactory, textFactory, _postOffice,
                                                    GraphicsDevice.PresentationParameters.Bounds);

            _stateManager.RegisterState(nameInputState);
            _stateManager.RegisterState(new LeaderboardState(buttonFactory, textFactory, leaderboardManager));
            _stateManager.RegisterState(new ExitState(this));

            var playState = new PlayState(_postOffice, squirrelFactory, buttonFactory, textFactory, statsManager, moneyManager, gateLevel,
                                          GraphicsDevice.PresentationParameters.Bounds, upgradeBar, stone, gate);

            _stateManager.RegisterState(playState);

            var loseState = new LoseState(buttonFactory, textFactory, _postOffice, leaderboardManager);

            _stateManager.RegisterState(loseState);

            var flavourText = new FlavourTextState(buttonFactory, textFactory);

            _stateManager.RegisterState(flavourText);


            // Register clients to the post office
            _postOffice.RegisterClient((ILetterbox)_stateManager, "StateManager");
            _postOffice.RegisterClient((ILetterbox)playerMetaDataManager, playerMetaDataManager.LetterboxName);
            _postOffice.RegisterClient((ILetterbox)nameInputState, nameInputState.StateRegisterName);
            _postOffice.RegisterClient((ILetterbox)statsManager, statsManager.LetterboxName);
            _postOffice.RegisterClient((ILetterbox)playState, playState.LetterboxName);
            _postOffice.RegisterClient((ILetterbox)moneyManager, moneyManager.LetterboxName);
            _postOffice.RegisterClient((ILetterbox)gate, "Gate");
            _postOffice.RegisterClient((ILetterbox)loseState, loseState.StateRegisterName);

            // Set the initial state to the menu
            _postOffice.SendMail("Null",
                                 new PostOfficeEventArgs()
            {
                SendAddress = "StateManager",
                MessageName = "SetInitialState",
                Data        = Encoding.ASCII.GetBytes("Menu")
            });

            // TODO: use this.Content to load your game content here
        }