IEnumerator Respawn(float cooldown)
    {
        yield return(new WaitForSeconds(cooldown));

        GameObject arturSceneManager = GameObject.FindGameObjectWithTag("SceneManager");

        ArturMetaInf metaInf      = arturSceneManager.GetComponent <ArturMetaInf>();
        LevelMetaInf levelMetaInf = transform.GetComponentInParent <LevelMetaInf>();

        Vector3 respawnPosition = levelMetaInf.respawnLocation;


        GameObject playerOne = GameObject.FindGameObjectWithTag("Player1");
        GameObject playerTwo = GameObject.FindGameObjectWithTag("Player2");

        playerOne.transform.parent = null;
        playerTwo.transform.parent = null;

        ArturPlayerOneController p1 = playerOne.GetComponent <ArturPlayerOneController>();
        ArturPlayerTwoController p2 = playerTwo.GetComponent <ArturPlayerTwoController>();

        p1.Respawn(respawnPosition + new Vector3(0, 3, 0));
        p2.Respawn(respawnPosition + new Vector3(2, 3, 0));


        metaInf.playerLives--;


        GameObject[] rooms = GameObject.FindGameObjectsWithTag("Room");

        foreach (GameObject g in rooms)
        {
            Vector3    instantiateAt = g.GetComponent <LevelMetaInf>().instantiatedAt;
            GameObject room          = Resources.Load <GameObject>("Rooms/" + ArturSceneManager.currentLevel + "/" + g.GetComponent <LevelMetaInf>().roomNumber);
            room.GetComponent <LevelMetaInf>().instantiatedAt  = instantiateAt;
            room.GetComponent <LevelMetaInf>().lastBlock       = g.GetComponent <LevelMetaInf>().lastBlock;
            room.GetComponent <LevelMetaInf>().respawnLocation = g.GetComponent <LevelMetaInf>().respawnLocation;

            Instantiate(room, instantiateAt, Quaternion.identity);
            Destroy(g);
        }
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        foreach (GameObject enemy in enemies)
        {
            Destroy(enemy);
        }

        string         enemyPath         = "Prefabs/Main/Enemies/Enemy";
        List <Vector3> allEnemyPositions = GameObject.FindGameObjectWithTag("ProceduralGenerator").GetComponent <ArturProceduralGeneratorManagerScript>().allEnemyPositions;

        foreach (Vector3 enemyPos in allEnemyPositions)
        {
            GameObject enemy = Resources.Load <GameObject>(enemyPath);
            Instantiate(enemy, enemyPos, Quaternion.identity);
        }
    }
Example #2
0
    public void Start()
    {
        pauseScreen            = GameObject.Find("PauseScreen");
        saveScoreScreen        = GameObject.Find("SaveScoreScreen");
        afterSavingNamesScreen = GameObject.Find("AfterSavingNamesScreen");
        gameoverScreen         = GameObject.Find("GameOverScreen");
        endOfLevelScreen       = GameObject.Find("EndOfLevelScreen");
        endOfLevelScreenFire   = GameObject.Find("EndOfLevelScreenFire");
        endLevelScore          = GameObject.Find("EndOfLevel - Score").GetComponent <Text>();
        endLevelScoreF         = GameObject.Find("EndOfLevel - ScoreF").GetComponent <Text>();

        player1 = GameObject.FindGameObjectWithTag("Player1").GetComponent <ArturPlayerOneController>();
        player2 = GameObject.FindGameObjectWithTag("Player2").GetComponent <ArturPlayerTwoController>();

        p1GameObject = GameObject.FindGameObjectWithTag("Player1");
        p2GameObject = GameObject.FindGameObjectWithTag("Player2");

        metaInf = GetComponent <ArturMetaInf>();

        pauseScreen.SetActive(false);
        gameoverScreen.SetActive(false);
        endOfLevelScreen.SetActive(false);
        endOfLevelScreenFire.SetActive(false);

        StandaloneInputModule inputModule = EventSystem.current.gameObject.GetComponent <StandaloneInputModule>();

        if (player1.controllerType == "DS4" && player1.playerNumber == 1)
        {
            inputModule.cancelButton   = "ds4_p1_button_circle";
            inputModule.submitButton   = "ds4_p1_button_x";
            inputModule.verticalAxis   = "ds4_p1_left_vertical";
            inputModule.horizontalAxis = "ds4_p1_left_horizontal";
        }
        else if (player1.controllerType == "DS4" && player1.playerNumber == 2)
        {
            inputModule.cancelButton   = "ds4_p2_button_circle";
            inputModule.submitButton   = "ds4_p2_button_x";
            inputModule.verticalAxis   = "ds4_p2_left_vertical";
            inputModule.horizontalAxis = "ds4_p2_left_horizontal";
        }
        else if (player1.controllerType == "Xbox" && player1.playerNumber == 1)
        {
            inputModule.cancelButton   = "xbox_p1_button_x";
            inputModule.submitButton   = "xbox_p1_button_a";
            inputModule.verticalAxis   = "xbox_p1_left_vertical";
            inputModule.horizontalAxis = "xbox_p1_left_horizontal";
        }
        else if (player1.controllerType == "Xbox" && player1.playerNumber == 2)
        {
            inputModule.cancelButton   = "xbox_p2_button_x";
            inputModule.submitButton   = "xbox_p2_button_a";
            inputModule.verticalAxis   = "xbox_p2_left_vertical";
            inputModule.horizontalAxis = "xbox_p2_left_horizontal";
        }
    }
