Пример #1
0
    void Update()
    {
        //spawnaaminen
        if (g == null)
        {
            g      = Instantiate(debugSprite);
            sprite = g.transform;
        }

        // liikuttaminen

        // kääntäminen

        // tippuminen (2)
        if (IsTherePuyoBelow() && g != null)
        {
            grid.AddPuyo((int)debugX, (int)debugY + 1, PuyoType.Puyo1, g);
            g      = null;
            debugX = defaultDebugX;
            debugY = defaultDebugY;
        }
        if (!IsTherePuyoBelow())
        {
            debugY = debugY - velocity * Time.deltaTime;                    //Ohjataan spriten liikettä y-akselilla
        }

        // piirtäminen (1)
        float worldX = -(grid.nX - 1) / 2f * grid.gridDistance + debugX * grid.gridDistance;
        float worldY = -(grid.nY - 1) / 2f * grid.gridDistance + debugY * grid.gridDistance;

        if (g != null)
        {
            sprite.transform.position = new Vector3(worldX, worldY) + grid.transform.position;          //Liikutetaan spritea, riippuvainen debugY:n arvosta
        }
    }
Пример #2
0
    void Update()
    {
        //spawnaaminen        }
        if (g1 == null)
        {
            if (grid.grid[defaultSpawnX1][defaultSpawnY1] != PuyoType.None ||
                grid.grid[defaultSpawnX2][defaultSpawnY2] != PuyoType.None)
            {
                gm.GameOver(playerId);
                return;
            }
            var generated = generator.GetNextPuyos(playerId);
            spawnType1 = generated[0];
            spawnType2 = generated[1];

            g1 = generator.InstantiatePuyoSprite(spawnType1);
            g2 = generator.InstantiatePuyoSprite(spawnType2);
        }
        ///////////////////// **JOYSTICK** /////////////////////
        var P1PadHorizontal = Input.GetAxisRaw("P1PadHorizontal");
        var P1PadVertical   = Input.GetAxisRaw("P1PadVertical");
        var P2PadHorizontal = Input.GetAxisRaw("P2PadHorizontal");
        var P2PadVertical   = Input.GetAxisRaw("P2PadVertical");

        // Puyo1 siirto oikealle ja vasemmalle, kiihdytys ja paikkojen vaihto
        if (playerId == 1)
        {
            if (P1PadHorizontal < 0 && P1PadAxis1 != P1PadHorizontal &&
                spawnX1 > 0 && !IsThereObstacleLeft1() && spawnX2 > 0 && !IsThereObstacleLeft2())
            {
                audioScript.moveSource.Play();
                spawnX1 = spawnX1 - 1;
                spawnX2 = spawnX2 - 1;
            }
            if (P1PadHorizontal > 0 && P1PadAxis1 != P1PadHorizontal &&
                spawnX1 < grid.nX - 1 && !IsThereObstacleRight1() && spawnX2 < grid.nX - 1 && !IsThereObstacleRight2())
            {
                audioScript.moveSource.Play();
                spawnX1 = spawnX1 + 1;
                spawnX2 = spawnX2 + 1;
            }
            if (P1PadVertical > 0)
            {
                velocity = defaultVelocity * 5;
            }
            else
            {
                velocity = defaultVelocity;
            }
            if (P1PadVertical < 0 && P1PadAxis2 != P1PadVertical)
            {
                var tempSt1 = spawnType1;
                spawnType1 = spawnType2;
                spawnType2 = tempSt1;
                var tempG1 = g1;
                g1 = g2;
                g2 = tempG1;
            }
        }
        if (playerId == 2)
        {
            // Puyo1 siirto oikealle ja vasemmalle, kiihdytys ja kääntö
            if (P2PadHorizontal < 0 && P2PadAxis1 != P2PadHorizontal &&
                spawnX1 > 0 && !IsThereObstacleLeft1() && spawnX2 > 0 && !IsThereObstacleLeft2())
            {
                audioScript.moveSource.Play();
                spawnX1 = spawnX1 - 1;
                spawnX2 = spawnX2 - 1;
            }
            if (P2PadHorizontal > 0 && P2PadAxis1 != P2PadHorizontal &&
                spawnX1 < grid.nX - 1 && !IsThereObstacleRight1() && spawnX2 < grid.nX - 1 && !IsThereObstacleRight2())
            {
                audioScript.moveSource.Play();
                spawnX1 = spawnX1 + 1;
                spawnX2 = spawnX2 + 1;
            }
            if (P2PadVertical > 0)
            {
                velocity = defaultVelocity * 5;
            }
            else
            {
                velocity = defaultVelocity;

                // kääntäminen
            }
            if (P2PadVertical < 0 && P2PadAxis2 != P2PadVertical)
            {
                var tempSt1 = spawnType1;
                spawnType1 = spawnType2;
                spawnType2 = tempSt1;
                var tempG1 = g1;
                g1 = g2;
                g2 = tempG1;
            }
        }
        P1PadAxis1 = P1PadHorizontal; //Muistetaan Padien Axis vanhat arvot
        P2PadAxis1 = P2PadHorizontal; //Muistetaan Padien Axis vanhat arvot
        P1PadAxis2 = P1PadVertical;
        P2PadAxis2 = P2PadVertical;
        ///////////////////// **KEYBOARD** /////////////////////
        // Puyo1 siirto oikealle ja vasemmalle, kiihdytys ja paikkojen vaihto
        if (Input.GetButtonDown("p1left") && spawnX1 > 0 && !IsThereObstacleLeft1() && spawnX2 > 0 && !IsThereObstacleLeft2() && playerId == 1)
        {
            audioScript.moveSource.Play();
            spawnX1 = spawnX1 - 1;
            spawnX2 = spawnX2 - 1;
        }
        if (Input.GetButtonDown("p1right") && spawnX1 < grid.nX - 1 && !IsThereObstacleRight1() && spawnX2 < grid.nX - 1 && !IsThereObstacleRight2() && playerId == 1)
        {
            audioScript.moveSource.Play();
            spawnX1 = spawnX1 + 1;
            spawnX2 = spawnX2 + 1;
        }
        if (Input.GetButtonDown("p1down") && playerId == 1)
        {
            velocity *= 5;
        }
        if (Input.GetButtonUp("p1down") && playerId == 1)
        {
            velocity = defaultVelocity;
        }
        // Puyo1 siirto oikealle ja vasemmalle, kiihdytys ja kääntö
        if (Input.GetButtonDown("p2left") && spawnX1 > 0 && !IsThereObstacleLeft1() && spawnX2 > 0 && !IsThereObstacleLeft2() && playerId == 2)
        {
            audioScript.moveSource.Play();
            spawnX1 = spawnX1 - 1;
            spawnX2 = spawnX2 - 1;
        }
        if (Input.GetButtonDown("p2right") && spawnX1 < grid.nX - 1 && !IsThereObstacleRight1() && spawnX2 < grid.nX - 1 && !IsThereObstacleRight2() && playerId == 2)
        {
            audioScript.moveSource.Play();
            spawnX1 = spawnX1 + 1;
            spawnX2 = spawnX2 + 1;
        }
        if (Input.GetButtonDown("p2down") && playerId == 2)
        {
            velocity *= 5;
        }
        if (Input.GetButtonUp("p2down") && playerId == 2)
        {
            velocity = defaultVelocity;
        }

        // kääntäminen
        if (Input.GetButtonDown("p1swap") && playerId == 1)
        {
            var tempSt1 = spawnType1;
            spawnType1 = spawnType2;
            spawnType2 = tempSt1;
            var tempG1 = g1;
            g1 = g2;
            g2 = tempG1;
        }
        if (Input.GetButtonDown("p2swap") && playerId == 2)
        {
            var tempSt1 = spawnType1;
            spawnType1 = spawnType2;
            spawnType2 = tempSt1;
            var tempG1 = g1;
            g1 = g2;
            g2 = tempG1;
        }



        //Tarkistus onko alhaalla jotain edessä?
        if (IsThereObstacleBelow1() && g1 != null || IsThereObstacleBelow2() && g2 != null)
        {
            grid.AddPuyo(Mathf.FloorToInt(spawnX1), Mathf.FloorToInt(spawnY1 + 1), spawnType1, g1);
            grid.AddPuyo(Mathf.FloorToInt(spawnX2), Mathf.FloorToInt(spawnY2 + 1), spawnType2, g2);
            Animator animator  = g1.GetComponent <Animator>();
            Animator animator2 = g2.GetComponent <Animator>();
            animator.Play("Bounce");
            animator2.Play("Bounce");
            audioScript.hitGroundSource.Play();
            g1      = null;
            g2      = null;
            spawnX1 = defaultSpawnX1;
            spawnY1 = defaultSpawnY1;
            spawnX2 = defaultSpawnX2;
            spawnY2 = defaultSpawnY2;
            StartCoroutine(grid.DropMatchRemove());
            velocity = defaultVelocity;
        }

        if (!IsThereObstacleBelow1() || !IsThereObstacleBelow2())
        {
            spawnY1 = spawnY1 - velocity * Time.deltaTime;
            spawnY2 = spawnY2 - velocity * Time.deltaTime; //Ohjataan spriten liikettä y-akselilla

            // piirtäminen (1)
            float worldX1 = -(grid.nX - 1) / 2f * grid.gridDistance + spawnX1 * grid.gridDistance;
            float worldY1 = -(grid.nY - 1) / 2f * grid.gridDistance + spawnY1 * grid.gridDistance;
            float worldX2 = -(grid.nX - 1) / 2f * grid.gridDistance + spawnX1 * grid.gridDistance;
            float worldY2 = -(grid.nY - 1) / 2f * grid.gridDistance + spawnY1 * grid.gridDistance;



            if (g1 != null)
            {
                g1.transform.position = new Vector3(worldX1, worldY1) + grid.transform.position;          //Liikutetaan spritea
                g2.transform.position = new Vector3(worldX2 + grid.gridDistance, worldY2) + grid.transform.position;
            }
        }
    }