Exemplo n.º 1
0
    void renderNextLevel(bool removeEntities)
    {
        if (removeEntities)
        {
            GameObject[] objToDelete = GameObject.FindGameObjectsWithTag("LevelTiles");
            for (int i = 0; i < objToDelete.Length; i++)
            {
                GameObject.Destroy(objToDelete[i].gameObject);
            }
            GameObject[] entitiesToDelete = GameObject.FindGameObjectsWithTag("Enemy");
            for (int i = 0; i < entitiesToDelete.Length; i++)
            {
                GameObject.Destroy(entitiesToDelete[i].gameObject);
            }
            GameObject[] signsToDelete = GameObject.FindGameObjectsWithTag("Sign");
            for (int i = 0; i < signsToDelete.Length; i++)
            {
                GameObject.Destroy(signsToDelete[i].gameObject);
            }
        }
        level += 1;
        if (level == 1)
        {
            levelTexture = firstLevel;
        }
        if (level == 2)
        {
            levelTexture = secondLevel;
        }
        if (level == 3)
        {
            levelTexture = thirdLevel;
        }
        if (level == 4)
        {
            levelTexture = fourthLevel;
            Instantiate(SignObj, new Vector2(29, 5), Quaternion.identity);
            GameObject go = GameObject.FindGameObjectWithTag("Sign");
            go.GetComponent <Sign>().message = "You're on your way to the concrete bunker";
            go.GetComponent <Sign>().cave    = true;
            go.GetComponent <Sign>().player  = player;
        }
        if (level == 5)
        {
            levelTexture = finalLevel;
        }

        tileColours = new Color[levelTexture.width * levelTexture.height];
        tileColours = levelTexture.GetPixels();
        for (int y = 0; y < levelTexture.height; y++)
        {
            for (int x = 0; x < levelTexture.width; x++)
            {
                if (tileColours[x + y * levelTexture.width] == grassColour)
                {
                    inst(grassSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == whiteBrickColour)
                {
                    inst(whiteBrickSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == woodColour)
                {
                    inst(woodSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == elevatorColour)
                {
                    inst(elevatorSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == whiteTileColour)
                {
                    inst(whiteTileSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == brickColour)
                {
                    inst(brickSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == usedElevatorColour)
                {
                    inst(usedElevatorSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == dirtColour)
                {
                    inst(dirtSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == redStoneColour)
                {
                    inst(redStoneSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == stoneColour)
                {
                    inst(stoneSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == spawnColour)
                {
                    inst(woodSprite, x, y);
                    player.updatePos(x, y);
                    obama.updatePos(x + 1, y);
                    secretService.updatePos(x + 2, y);
                }
                if (tileColours[x + y * levelTexture.width] == enemySpawnColour)
                {
                    inst(woodSprite, x, y);
                    Instantiate(enemy, new Vector2(x, y), new Quaternion());
                }

                //Bunker Code
                if (tileColours[x + y * levelTexture.width] == concreteWallColour)
                {
                    inst(concreteWallSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == concreteTileColour)
                {
                    inst(concreteTileSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == concreteLightRightColour)
                {
                    inst(concreteLightRightSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == concreteLightLeftColour)
                {
                    inst(concreteLightLeftSprite, x, y);
                }
                if (tileColours[x + y * levelTexture.width] == doorColour)
                {
                    inst(doorSprite, x, y);
                }
            }
        }
    }