Exemplo n.º 1
0
    void Start()
    {
        // Coloca o mapa
        var arenaAtual = Instantiate(arenas[Random.Range(0, arenas.Length)]);

        arenaAtual.GetComponent <ArenaScript>().SpawnInteractable(spawnPoints[2].transform.position);
        arenaAtual.GetComponent <ArenaScript>().SpawnInteractable(spawnPoints[3].transform.position);

        timeLeft         = totalTime;
        uiTexts[10].text = timeLeft.ToString();

        audioSource = GetComponent <AudioSource>();

        // Arrumas os player
        leftPlayerChosen  = Mensageiro.leftPlayerIndex;
        rightPlayerChosen = Mensageiro.rightPlayerIndex;

        var leftPlayerPreFab = Instantiate(players[leftPlayerChosen]);

        leftPlayer                      = leftPlayerPreFab.transform.GetChild(0).gameObject;
        leftPlayerScript                = leftPlayerPreFab.transform.GetChild(0).GetComponent <playerPlataformerController>();
        leftPlayerScript.isPlayer1      = true;
        leftPlayerScript.gameController = this;

        var rightPlayerPreFab = Instantiate(players[rightPlayerChosen]);

        rightPlayer                      = rightPlayerPreFab.transform.GetChild(0).gameObject;
        rightPlayerScript                = rightPlayerPreFab.transform.GetChild(0).GetComponent <playerPlataformerController>();
        rightPlayerScript.isPlayer1      = false;
        rightPlayerScript.gameController = this;

        // Acha a camera
        sceneCamera = GameObject.FindWithTag("MainCamera");

        // Pega os scripts dos players
        leftPlayerScript  = leftPlayer.transform.root.GetChild(0).GetComponent <playerPlataformerController>();
        rightPlayerScript = rightPlayer.transform.root.GetChild(0).GetComponent <playerPlataformerController>();

        leftPlayerScript.MoveTo(spawnPoints[0].transform.position);
        rightPlayerScript.MoveTo(spawnPoints[1].transform.position);

        // Vira os personagens
        rightPlayerScript.isLeft = false;
        leftPlayerScript.isLeft  = true;

        rightPlayerScript.flipCharacterLeft();
        leftPlayerScript.flipCharacterRight();

        // Coloca os nomes
        uiTexts[0].text = leftPlayerScript.characterName;
        uiTexts[1].text = rightPlayerScript.characterName;

        // Desativa pause e vitória
        uiTexts[4].enabled = false;
        uiTexts[5].enabled = false;

        uiTexts[6].gameObject.SetActive(false);
        uiTexts[7].gameObject.SetActive(false);
        uiTexts[8].gameObject.SetActive(false);
        uiTexts[9].gameObject.SetActive(false);

        uiTexts[2].gameObject.SetActive(false);
        uiTexts[3].gameObject.SetActive(false);

        // Colocam a cor
        uiImages[0].color = leftPlayerScript.mainColor;
        uiTexts[0].color  = leftPlayerScript.mainColor;
        uiTexts[2].color  = leftPlayerScript.mainColor;
        uiImages[6].color = leftPlayerScript.mainColor;

        uiTexts[1].color   = rightPlayerScript.mainColor;
        uiTexts[3].color   = rightPlayerScript.mainColor;
        uiImages[3].color  = rightPlayerScript.mainColor;
        uiImages[10].color = rightPlayerScript.mainColor;


        transform.GetChild(2).GetComponent <SpriteRenderer>().color = Color.black;

        // Coloca o sangue nos prefabs
        AttachParticles();

        StartCoroutine(StartCondition());

        /*// Start settings
         * camera.GetComponent<Camera>().orthographicSize = 15;
         * foreach (var text in uiTexts){
         *  text.GetComponent<CanvasRenderer>().SetAlpha(0);
         * }
         * foreach (var images in uiImages){
         *  images.GetComponent<CanvasRenderer>().SetAlpha(0);
         * }
         * uiImages[2].rectTransform.localScale = new Vector3(0, uiImages[2].rectTransform.localScale.y, uiImages[2].rectTransform.localScale.z);
         * uiImages[1].rectTransform.localScale = new Vector3(0, uiImages[1].rectTransform.localScale.y, uiImages[1].rectTransform.localScale.z);
         *
         * uiImages[5].rectTransform.localScale = new Vector3(0, uiImages[5].rectTransform.localScale.y, uiImages[5].rectTransform.localScale.z);
         * uiImages[4].rectTransform.localScale = new Vector3(0, uiImages[4].rectTransform.localScale.y, uiImages[4].rectTransform.localScale.z);*/
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // Cuida da vida
        PlayerHealth();

        PlayerBar();

        // Camera
        CameraControl();

        // BGOs do mapa
        MapaBGO();

        if (Input.GetKeyDown(KeyCode.Escape) && mode16bit)
        {
            mode16bit = false;
        }
        else if (Input.GetKeyDown(KeyCode.Escape) && !mode16bit)
        {
            mode16bit = true;
        }

        if (Input.GetKeyDown(KeyCode.JoystickButton8))
        {
            Instantiate(players[3]);
        }

        // Pausa o jogo
        if (Input.GetKeyDown(KeyCode.JoystickButton9) && !isPaused)
        {
            isPaused = true;
        }
        else if (Input.GetKeyDown(KeyCode.JoystickButton9) && isPaused)
        {
            isPaused = false;
        }

        if (Input.GetKeyDown(KeyCode.Backspace))
        {
            TDEEffect(rightPlayerScript);
        }

        // Pausa o jogo
        if (isPaused)
        {
            Time.timeScale = 0;
            leftPlayerScript.animator.speed  = 0;
            rightPlayerScript.animator.speed = 0;
            leftPlayerScript.enableControls  = false;
            rightPlayerScript.enableControls = false;
            uiTexts[5].enabled = true;
        }
        else
        {
            uiTexts[5].enabled = false;
        }

        if (!hitStopCurrently && !isPaused && !timeFreeze)
        {
            Time.timeScale = 1;
            leftPlayerScript.animator.speed  = 1;
            rightPlayerScript.animator.speed = 1;
        }


        // Checa a troca de lados
        var onTopLeft  = leftPlayer.transform.root.GetChild(2).GetChild(4).GetComponent <jumpOverCheck>().onTop;
        var onTopRight = rightPlayer.transform.root.GetChild(2).GetChild(4).GetComponent <jumpOverCheck>().onTop;

        if (leftPlayerScript.inCorner || rightPlayerScript.inCorner)
        {
            if (leftPlayerScript.posX > rightPlayerScript.posX && flipToggle && !onTopLeft && !onTopRight && !leftPlayerScript.currentlyAttacking && !rightPlayerScript.currentlyAttacking && leftPlayerScript.grounded && rightPlayerScript.grounded)
            {
                leftPlayerScript.isLeft  = false;
                rightPlayerScript.isLeft = true;
                leftPlayerScript.flipCharacterLeft();
                rightPlayerScript.flipCharacterRight();
                flipToggle = false;
            }
            else if (leftPlayerScript.posX < rightPlayerScript.posX && !flipToggle && !onTopLeft && !onTopRight && !leftPlayerScript.currentlyAttacking && !rightPlayerScript.currentlyAttacking && leftPlayerScript.grounded && rightPlayerScript.grounded)
            {
                leftPlayerScript.isLeft  = true;
                rightPlayerScript.isLeft = false;
                leftPlayerScript.flipCharacterRight();
                rightPlayerScript.flipCharacterLeft();
                flipToggle = true;
            }
        }
        else
        {
            if (leftPlayerScript.posX > rightPlayerScript.posX && flipToggle && !onTopLeft && !onTopRight && !leftPlayerScript.currentlyAttacking && !rightPlayerScript.currentlyAttacking)
            {
                leftPlayerScript.isLeft  = false;
                rightPlayerScript.isLeft = true;
                leftPlayerScript.flipCharacterLeft();
                rightPlayerScript.flipCharacterRight();
                flipToggle = false;
            }
            else if (leftPlayerScript.posX < rightPlayerScript.posX && !flipToggle && !onTopLeft && !onTopRight && !leftPlayerScript.currentlyAttacking && !rightPlayerScript.currentlyAttacking)
            {
                leftPlayerScript.isLeft  = true;
                rightPlayerScript.isLeft = false;
                leftPlayerScript.flipCharacterRight();
                rightPlayerScript.flipCharacterLeft();
                flipToggle = true;
            }
        }

        // Cuida do contador de combo
        ComboCounter();

        // Seleciona as coisas que acontecem quando o jogo roda
        if (gameRunning && !isPaused)
        {
            // Controle
            leftPlayerScript.enableControls  = true;
            rightPlayerScript.enableControls = true;
            timeLeft -= Time.deltaTime;
            if (timeLeft > 0)
            {
                uiTexts[10].text = timeLeft.ToString("0");
            }
            else
            {
                uiTexts[10].text = 0.ToString("0");
            }
        }
        else
        {
            leftPlayerScript.enableControls  = false;
            rightPlayerScript.enableControls = false;
        }

        leftPlayerScript.gameRunning  = gameRunning;
        rightPlayerScript.gameRunning = gameRunning;

        if (leftPlayerScript.jumpingOver || leftPlayerScript.beingJumpedOver)
        {
            leftPlayerScript.enableControls = false;
            leftPlayerScript.StopInput();
        }

        if (rightPlayerScript.jumpingOver || rightPlayerScript.beingJumpedOver)
        {
            rightPlayerScript.enableControls = false;
            rightPlayerScript.StopInput();
        }

        /*if (!introDone){
         *  DOTween.To(() => GameObject.FindWithTag("MainCamera").GetComponent<Camera>().orthographicSize, x => GameObject.FindWithTag("MainCamera").GetComponent<Camera>().orthographicSize = x, 10f, 2f);
         *  DOTween.To(() => alpha, x => alpha = x, 1f, 2f);
         *
         *  uiImages[2].rectTransform.DOScaleX(1, 2).SetDelay(2);
         *  uiImages[5].rectTransform.DOScaleX(1, 2).SetDelay(2);
         *  uiImages[1].rectTransform.DOScaleX(1, 2).SetDelay(2);
         *  uiImages[4].rectTransform.DOScaleX(1, 2).SetDelay(2);
         *
         *  foreach (var text in uiTexts){
         *      text.GetComponent<CanvasRenderer>().SetAlpha(alpha);
         *  }
         *  foreach (var images in uiImages){
         *      images.GetComponent<CanvasRenderer>().SetAlpha(alpha);
         *  }
         *  StartCoroutine(StartCondition());
         * }*/
    }