예제 #1
0
    // Use this for initialization
    void Start()
    {
        theGameManager       = FindObjectOfType <GameManager>();
        thePlayerManager     = FindObjectOfType <PlayerManager>();
        theShopkeeperManager = FindObjectOfType <ShopkeeperManager>();

        Physics2D.IgnoreLayerCollision(9, 10, true);
    }
예제 #2
0
 void Start()
 {
     //Ignore collision between UI and spell
     Physics2D.IgnoreLayerCollision(5, 8);
     theButtonManager     = FindObjectOfType <ButtonManager>();
     theGamemanager       = FindObjectOfType <GameManager>();
     thePlayerManager     = FindObjectOfType <PlayerManager>();
     theShopkeeperManager = FindObjectOfType <ShopkeeperManager>();
 }
예제 #3
0
    void OnMouseDown()
    {
        //Debug.Log("Click");

        bmc.GetComponent <BombMixController>().FinalizeSpell();
        bomb = bmc.GetComponent <BombMixController>().SpawnSpell();
        if (bomb != null)
        {
            bmc.GetComponent <BombMixController>().PlayHoldClip();
            fireMode = true;
        }
        else
        {
            if (theGamemanager.shopKeepLevel)
            {
                //Debug.Log("should theshopkeepleave?");
                theShopkeeperManager = FindObjectOfType <ShopkeeperManager>();
                thePlayerManager.setCurrentState(PlayerManager.GameState.Wait);
                theGamemanager.setCurrentState(GameManager.GameState.Wait);
                theShopkeeperManager.setCurrentState(ShopkeeperManager.GameState.leave);
            }
            bmc.GetComponent <BombMixController>().ResetMix();
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        //Update health every frame no matter what
        healthDial.fillAmount = (currentHealth / maxHealth);
        GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, transparency);
        transform.GetChild(0).GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, transparency);


        //End the game if dead
        if (currentHealth <= 0f)
        {
            theEnemyManager.setCurrentState(EnemyManager.GameState.wait);
            theGameManager.resetTime();
            theGameManager.setCurrentState(GameManager.GameState.Wait);
            setCurrentState(GameState.Die);
        }

        //State machine
        switch (currentState)
        {
        case GameState.Wait:
            time = 0f;
            break;

        case GameState.EnterScene:
            time += Time.deltaTime / 2;

            transform.position   = new Vector2(Mathf.SmoothStep(offScreenStartingPos.x, FightingPos.x, time), Mathf.SmoothStep(offScreenStartingPos.y, FightingPos.y, time)); // Vector3.Lerp(offScreenStartingPos, FightingPos, time);
            transform.localScale = new Vector3(Mathf.SmoothStep(0.3f, 0.1f, time), Mathf.SmoothStep(0.3f, 0.1f, time), Mathf.SmoothStep(0.3f, 0.1f, time));                   //Vector3.Lerp(new Vector3(30, 30, 30), new Vector3(15, 15, 15), Time.time/2);
            if (getStateElapsed() > 2.0f)
            {
                if (theGameManager.shopKeepLevel)
                {
                    theShopkeeperManager = FindObjectOfType <ShopkeeperManager>();
                    theShopkeeperManager.setCurrentState(ShopkeeperManager.GameState.appear);
                }
                else
                {
                    theEnemyManager = FindObjectOfType <EnemyManager>();
                    theEnemyManager.setCurrentState(EnemyManager.GameState.appear);
                }
                setCurrentState(GameState.Wait);
                time = 0;
            }
            break;

        case GameState.Fight:
            time        += Time.deltaTime / 2;
            transparency = Mathf.SmoothStep(1.0f, 0.3f, time);

            break;

        case GameState.LeaveScene:
            time                += Time.deltaTime / 2;
            transparency         = Mathf.SmoothStep(0.3f, 1.0f, time);
            transform.position   = new Vector2(Mathf.SmoothStep(FightingPos.x, ExitPos.x, time), Mathf.SmoothStep(FightingPos.y, ExitPos.y, time));            //Vector3.Lerp(FightingPos, ExitPos, time);
            transform.localScale = new Vector3(Mathf.SmoothStep(0.1f, 0.05f, time), Mathf.SmoothStep(0.1f, 0.05f, time), Mathf.SmoothStep(0.1f, 0.05f, time)); //Vector3.Lerp(new Vector3(15, 15, 15), new Vector3(5, 5, 5), time);

            break;

        case GameState.Die:
            currentHealth = 1;
            theGameManager.setCurrentState(GameManager.GameState.GameOverSequence);
            setCurrentState(GameState.Wait);
            FindObjectOfType <ButtonManager>().SetAllButtons(false);
            healthDial.gameObject.SetActive(false);
            break;
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        RoomLevel.text = "Level: " + currentLevel;

        switch (currentState)
        {
        case GameState.Wait:
            time = 0f;
            break;

        case GameState.IntroSequence:
            //theEnemyManager.currentHealth = 100;
            //thePlayerManager.currentHealth = 5;
            thePlayerManager.setCurrentState(PlayerManager.GameState.EnterScene);
            //figure out whether the player encounters a shopkeeper or an enemy
            //update the (enemy or shopkeeper) and player variables
            //have the player move up
            // have the ennemy or shopkeeper
            //move on to the pause before start
            if (shopKeepLevel)
            {
                //WE NEED TO DISABLE THIS VALUE AT SOME POINT!!!!!
                theShopkeeperManager = FindObjectOfType <ShopkeeperManager>();
                //set the shopkeeper to wait
            }
            else
            {
                theEnemyManager = FindObjectOfType <EnemyManager>();
                theEnemyManager.setCurrentState(EnemyManager.GameState.wait);
            }
            setCurrentState(GameState.Wait);
            break;

        case GameState.PauseBeforeStart:
            time += Time.deltaTime;
            //Fight.GetComponent<RectTransform>().anchoredPosition = Vector2.Lerp(new Vector2(-377, -4), new Vector2(-15, -4), time);
            Fight.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.SmoothStep(-900, -15, time), -4);
            if (getStateElapsed() > 2.0f)
            {
                thePlayerManager.setCurrentState(PlayerManager.GameState.Fight);
                theEnemyManager.setCurrentState(EnemyManager.GameState.attack);
                setCurrentState(GameState.FightingEnemy);
                time = 0.0f;
            }
            //check whether we are dealing with the shopkeeper or an ennemy
            //Fight/Barter comes up from the left, stops in the center, and then moves to the right
            //move on to FightingEnnemy or ShopKeeper phase
            break;

        case GameState.FightingEnemy:
            time += Time.deltaTime;
            Fight.GetComponent <RectTransform>().anchoredPosition = new Vector2(Mathf.SmoothStep(-15, 900, time * 3), -4);  // new Vector2(-15, -4), new Vector2(387, -4), time*3);


            if (getStateElapsed() > 1.0f)
            {
                theButtonManager.SetAllButtons(true);
                setCurrentState(GameState.Wait);
            }
            //this code might be unnecessary, I think i can do these things from the player and ennemy manager.

            /*if (enemyIsDefeated)
             * {
             *  setCurrentState(GameState.OutroSequence);
             * }else if (playerIsDead)
             * {
             *  setCurrentState(GameState.GameOverSequence);
             * }*/

            //Activate the player fighting phase
            //check if either the player or the ennemy are dead
            //move on to the gameOver or Outro Sequence
            break;

        case GameState.OutroSequence:
            theButtonManager.SetAllButtons(false);
            theEnemyManager.setCurrentState(EnemyManager.GameState.wait);
            thePlayerManager.setCurrentState(PlayerManager.GameState.LeaveScene);
            time += Time.deltaTime * 2;
            Color tmp = fadeToBlack.color;
            alpha             = Mathf.Lerp(0.0f, 1.0f, time / 2);
            tmp.a             = alpha;
            fadeToBlack.color = tmp;
            if (getStateElapsed() > 2.0f)
            {
                thePlayerManager.setCurrentState(PlayerManager.GameState.Wait);
                theEnemyManager.setCurrentState(EnemyManager.GameState.wait);
                setCurrentState(GameState.ItemCollection);
                time = 0.0f;
            }
            //Have the enemie perform death animation and then fade out.
            //Then have the player move upwards out of the canvas
            //Then fade to black
            //Move on to Item Collection Phase
            break;

        case GameState.ItemCollection:
            //Debug.Log("You have collected this: insert name here");
            int fire = 0, water = 0, earth = 0, air = 0;
            if (!shopKeepLevel)
            {
                Collection.text = "You picked up: ";

                for (int i = 0; i < totalDrop; i++)
                {
                    if (theEnemyManager.GetComponent <EnemyType>().drop[i] == Item.EmberPebble)
                    {
                        fire += 1;
                        //theInventoryScript.ChangeItemValue(Item.EmberPebble, 1);
                    }
                    else if (theEnemyManager.GetComponent <EnemyType>().drop[i] == Item.GaiaSeed)
                    {
                        earth += 1;
                        //theInventoryScript.ChangeItemValue(Item.GaiaSeed, 1);
                    }
                    else if (theEnemyManager.GetComponent <EnemyType>().drop[i] == Item.NimbusQuill)
                    {
                        air += 1;
                        //theInventoryScript.ChangeItemValue(Item.NimbusQuill, 1);
                    }
                    else if (theEnemyManager.GetComponent <EnemyType>().drop[i] == Item.MermaidScale)
                    {
                        water += 1;
                        //theInventoryScript.ChangeItemValue(Item.MermaidScale, 1);
                    }
                }
                if (fire != 0)
                {
                    Collection.text += "\n Ember Pebble: " + fire;
                }
                if (earth != 0)
                {
                    Collection.text += "\n GaiaSeed: " + earth;
                }
                if (air != 0)
                {
                    Collection.text += "\n NimbusQuill: " + air;
                }
                if (water != 0)
                {
                    Collection.text += "\n MermaidScale: " + water;
                }
                Collection.gameObject.SetActive(true);
            }
            else
            {
                if (thePlayerManager.currentHealth == thePlayerManager.maxHealth && theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count > 0)
                {
                    // thePlayerManager.currentHealth -= 25;
                    // thePlayerManager.maxHealth += 50;
                    Collection.text = "Thank you for these resources stranger. \nYou seem in good health, let me enhances your abilities\n\nYour max health pool has increased to: " + (thePlayerManager.maxHealth + 50) + "\nUnfortunately, you had to sustain 25 damage.";
                }
                else if (theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count > 0)
                {
                    //thePlayerManager.currentHealth += 25;
                    //Mathf.Clamp(thePlayerManager.currentHealth, 0, thePlayerManager.maxHealth);
                    Collection.text = "Thank you for these resources stranger.\nLet me heal your wounds";
                }
                else
                {
                    Collection.text = "Another time then...";
                }
                Collection.gameObject.SetActive(true);
            }
            if (getStateElapsed() > 4.0f)
            {
                if (!shopKeepLevel)
                {
                    if (fire != 0)
                    {
                        theInventoryScript.ChangeItemValue(Item.EmberPebble, fire);
                    }
                    if (earth != 0)
                    {
                        theInventoryScript.ChangeItemValue(Item.GaiaSeed, earth);
                    }
                    if (air != 0)
                    {
                        theInventoryScript.ChangeItemValue(Item.NimbusQuill, air);
                    }
                    if (water != 0)
                    {
                        theInventoryScript.ChangeItemValue(Item.MermaidScale, water);
                    }
                }
                else
                {
                    if (thePlayerManager.currentHealth == thePlayerManager.maxHealth && theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count > 0)
                    {
                        theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count = 0;
                        thePlayerManager.currentHealth -= 25;
                        thePlayerManager.maxHealth     += 50;
                        //Collection.text = "Thank you for these ressources stranger. \nYou seem in good health, let me enhances your abilities\n\nYour max health pool has increased to: " + thePlayerManager.maxHealth + "\nUnfortunately, you had to sustain 25 damage.";
                    }
                    else if (theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count > 0)
                    {
                        theShopkeeperManager.gameObject.transform.GetChild(0).GetComponent <ShopkeepBucket>().count = 0;
                        //thePlayerManager.currentHealth += 25;
                        thePlayerManager.currentHealth = Mathf.Clamp(thePlayerManager.currentHealth += 25, 0, thePlayerManager.maxHealth);
                        //Collection.text = "Thank you for theses ressources stranger.\nLet me heal your wounds";
                    }
                }
                Collection.gameObject.SetActive(false);
                setCurrentState(GameState.RestartPhase);
            }
            //Display the Items that were collected
            //Update the inventory of the player
            //wait until the player presses continue before restarting the phase
            //updating levels and percentages might happen here
            break;

        case GameState.RestartPhase:

            //Emable a random room
            rm.EnableClearRoom();

            //this is where we change the background, music, ennemies, shopkeep, etc
            shopKeepLevel = false;
            time         += Time.deltaTime * 2;
            Color tmp2 = fadeToBlack.color;
            alpha             = Mathf.Lerp(1.0f, 0.0f, time / 2);
            tmp2.a            = alpha;
            fadeToBlack.color = tmp2;

            if (getStateElapsed() > 2.0f)
            {
                //attempts to spawn a shopkeeper
                int levelsSinceShop = currentLevel - lastLevelShop;
                currentLevel += 1;
                //level that just ended was a shop, automatically spawn a monster for next level
                if (levelsSinceShop == 0 && currentLevel != 2)
                {
                    Destroy(theShopkeeperManager.gameObject);
                    Instantiate(enemies[Random.Range(0, 3)]);
                    rm.EnableRandomRoom();
                }
                else if (levelsSinceShop < 4)
                {
                    Destroy(theEnemyManager.gameObject);
                    int spawnshop = Random.Range(1, 11);
                    if (spawnshop <= 2)
                    {
                        //Instantiate the shopkeeper

                        Instantiate(shopkeeper);
                        shopKeepLevel = true;
                        lastLevelShop = currentLevel;
                    }
                    else
                    {
                        Instantiate(enemies[Random.Range(0, 3)]);
                        rm.EnableRandomRoom();
                    }
                }
                else if (levelsSinceShop < 8)
                {
                    Destroy(theEnemyManager.gameObject);
                    int spawnshop = Random.Range(1, 11);
                    if (spawnshop <= 4)
                    {
                        //Instantiate the shopkeeper

                        Instantiate(shopkeeper);
                        shopKeepLevel = true;
                        lastLevelShop = currentLevel;
                    }
                    else
                    {
                        Instantiate(enemies[Random.Range(0, 3)]);
                        rm.EnableRandomRoom();
                    }
                }
                else if (levelsSinceShop < 10)
                {
                    Destroy(theEnemyManager.gameObject);
                    int spawnshop = Random.Range(1, 11);
                    if (spawnshop <= 6)
                    {
                        //Instantiate the shopkeeper

                        Instantiate(shopkeeper);
                        shopKeepLevel = true;
                        lastLevelShop = currentLevel;
                    }
                    else
                    {
                        Instantiate(enemies[Random.Range(0, 3)]);
                        rm.EnableRandomRoom();
                    }
                }
                else if (levelsSinceShop >= 10)
                {
                    Destroy(theEnemyManager.gameObject);
                    //instantiate the shopkeeper
                    Instantiate(shopkeeper);
                    shopKeepLevel = true;
                    lastLevelShop = currentLevel;
                }
                //Destroy(theEnemyManager.gameObject);
                //Instantiate(enemies[Random.Range(0, 3)]);
                time = 0;

                setCurrentState(GameState.IntroSequence);
            }
            break;

        case GameState.ShopkeeperSequence:
            //enable the phase to barter/fight the shopkeeper
            //figure out if we need an other outro sequence for the shopkeeper, or if we can skip that
            //move back to the intro sequence
            break;

        case GameState.PauseScreen:
            //this is for if we have the time;
            break;

        case GameState.GameOverSequence:
            //Debug.Log("The Player Died: " + getStateElapsed());
            if (shopKeepLevel)
            {
                theShopkeeperManager.setCurrentState(ShopkeeperManager.GameState.wait);
            }
            time += Time.deltaTime * 2;
            Color tmp3 = fadeToBlack.color;
            alpha             = Mathf.Lerp(0.0f, 1.0f, time);
            tmp3.a            = alpha;
            fadeToBlack.color = tmp3;
            if (getStateElapsed() >= 2.0f)
            {
                SceneManager.LoadScene(0);
            }
            //GAME OVER
            break;
        }
    }