void Update()
    {
        //Moving and adding points while playing
        if (!gameOver && gameStarted)
        {
            transform.Translate(-spawnedTiles[0].transform.forward * Time.deltaTime * (movingSpeed + (score / 500)), Space.World);
            score += Time.deltaTime * movingSpeed;
        }

        //Move the tile to the front if it's behind the Camera
        if (mainCamera.WorldToViewportPoint(spawnedTiles[0].endPoint.position).z < 0)
        {
            PlatformTile tileTmp = spawnedTiles[0];
            spawnedTiles.RemoveAt(0);
            tileTmp.transform.position = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - tileTmp.startPoint.localPosition;
            tileTmp.GetRandomObstacle();
            spawnedTiles.Add(tileTmp);
        }

        //Enable UI needs to start the game again
        if ((gameOver || !gameStarted) && mainCanvas.enabled == false && !menuController.paused)
        {
            mainCanvas.enabled = true;
        }

        scoreUI.text = "Score: " + (int)score;
    }
Example #2
0
    void brotherGeneration(PlatformTile t1, PlatformTile t2)
    {
        int iteration = random.Next(1, 3);

        for (int i = 0; i < iteration; i++)
        {
            currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - t1.startPoint.localPosition;
            PlatformTile spawnedT1 = Instantiate(t1, currentSpawnPos, Quaternion.identity) as PlatformTile;

            spawnedT1.transform.SetParent(transform);
            spawnedTiles.Add(spawnedT1);

            currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - t2.startPoint.localPosition;
            PlatformTile spawnedT2 = Instantiate(t2, currentSpawnPos, Quaternion.identity) as PlatformTile;

            spawnedT2.transform.SetParent(transform);
            spawnedTiles.Add(spawnedT2);
        }

        currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - startTile.startPoint.localPosition;
        PlatformTile spawnedStartTile = Instantiate(startTile, currentSpawnPos, Quaternion.identity) as PlatformTile;

        spawnedStartTile.transform.SetParent(transform);
        spawnedTiles.Add(spawnedStartTile);
    }
Example #3
0
    void Update()
    {
        if (!gameOver)
        {
            transform.Translate(-spawnedTiles[0].transform.forward * Time.deltaTime * (movingSpeed), Space.World);
            score += multiplier;
            scoreboost++;
            scoreTxt.text = score.ToString();

            if (scoreboost > 1000)
            {
                movingSpeed += 5;
                scoreboost   = 0;
            }
        }

        if (mainCamera.WorldToViewportPoint(spawnedTiles[0].endPoint.position).z < 0)
        {
            PlatformTile tileTmp = spawnedTiles[0];
            spawnedTiles.RemoveAt(0);
            tileTmp.transform.position = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - tileTmp.startPoint.localPosition;
            tileTmp.ActivateRandomObstacle();
            spawnedTiles.Add(tileTmp);
        }
    }
Example #4
0
    void Start()
    {
        instance = this;

        multiplier = PlayerPrefs.GetInt("multiplier", 1);
        Vector3 spawnPosition           = startPoint.position;
        int     tilesWithNoObstaclesTmp = tilesWithoutObstacles;

        for (int i = 0; i < tilesToPreSpawn; i++)
        {
            spawnPosition -= tilePrefab.startPoint.localPosition;
            PlatformTile spawnedTile = Instantiate(tilePrefab, spawnPosition, Quaternion.identity) as PlatformTile;
            if (tilesWithNoObstaclesTmp > 0)
            {
                spawnedTile.DeactivateAllObstacles();
                tilesWithNoObstaclesTmp--;
            }
            else
            {
                spawnedTile.ActivateRandomObstacle();
            }

            spawnPosition = spawnedTile.endPoint.position;
            spawnedTile.transform.SetParent(transform);
            spawnedTiles.Add(spawnedTile);
        }
    }