Example #3
0
    void Start()
    {
        player1 = GameObject.FindGameObjectWithTag("Player1").GetComponent <ArturPlayerOneController>();
        player2 = GameObject.FindGameObjectWithTag("Player2").GetComponent <ArturPlayerTwoController>();
        metaInf = GetComponent <ArturMetaInf>();

        speedBonusTimePlayer1 = metaInf.speedBonusTime;
        speedBonusTimePlayer2 = metaInf.speedBonusTime;

        //splitScreenController = GameObject.Find("SplitScreen").GetComponent<SplitScreenController>();
        splitScreenController = GameObject.FindGameObjectWithTag("SplitScreenController").GetComponent <ArturSplitScreenCamera>();

        barContainerRight = GameObject.Find("Right Corner").GetComponent <Transform>();
        barTemplate       = GameObject.Find("BarTemplate").GetComponent <Transform>();
        barTemplate.gameObject.SetActive(false); // Template is not visible
        barContainerLeft = GameObject.Find("Left Corner").GetComponent <Transform>();
        barPositionRight = new Vector3(1650, 1000, 0);
        barPositionLeft  = new Vector3(-1650, 1000, 0);

        scorebarleft  = GameObject.Find("ScoreBarLeft");
        scorebarright = GameObject.Find("ScoreBarRight");
        livesleft     = GameObject.Find("LivesLeft");
        livesright    = GameObject.Find("LivesRight");
        middlecorner  = GameObject.Find("Middle Corner");

        AddNewBar(1, "energy");
        AddNewBar(2, "energy");

        // Initialize Scoretexts
        scoretexts = GameObject.FindGameObjectsWithTag("HighScoreText");
        foreach (GameObject g in scoretexts)
        {
            g.GetComponent <Text>().text = "0";
        }

        // Initialize Livetexts
        livetexts = GameObject.FindGameObjectsWithTag("LiveText");
        foreach (GameObject g in livetexts)
        {
            g.GetComponent <Text>().text = metaInf.playerLives.ToString();
        }
        // Initialize Health
        livesleft.transform.Find("Health").GetComponent <Image>().fillAmount  = (float)metaInf.playerHealth / (float)metaInf.initialPlayerHealth;
        livesright.transform.Find("Health").GetComponent <Image>().fillAmount = (float)metaInf.playerHealth / (float)metaInf.initialPlayerHealth;
        middlecorner.transform.Find("LivesMiddle").Find("Health").GetComponent <Image>().fillAmount = (float)metaInf.playerHealth / (float)metaInf.initialPlayerHealth;
    }
Example #4
0
    IEnumerator Respawn(float cooldown)
    {
        yield return(new WaitForSeconds(cooldown));

        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        foreach (GameObject enemy in enemies)
        {
            Destroy(enemy);
        }
        GameObject playerOne = GameObject.FindGameObjectWithTag("Player1");
        GameObject playerTwo = GameObject.FindGameObjectWithTag("Player2");

        playerOne.transform.parent = null;
        playerTwo.transform.parent = null;

        ArturPlayerOneController p1 = playerOne.GetComponent <ArturPlayerOneController>();
        ArturPlayerTwoController p2 = playerTwo.GetComponent <ArturPlayerTwoController>();

        ArturBasePlayerController behind = p1;

        if (p2.transform.position.x < p1.transform.position.x)
        {
            behind = p2;
        }


        GameObject[] rooms        = GameObject.FindGameObjectsWithTag("Room");
        LevelMetaInf levelMetaInf = rooms[0].GetComponent <LevelMetaInf>();

        for (int i = 0; i < rooms.Length - 1; i++)
        {
            if (rooms[i].transform.position.x <behind.transform.position.x &&
                                               rooms[i + 1].transform.position.x> behind.transform.position.x)
            {
                levelMetaInf = rooms[i].GetComponent <LevelMetaInf>();
            }
        }
        Vector3 respawnPosition = levelMetaInf.respawnLocation;

        p1.Respawn(respawnPosition + new Vector3(0, 3, 0));
        p2.Respawn(respawnPosition + new Vector3(2, 3, 0));

        foreach (GameObject g in rooms)
        {
            Vector3    instantiateAt = g.GetComponent <LevelMetaInf>().instantiatedAt;
            GameObject room          = Resources.Load <GameObject>("Rooms/" + ArturSceneManager.currentLevel + "/" + g.GetComponent <LevelMetaInf>().roomNumber);
            room.GetComponent <LevelMetaInf>().instantiatedAt  = instantiateAt;
            room.GetComponent <LevelMetaInf>().lastBlock       = g.GetComponent <LevelMetaInf>().lastBlock;
            room.GetComponent <LevelMetaInf>().respawnLocation = g.GetComponent <LevelMetaInf>().respawnLocation;

            Instantiate(room, instantiateAt, Quaternion.identity);
            Destroy(g);
        }

        string         enemyPath         = "Prefabs/Main/Enemies/Enemy";
        List <Vector3> allEnemyPositions = GameObject.FindGameObjectWithTag("ProceduralGenerator").GetComponent <ArturProceduralGeneratorManagerScript>().allEnemyPositions;

        foreach (Vector3 enemyPos in allEnemyPositions)
        {
            GameObject enemy = Resources.Load <GameObject>(enemyPath);
            Instantiate(enemy, enemyPos, Quaternion.identity);
        }

        //GameObject.FindGameObjectWithTag("ScreenFader").GetComponent<Animator>().SetBool("fade_out_in", false);
    }