예제 #1
0
        /// <summary>
        /// Maakt de blok aan
        /// </summary>
        /// <param name="id">Afhankelijk van de id zullen we een bepaalde blok aanmaken</param>
        /// <param name="content">ContentManager object dat we gebruiken om textures te laden</param>
        /// <returns>De aangemaakt blok</returns>
        protected override GameObject CreateBlock(int id, ContentManager content)
        {
            GameObject b = null;

            if (id == 1)
            {
                b = new DirtBlock(content, "01");
            }
            else if (id == 2)
            {
                b = new GrassTopBlock(content, "04");
            }
            else if (id == 3)
            {
                b = new GrassRightBLock(content, "08");
            }
            else if (id == 4)
            {
                b = new LeftTopCornerBlock(content, "03");
            }
            else if (id == 5)
            {
                b = new RightTopCornerBlock(content, "02");
            }
            else if (id == 6)
            {
                b = new AcidMudLeftAndBottomBlock(content, "19");
            }
            else if (id == 7)
            {
                b = new AcidMudBottomBlock(content, "15");
            }
            else if (id == 8)
            {
                b = new AcidMudRightAndBottomBlock(content, "22");
            }
            else if (id == 9)
            {
                b = new GrassLeftBlock(content, "07");
            }
            else if (id == 10)
            {
                b = new LeftBottomCornerBlock(content, "10");
            }
            else if (id == 11)
            {
                b = new RightBottomCornerBlock(content, "09");
            }
            else if (id == 12)
            {
                b = new PlatformBlock(content, "plate1");
            }
            else if (id == 13)
            {
                b = new BoxFirstVariant(content, "box1");
            }
            else if (id == 14)
            {
                b = new BoxSecondVariant(content, "box2");
            }
            else if (id == 15)
            {
                b = new Scarecrow(content, "scarecrow");
            }
            else if (id == 16)
            {
                b = new Pointer(content, "pointer");
            }
            else if (id == 17)
            {
                b = new OrangeTree(content, "tree1");
            }
            else if (id == 18)
            {
                b = new YellowTree(content, "tree2");
            }
            else if (id == 19)
            {
                b = new MovingBlock(content, "plate1");
            }
            else if (id == 20)
            {
                b = new MovingBlock(content, "plate1")
                {
                    Invert = true
                }
            }
            ;
            else if (id == 21)
            {
                b = new StarCollectable(content, "star");
            }
            else if (id == 22)
            {
                b = new BouncingAcidBall(content, "LavaFireballSprite");
            }
            else if (id == 23)
            {
                b = new UpUnderBlock(content, "bovenonder");
            }
            else if (id == 24)
            {
                b = new LeftOverRoofBlock(content, "linksoverkaping");
            }
            else if (id == 25)
            {
                b = new RightOverRoofBlock(content, "rechtsoverkaping");
            }
            else if (id == 26)
            {
                b = new UnderBlock(content, "13");
            }
            else if (id == 27)
            {
                b = new FullBlock(content, "11");
            }
            else if (id == 30)
            {
                b = new GreenGoblin(content, "GreenGoblinSprite");
            }
            else if (id == 31)
            {
                b = new Giant(content, "GiantSprite");
            }
            else if (id == 32)
            {
                b = new Orc(content, "BlackGoblin");
            }
            else if (id == 33)
            {
                b = new BlueGoblin(content, "BlueMonster");
            }
            else if (id == 40)
            {
                b = new InvisibleBlock(content, "legeBlok");
            }
            else if (id == 50)
            {
                b = new ButtonNextLevel(content, "button");
            }
            return(b);
        }
    public void Init(Vector2 pos, FloorBlock floorPatern, WallBlock wallPatern, PlatformBlock platformPatern, SpriteRenderer background)
    {
        position           = pos;
        backgroundRenderer = Instantiate(background);
        backgroundRenderer.transform.localScale = new Vector2(0.9333f, 0.948f);
        backgroundRenderer.transform.parent     = transform;
        backgroundRenderer.gameObject.SetActive(false);

        int platform, wall, floor;

        platform = wall = floor = 0;
        for (int i = 0; i < patern.GetLength(0); ++i)
        {
            for (int j = 0; j < patern.GetLength(1); ++j)
            {
                switch (patern[i, j])
                {
                // Floor
                case 1:
                    ++floor;
                    break;

                // Wall
                case 2:
                    ++wall;
                    break;

                // Platform
                case 3:
                    ++platform;
                    break;

                // Void
                default:
                    break;
                }
            }
        }

        floorBlock    = new FloorBlock[floor];
        wallBlock     = new WallBlock[wall];
        platformBlock = new PlatformBlock[platform];

        Vector2 newPosition = -BLOCK_POS_MAX;

        for (int i = 0; i < patern.GetLength(0); ++i)
        {
            for (int j = 0; j < patern.GetLength(1); ++j)
            {
                switch (patern[i, j])
                {
                // Floor
                case 1:
                    --floor;
                    floorBlock[floor] = Instantiate(floorPatern);
                    floorBlock[floor].transform.parent   = transform;
                    floorBlock[floor].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    floorBlock[floor].Disable();
                    break;

                // Wall
                case 2:
                    --wall;
                    wallBlock[wall] = Instantiate(wallPatern);
                    wallBlock[wall].transform.parent   = transform;
                    wallBlock[wall].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    wallBlock[wall].Disable();
                    break;

                // Platform
                case 3:
                    --platform;
                    platformBlock[platform] = Instantiate(platformPatern);
                    platformBlock[platform].transform.parent   = transform;
                    platformBlock[platform].transform.position = new Vector3(newPosition.x, newPosition.y, 0f);
                    platformBlock[platform].Disable();
                    break;

                // Void
                default:
                    break;
                }
                newPosition.x += spriteSize;
            }
            newPosition.y -= spriteSize;
            newPosition.x  = -BLOCK_POS_MAX.x;
        }

        transform.Translate(new Vector2(position.x * (BLOCK_POS_MAX.x * 2) + position.x * spriteSize, position.y * (BLOCK_POS_MAX.y * 2) + position.y * spriteSize));
    }