Example #5
0
        //Finds the destination tilemap of out tile
        //Checkflag true if you want it to launch errors
        public Tilemap findDestinationTilemap(bool checkFlag)
        {
            if (!(cells[0].tile is PlatformTile))
            {
                if (checkFlag)
                {
                    Debug.LogError("What you're trying to paint is not a PlatformTile. You cannot use this brush to paint such object");
                }
                return(null);
            }

            PlatformTile tile = (PlatformTile)cells[0].tile; //Gets the tile to be painted

            if (checkFlag)
            {
                //Checks if all tiles selected are part of the same destination. If not, the system doesnt allow it
                for (int i = 1; i < cellCount; i++)
                {
                    PlatformTile tileToCheck = (PlatformTile)cells[i].tile;
                    if (tile.getDestination() != tileToCheck.getDestination())
                    {
                        Debug.LogError("Cannot Paint tiles that have different destinations");
                        return(null);
                    }
                }
            }

            //Finds the destination Tilemap
            Tilemap destinationTilemap = neutralTilemap;

            switch (tile.getDestination())
            {
            case destinationOption.Neutral:
                destinationTilemap = neutralTilemap;
                break;

            case destinationOption.Black:
                destinationTilemap = blackTilemap;
                break;

            case destinationOption.White:
                destinationTilemap = whiteTilemap;
                break;

            default:
                Debug.Log("Errore, Destination non corretta");
                break;
            }

            //Returns the destination Tilemap
            return(destinationTilemap);
        }
Example #6
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.transform.tag == "LargeObject" && playerManager.hasCollectable)
     {
         if (Input.GetButton("ActivateCollectable" + playerNumber))
         {
             PlatformTile tile = collision.gameObject.GetComponent <PlatformTile>();
             if (tile.state != playerManager.state)
             {
                 tile.SetState(playerManager.state);
                 playerManager.ChangeObject(PlayerManager.Objects.LARGE_OBJECT);
             }
         }
     }
 }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        // Move the object upward in world space x unit/second.
        if (!gameOver && gameStarted)
        {
            title.SetActive(false);
            menuTxt.text  = "";
            scoreTxt.text = "x" + score.ToString();
            transform.Translate(-spawnedTiles[0].transform.forward * Time.deltaTime * (movingSpeed * (invincibleMode ? 1.5f : 1) + (score / 10)), Space.World);
        }

        if (mainCamera.WorldToViewportPoint(spawnedTiles[0].endPoint.position).z < 0)
        {
            //Move the tile to the front if it's behind the Camera

            PlatformTile tileTmp = spawnedTiles[0];
            if (tileTmp.CompareTag("Separator"))
            {
                CoordonatedGeneration();
            }
            Destroy(tileTmp.gameObject);
            spawnedTiles.RemoveAt(0);
        }

        if (gameOver || !gameStarted)
        {
            if ((Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) || Input.GetMouseButtonDown(0))
            {
                if (gameOver)
                {
                    menuTxt.text = "";
                    title.SetActive(false);
                    //Restart current scene
                    Scene scene = SceneManager.GetActiveScene();
                    SceneManager.LoadScene(scene.name);
                }
                else
                {
                    //Start the game
                    gameStarted  = true;
                    menuTxt.text = "";
                    title.SetActive(false);
                }
            }
        }
    }
Example #8
0
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.transform.tag == "PlatformTile")
     {
         if (playerEnergy.energy <= 0 || !playerMovement.isGrounded)
         {
             return;
         }
         if (Input.GetButton("Trail" + playerNumber))
         {
             PlatformTile tile = collision.gameObject.GetComponent <PlatformTile>();
             if (tile.state != playerManager.state)
             {
                 tile.SetState(playerManager.state);
                 playerManager.ChangeObject(PlayerManager.Objects.TILE);
             }
         }
     }
 }
    void Start()
    {
        menuController     = FindObjectOfType <MenuController>();
        mainCanvas.enabled = false;
        gameOverUI.enabled = false;
        instance           = this;

        if (PlayerPrefs.HasKey("CameraView"))
        {
            if (PlayerPrefs.GetInt("CameraView") == 1)
            {
                SetView_Side();
            }
            else
            {
                SetView_Default();
            }
        }

        Vector3 spawnPosition           = spawnPoint;
        int     tilesWithNoObstaclesTmp = tilesWithoutObstacles;

        //Spawn set number of tiles to PreSpawn
        for (int i = 0; i < tilesToPreSpawn; i++)
        {
            spawnPosition -= tilePrefab.startPoint.localPosition;
            PlatformTile spawnedTile = Instantiate(tilePrefab, spawnPosition, Quaternion.identity);
            if (tilesWithNoObstaclesTmp > 0)
            {
                spawnedTile.DisableAllObstacles();
                tilesWithNoObstaclesTmp--;
            }
            else
            {
                spawnedTile.GetRandomObstacle();
            }

            spawnPosition = spawnedTile.endPoint.position;
            spawnedTile.transform.SetParent(transform);
            spawnedTiles.Add(spawnedTile);
        }
    }
