예제 #1
0
        public bool LoadMap(string filename, bool loadTiles, bool loadObjects)
        {
            this.mapFilename = filename.Substring(filename.LastIndexOf('\\') + 1);
            if (GameEngine.Framework.UsingExternalMaps)
            {
                filename = GameEngine.Framework.GetMapFolder() + this.mapFilename;
            }
            else
            {
                filename = "Maps." + filename.ToLower();
            }
            string tileSet = "";
            this.yOffset = 0;
            this.alternatePalette = false;
            int fromIndex = 0;
            string[] lines = GameEngine.ReadTextFile(filename, !GameEngine.Framework.UsingExternalMaps, !GameEngine.Framework.UsingExternalMaps);
            if (lines == null)
            {
                return false;
            }
            if (loadObjects)
            {
                this.objects.Clear();
                this.gameObjects.Clear();
                this.doors.Clear();
                this.objects.Add(this.player);
                this.gameObjects.Add(this.player);
            }
            GameEngine.Game.BaseDifficulty = 1;
            string[] strArray2 = GameEngine.GetSaveFileSegment(lines, "LEVELDATA", 0);
            foreach (string str2 in strArray2)
            {
                string[] strArray3 = str2.Split(new char[] { '=' });
                switch (strArray3[0])
                {
                    case "alternatePalette":
                        this.alternatePalette = bool.Parse(strArray3[1]);
                        goto Label_0357;

                    case "tileset":
                        tileSet = strArray3[1];
                        if (!this.alternatePalette)
                        {
                            goto Label_024E;
                        }
                        if (this.mapFilename.IndexOf("SKYDUNGEON") != 0)
                        {
                            break;
                        }
                        this.tileTexture = new GameTexture(tileSet + ".bmp", TileSize, ColorSwaps.SkyNormal, ColorSwaps.SkyAlternate, TextureDisposePolicy.DisposeOnTileChange);
                        goto Label_0357;

                    case "music":
                        this.song = Utility.ParseSongString(strArray3[1]);
                        GameEngine.Framework.PlayMusic(this.song);
                        goto Label_0357;

                    case "skycolor":
                    {
                        string[] strArray4 = strArray3[1].Split(new char[] { ',' });
                        base.BackColor = Color.FromArgb(0xff, int.Parse(strArray4[0]), int.Parse(strArray4[1]), int.Parse(strArray4[2]));
                        this.skyColor = base.BackColor;
                        goto Label_0357;
                    }
                    case "liquid":
                        if (!strArray3[1].Equals(SurfaceType.LavaSurface.ToString()))
                        {
                            goto Label_0306;
                        }
                        this.liquidSurface = SurfaceType.LavaSurface;
                        goto Label_0357;

                    case "tremor":
                        this.castleTremor = bool.Parse(strArray3[1]);
                        if (this.castleTremor)
                        {
                            this.flashColor = Color.Red;
                        }
                        goto Label_0357;

                    case "mapdifficulty":
                        GameEngine.Game.BaseDifficulty = int.Parse(strArray3[1]);
                        goto Label_0357;

                    case "yoffset":
                        this.yOffset = int.Parse(strArray3[1]);
                        goto Label_0357;

                    default:
                        goto Label_0357;
                }
                this.tileTexture = new GameTexture(tileSet + ".bmp", TileSize, ColorSwaps.CaveNormal, ColorSwaps.CaveAlternate, TextureDisposePolicy.DisposeOnTileChange);
                goto Label_0357;
            Label_024E:
                this.tileTexture = new GameTexture(tileSet + ".bmp", TileSize, TextureDisposePolicy.DisposeOnTileChange);
                goto Label_0357;
            Label_0306:
                this.liquidSurface = SurfaceType.WaterSurface;
            Label_0357:;
            }
            if (loadTiles)
            {
                fromIndex += strArray2.Length;
                string[] strArray5 = GameEngine.GetSaveFileSegment(lines, "MAP", fromIndex);
                fromIndex += strArray5.Length;
                string[] strArray6 = GameEngine.GetSaveFileSegment(lines, "MAP", fromIndex);
                fromIndex += strArray6.Length;
                string[] foredata = GameEngine.GetSaveFileSegment(lines, "MAP", fromIndex);
                this.tileMap = new TileMap(this.tileTexture, strArray5, strArray6, foredata);
            }
            if (loadObjects)
            {
                string[] strArray9 = GameEngine.GetSaveFileSegment(lines, "OBJECTS", 0)[1].Split(new char[] { ';' });
                for (int i = 0; i < strArray9.Length; i++)
                {
                    string[] strArray10 = strArray9[i].Split(new char[] { ' ' });
                    if (strArray10.Length > 1)
                    {
                        if (strArray10[0].Equals("Door"))
                        {
                            Door item = new Door(int.Parse(strArray10[2]), Utility.ParseDoorTypeString(strArray10[5]), this.mapFilename);
                            Point point = Utility.ParsePointString(strArray10[1]);
                            item.Location = new PointF((float) point.X, (float) point.Y);
                            item.DestinationDoor = int.Parse(strArray10[3]);
                            item.DestinationMap = strArray10[4];
                            item.ObjClass = ObjectClass.Door;
                            if (strArray10.Length > 6)
                            {
                                item.IsWaterTransition = bool.Parse(strArray10[6]);
                            }
                            if (strArray10.Length > 7)
                            {
                                item.Flipped = bool.Parse(strArray10[7]);
                            }
                            this.objects.Insert(0, item);
                            this.doors.Add(item);
                        }
                        else if (strArray10[0].Equals("PrizeBlock"))
                        {
                            string str3 = "";
                            if (strArray10.Length > 2)
                            {
                                str3 = strArray10[2];
                            }
                            DragonTrap.PrizeBlock block = new DragonTrap.PrizeBlock(str3, this.mapFilename);
                            Point point2 = Utility.ParsePointString(strArray10[1]);
                            block.Location = new PointF((float) point2.X, (float) point2.Y);
                            this.objects.Add(block);
                        }
                        else if (strArray10[0].Equals("FallingBlock"))
                        {
                            FallingBlockTrigger playerOn = FallingBlockTrigger.PlayerOn;
                            if (strArray10[3].Equals("PlayerNear"))
                            {
                                playerOn = FallingBlockTrigger.PlayerNear;
                            }
                            if (strArray10[3].Equals("PlayerHit"))
                            {
                                playerOn = FallingBlockTrigger.PlayerHit;
                            }
                            if (strArray10[3].Equals("PlayerOn"))
                            {
                                playerOn = FallingBlockTrigger.PlayerOn;
                            }
                            FallingBlock block2 = new FallingBlock(this.mapFilename, playerOn, int.Parse(strArray10[2]));
                            Point point3 = Utility.ParsePointString(strArray10[1]);
                            block2.Location = new PointF((float) (point3.X * 0x10), (float) (point3.Y * 0x10));
                            this.objects.Add(block2);
                        }
                        else if (strArray10[0].Equals("Treasure"))
                        {
                            Point point4 = Utility.ParsePointString(strArray10[1]);
                            PointF tf = new PointF((float) point4.X, (float) point4.Y);
                            Direction left = Direction.Left;
                            if (strArray10.Length > 4)
                            {
                                left = Utility.ParseDirectionString(strArray10[4]);
                            }
                            TreasureChest chest = new TreasureChest(int.Parse(strArray10[2]), strArray10[3].Split(new char[] { ':' }), this.mapFilename, left) {
                                Location = tf
                            };
                            this.objects.Add(chest);
                        }
                        else if (strArray10[0].Equals("Generator"))
                        {
                            Point point5 = Utility.ParsePointString(strArray10[1]);
                            PointF tf2 = new PointF((float) point5.X, (float) point5.Y);
                            EnemyGenerator generator = new EnemyGenerator(Utility.ParseObjectTypeString(strArray10[2]), Utility.ParseColorSwapString(strArray10[3]), int.Parse(strArray10[4])) {
                                Location = tf2
                            };
                            this.objects.Add(generator);
                        }
                        else if (strArray10[0].Equals("ExplosionGenerator"))
                        {
                            Point point6 = Utility.ParsePointString(strArray10[1]);
                            PointF tf3 = new PointF((float) point6.X, (float) point6.Y);
                            ExplosionPoint point7 = new ExplosionPoint(100, 10) {
                                Location = tf3
                            };
                            this.objects.Add(point7);
                        }
                        else
                        {
                            ObjectType t = Utility.ParseObjectTypeString(strArray10[0]);
                            ColorSwaps normal = ColorSwaps.Normal;
                            int delay = 0;
                            if (strArray10.Length > 2)
                            {
                                normal = Utility.ParseColorSwapString(strArray10[2]);
                            }
                            if (strArray10.Length > 5)
                            {
                                delay = int.Parse(strArray10[5]);
                            }
                            GameObject obj2 = ObjectFactory.CreateObjectOfType(t, normal, Utility.ParseDirectionString(strArray10[3]), strArray10[4], delay);
                            Point point8 = Utility.ParsePointString(strArray10[1]);
                            obj2.Location = new PointF((float) point8.X, (float) point8.Y);
                            this.objects.Add(obj2);
                            this.gameObjects.Add(obj2);
                        }
                    }
                }
            }
            this.InitSpecialTiles(tileSet);
            if (!this.castleTremor)
            {
                if (this.mapFilename.ToUpper().Equals("SKYFALL.TXT"))
                {
                    this.tileMap.ScrollBackground = true;
                    this.castleTremor = true;
                    this.flashColor = Color.Black;
                    this.skyColor = Color.Black;
                }
                else
                {
                    this.castleTremor = false;
                    this.tileMap.ScrollBackground = false;
                }
            }
            return true;
        }
예제 #2
0
 public BaseObject AddEnemyGenerator(ObjectType type, ColorSwaps colorSwap, int delay)
 {
     EnemyGenerator item = new EnemyGenerator(type, colorSwap, delay) {
         Location = new PointF(this.screenPos.X + (GameEngine.ScreenWidth / 2), this.screenPos.Y + (GameEngine.ScreenHeight / 2))
     };
     this.objects.Add(item);
     return item;
 }