Esempio n. 1
0
        /// <summary>
        /// Adds objects to the world from the 2d level array
        /// </summary>
        /// <param name="layer1"></param>
        /// <param name="size"></param>
        protected void GenerateLevel(int[,] layer1, int[,] layer2, float size)
        {
            if (wtf == false)
            {
                for (int x = 0; x < layer1.GetLength(1); x++)
                {
                    for (int y = 0; y < layer1.GetLength(0); y++)
                    {
                        int coordinate = layer1[y, x];

                        switch (coordinate)
                        {
                        case (1):
                        {
                            GameObject newWall = new Wall(new Vector2(x * size, y * size));
                            AddObj(newWall);
                            break;
                        }

                        case (2):
                        {
                            GameObject newCrate = new Crate(new Vector2(x * size, y * size));
                            AddObj(newCrate);
                            break;
                        }

                        case (3):
                        {
                            GameObject newSun = new Sun(new Vector2(x * size, y * size));
                            AddObj(newSun);
                            break;
                        }

                        case (4):
                        {
                            GameObject newSunRay = new SunRay(new Vector2(x * size, y * size));
                            AddObj(newSunRay);
                            break;
                        }

                        //case (5):
                        //    {
                        //        GameWorld.gameObjects.Add(new Door("Door1", new Vector2(x * size, y * size), true));
                        //        break;
                        //    }

                        //case (6):
                        //    {
                        //        GameWorld.gameObjects.Add(new Key("Key1", new Vector2(x * size, y * size)));
                        //        break;
                        //    }

                        case (7):
                        {
                            GameObject newChest = new Chest(new Vector2(x * size, y * size));
                            AddObj(newChest);
                            break;
                        }

                        case (8):
                        {
                            GameObject newEnemy = new Enemy(new Vector2(x * size, y * size));
                            AddObj(newEnemy);
                            break;
                        }

                        case (9):
                        {
                            GameObject newVase = new Vase(new Vector2(x * size, y * size));
                            AddObj(newVase);
                            break;
                        }

                        case (10):
                        {
                            Key newKeyA = new Key(new Vector2(x * size, y * size), 1);
                            KeyList.Add(newKeyA);
                            AddObj(newKeyA);
                            break;
                        }

                        case (11):
                        {
                            Key newKeyB = new Key(new Vector2(x * size, y * size), 2);
                            KeyList.Add(newKeyB);
                            AddObj(newKeyB);
                            break;
                        }

                        case (12):
                        {
                            Key newKeyC = new Key(new Vector2(x * size, y * size), 3);
                            KeyList.Add(newKeyC);
                            AddObj(newKeyC);
                            break;
                        }

                        case (13):
                        {
                            foreach (Key key in KeyList)
                            {
                                if (key.ID == 1)
                                {
                                    Door newDoorA = new Door(new Vector2(x * size, y * size), key);
                                    AddObj(newDoorA);
                                }
                            }
                            break;
                        }

                        case (14):
                        {
                            foreach (Key key in KeyList)
                            {
                                if (key.ID == 2)
                                {
                                    Door newDoorB = new Door(new Vector2(x * size, y * size), key);
                                    AddObj(newDoorB);
                                }
                            }
                            break;
                        }

                        case (15):
                        {
                            foreach (Key key in KeyList)
                            {
                                if (key.ID == 3)
                                {
                                    Door newDoorC = new Door(new Vector2(x * size, y * size), key);
                                    AddObj(newDoorC);
                                }
                            }
                            break;
                        }
                        }
                    }
                }


                for (int x = 0; x < layer2.GetLength(1); x++)
                {
                    for (int y = 0; y < layer2.GetLength(0); y++)
                    {
                        int coordinate = layer2[y, x];

                        switch (coordinate)
                        {
                        case (1):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.WallSprite, new Vector2(x * size, y * size)));
                            break;
                        }

                        case (2):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.BookshelfSprite, new Vector2(x * size, y * size)));
                            break;
                        }

                        case (3):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.SunSprite, new Vector2(x * size, y * size)));
                            break;
                        }

                        case (4):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.CarpetTexture, new Vector2(x * size, y * size)));
                            break;
                        }

                        case (5):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.CarpetSunTexture, new Vector2(x * size, y * size)));
                            break;
                        }

                        case (6):
                        {
                            GameWorld.decorationsObjects.Add(new Decoration(GameWorld.FloorboardTexture, new Vector2(x * size, y * size)));
                            break;
                        }
                        }
                    }
                }
                wtf = true;
            }
        }
        // 0 = Null *
        // 1 = Wall *
        // 2 = Crate *
        // 3 = Sun *
        // 4 = Sunrays *
        // 5 = Door 1 *
        // 6 = Key *
        // 7 = Chest *
        // 8 = Enemy *
        // 9 = Vase *
        // 10 = Player *
        // 11 = Door 2 *

        public LevelOne()
        {
            GameObject newSunRay = new SunRay(new Vector2(19 * 96 * GameWorld.Scale, 13 * 96 * GameWorld.Scale));

            GameWorld.collisionObjects.Add(newSunRay);
            GameWorld.gameObjects.Add(newSunRay);

            GameObject newSunRay1 = new SunRay(new Vector2(31 * 96 * GameWorld.Scale, 12 * 96 * GameWorld.Scale));

            GameWorld.collisionObjects.Add(newSunRay1);
            GameWorld.gameObjects.Add(newSunRay1);

            GameObject newSunRay2 = new SunRay(new Vector2(39 * 96 * GameWorld.Scale, 14 * 96 * GameWorld.Scale));

            GameWorld.collisionObjects.Add(newSunRay2);
            GameWorld.gameObjects.Add(newSunRay2);

            GameObject newSunRay3 = new SunRay(new Vector2(23 * 96 * GameWorld.Scale, 14 * 96 * GameWorld.Scale));

            GameWorld.collisionObjects.Add(newSunRay3);
            GameWorld.gameObjects.Add(newSunRay3);

            GameObject newSunRay4 = new SunRay(new Vector2(30 * 96 * GameWorld.Scale, 17 * 96 * GameWorld.Scale));

            GameWorld.collisionObjects.Add(newSunRay4);
            GameWorld.gameObjects.Add(newSunRay4);



            GenerateLevel(new int[, ]
            {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 0, 0, 0, 1, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 0, 0, 0, 11, 0, 1, 1, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 10, 0, 11, 0, 12, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 13, 0, 14, 0, 15, 0, 4, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 0, 4, 4, 9, 9, 4, 4, 0, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 4, 0, 2, 4, 4, 2, 0, 4, 4, 0, 0, 4, 2, 1, 9, 1, 1, 0, 0, 4, 4, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 2, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 4, 4, 0, 0, 4, 2, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 4, 8, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 0, 0, 0, 0, 0, 4, 4, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 0, 9, 9, 0, 0, 4, 4, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 2, 4, 1, 0, 9, 9, 0, 0, 1, 1, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 0, 0, 0, 0, 0, 9, 9, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 7, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 0, 0, 0, 9, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 10 },
            }, new int[, ]
            {
                { 0, 0, 0, 0, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 4, 4, 4, 1, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 4, 4, 4, 0, 4, 2, 2, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 4, 4, 4, 1, 4, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 4, 4, 4, 4, 4, 5, 5, 4, 4, 2, 2, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 5, 5, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 1, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 5, 5, 4, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 1 },
                { 0, 0, 0, 0, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 4, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 3, 3, 1, 1, 1 },
                { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 9, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 9, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 7, 7, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 9, 9, 6, 6, 1, 1, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 0, 0, 6, 6, 0, 0, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 6, 6, 7, 7, 1, 6, 0, 0, 6, 6, 9, 9, 6, 6, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 7, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 0, 0, 0, 9, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 },
            },
                          96 * GameWorld.Scale);
        }