Example #10
0
    // Start is called before the first frame update
    void Start()
    {
        currentSpawnPos = startPoint.position;
        for (int j = 0; j < nbTutoTiles; j++)
        {
            PlatformTile spawnedStartTile = Instantiate(startTile, currentSpawnPos, Quaternion.identity) as PlatformTile;
            currentSpawnPos = spawnedStartTile.endPoint.position - startTile.startPoint.localPosition;
            spawnedStartTile.transform.SetParent(transform);
            spawnedTiles.Add(spawnedStartTile);
        }

        for (int i = 0; i < tilesToPreSpawn; i++)
        {
            CoordonatedGeneration();
        }

        menuString    = menuTxt.text;
        scoreMax      = PlayerPrefs.GetInt("ScoreMax");
        scoreTxt.text = "x" + scoreMax.ToString();
    }
Example #11
0
    // Start is called before the first frame update
    void Start()
    {
        if (!platformMakerOn)
        {
            return;
        }
        ;

        for (int j = 0; j < lignes; j++)
        {
            for (int i = 0; i < colonnes; i++)
            {
                //if (i == 0&j==0)
                //{
                //   Instantiate(tile, gameObject.transform);
                //}

                Vector2      newPos          = new Vector2(gameObject.transform.position.x + i * offset, gameObject.transform.position.y + j * (-offset));
                PlatformTile newPlatformTile = Instantiate(tile, newPos, transform.rotation);
                newPlatformTile.transform.SetParent(gameObject.transform);
            }
        }
    }
Example #12
0
    void  CoordonatedGeneration()
    {
        bool spawnCross = false;

        if (nbTemplateNoStar > 0 && !invincibleMode)
        {
            int p = random.Next(1, 10);
            if (p <= nbTemplateNoStar)
            {
                spawnCross       = true;
                nbTemplateNoStar = 0;
            }
        }


        int          randomNumber = random.Next(0, tiles.Length);
        PlatformTile original     = tiles[randomNumber];
        PlatformTile brother;

        if (spawnCross)
        {
            currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - cross.startPoint.localPosition;
            PlatformTile spawnedCross = Instantiate(cross, currentSpawnPos, Quaternion.identity) as PlatformTile;

            spawnedCross.transform.SetParent(transform);
            spawnedTiles.Add(spawnedCross);
        }
        else if (original.CompareTag("Corridor") || original.CompareTag("Narrow"))
        {
            int iteration = random.Next(2, 4);
            for (int i = 0; i < iteration; i++)
            {
                //currentSpawnPos -= original.startPoint.localPosition;
                currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - original.startPoint.localPosition;
                PlatformTile spawnedCorridor = Instantiate(original, currentSpawnPos, Quaternion.identity) as PlatformTile;

                spawnedCorridor.transform.SetParent(transform);
                spawnedTiles.Add(spawnedCorridor);
            }
            if (!invincibleMode)
            {
                nbTemplateNoStar++;
            }
        }
        else if (original.CompareTag("ZigZag1"))
        {
            brother = zigzag2;
            brotherGeneration(original, brother);
            if (!invincibleMode)
            {
                nbTemplateNoStar++;
            }
        }
        else if (original.CompareTag("ZigZag3"))
        {
            brother = zigzag4;
            brotherGeneration(original, brother);
            if (!invincibleMode)
            {
                nbTemplateNoStar++;
            }
        }
        else if (original.CompareTag("ZigZag5"))
        {
            brother = zigzag6;
            brotherGeneration(original, brother);
            if (!invincibleMode)
            {
                nbTemplateNoStar++;
            }
        }

        currentSpawnPos = spawnedTiles[spawnedTiles.Count - 1].endPoint.position - startTile.startPoint.localPosition;
        PlatformTile spawnedStartTile = Instantiate(startTile, currentSpawnPos, Quaternion.identity) as PlatformTile;

        spawnedStartTile.transform.SetParent(transform);
        spawnedTiles.Add(spawnedStartTile);
    }