Ejemplo n.º 1
0
 public void Draw(SpriteBatch spriteBatch, Camera camera, Renderer renderer)
 {
     foreach (var back in backgrounds)
     {
         back.Draw(spriteBatch, camera);
     }
     {
         var i = BackgroundTiles.GetEnumerator();
         while (i.MoveNext())
         {
             KeyValuePair <Point, Tile> curTile = i.Current;
             curTile.Value.Draw(curTile.Key, camera, spriteBatch, renderer);
         }
     }
     {
         var i = MidTiles.GetEnumerator();
         while (i.MoveNext())
         {
             KeyValuePair <Point, Tile> curTile = i.Current;
             curTile.Value.Draw(curTile.Key, camera, spriteBatch, renderer);
         }
     }
     foreach (Entity entity in Entities)
     {
         entity.Draw(camera, spriteBatch, renderer);
     }
     foreach (Particle particle in Particles)
     {
         particle.Draw(camera, spriteBatch);
     }
     {
         var i = ForegroundTiles.GetEnumerator();
         while (i.MoveNext())
         {
             KeyValuePair <Point, Tile> curTile = i.Current;
             curTile.Value.Draw(curTile.Key, camera, spriteBatch, renderer);
         }
     }
     foreach (var fore in foregrounds)
     {
         fore.Draw(spriteBatch, camera);
     }
 }
        private static void LevelLoader_LoadingThread(On.Celeste.LevelLoader.orig_LoadingThread orig, LevelLoader self)
        {
            orig(self);
            MapData mapData = self.Level.Session.MapData;

            var controllers = from level in mapData.Levels
                              from entity in level.Entities
                              where entity.Name == "FancyTileEntities/TileSeedController"
                              select new { entity, level };

            Rectangle       mapTileBounds = mapData.TileBounds;
            SolidTiles      fgTiles       = self.Level.SolidTiles;
            BackgroundTiles bgTiles       = self.Level.BgTiles;

            Regex regex = new Regex("\\r\\n|\\n\\r|\\n|\\r");

            Autotiler.Behaviour behaviour = new Autotiler.Behaviour {
                EdgesExtend             = true,
                EdgesIgnoreOutOfLevel   = false,
                PaddingIgnoreOutOfLevel = true
            };

            foreach (var controller in controllers)
            {
                EntityData data  = controller.entity;
                LevelData  level = controller.level;

                int randomSeed = data.Int("randomSeed", 42);

                Rectangle bounds     = level.TileBounds;
                Rectangle tileBounds = self.Level.Session.MapData.TileBounds;

                if (data.Bool("fg", true))
                {
                    VirtualMap <char> map = new VirtualMap <char>(bounds.Width, bounds.Height, '0');

                    string[] array = regex.Split(level.Solids);
                    for (int y = 0; y < array.Length; y++)
                    {
                        for (int x = 0; x < array[y].Length; x++)
                        {
                            map[x, y] = array[y][x];
                        }
                    }

                    Calc.PushRandom(randomSeed);
                    Autotiler.Generated gen = Extensions.GenerateOverlay(GFX.FGAutotiler, map, bounds.X - tileBounds.Left, bounds.Y - tileBounds.Top, self.Level.SolidsData, behaviour);
                    Calc.PopRandom();

                    int left = bounds.Left;
                    int top  = bounds.Top;
                    for (int y = top; y < top + array.Length; y++)
                    {
                        for (int x = left; x < left + array[y - top].Length; x++)
                        {
                            fgTiles.Tiles.Tiles[x - mapTileBounds.Left, y - mapTileBounds.Top] = gen.TileGrid.Tiles[x - left, y - top];
                        }
                    }
                }

                if (data.Bool("bg", true))
                {
                    VirtualMap <char> map = new VirtualMap <char>(bounds.Width, bounds.Height, '0');

                    string[] array = regex.Split(level.Bg);
                    for (int y = 0; y < array.Length; y++)
                    {
                        for (int x = 0; x < array[y].Length; x++)
                        {
                            map[x, y] = array[y][x];
                        }
                    }

                    Calc.PushRandom(randomSeed);
                    Autotiler.Generated gen = Extensions.GenerateOverlay(GFX.BGAutotiler, map, bounds.X - tileBounds.Left, bounds.Y - tileBounds.Top, self.Level.BgData, behaviour);
                    Calc.PopRandom();

                    int left = bounds.Left;
                    int top  = bounds.Top;
                    for (int y = top; y < top + array.Length; y++)
                    {
                        for (int x = left; x < left + array[y - top].Length; x++)
                        {
                            bgTiles.Tiles.Tiles[x - mapTileBounds.Left, y - mapTileBounds.Top] = gen.TileGrid.Tiles[x - left, y - top];
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Player LoadLevel(string path)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(path + ".oel");
            var levelExtraXml = new XmlDocument();

            levelExtraXml.Load(path + ".extra");
            XmlNode offsetNode = levelExtraXml.DocumentElement.GetElementsByTagName("offset")[0];
            int     levelxoff  = Convert.ToInt32(offsetNode.Attributes["x"].Value);
            int     levelyoff  = Convert.ToInt32(offsetNode.Attributes["y"].Value);

            foreach (XmlNode xmlNode in levelExtraXml.DocumentElement.GetElementsByTagName("backgrounds")[0].ChildNodes)
            {
                if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "background")
                {
                    string image_key = xmlNode.Attributes["image"].Value;
                    float  xrate     = Convert.ToSingle(xmlNode.Attributes["xrate"].Value);
                    float  yrate     = Convert.ToSingle(xmlNode.Attributes["yrate"].Value);
                    float  xoff      = Convert.ToSingle(xmlNode.Attributes["xoff"].Value);
                    float  yoff      = Convert.ToSingle(xmlNode.Attributes["yoff"].Value);
                    bool   xloops    = Convert.ToBoolean(xmlNode.Attributes["xloops"].Value);
                    bool   yloops    = Convert.ToBoolean(xmlNode.Attributes["yloops"].Value);
                    backgrounds.Add(new Background(Images.GetImage(image_key), xrate, yrate, xoff, yoff, xloops, yloops));
                }
            }
            {
                XmlNode tileLayerNode = xmlDocument.DocumentElement.GetElementsByTagName("back_tile_layer")[0];
                string  tileSheetKey  = tileLayerNode.Attributes["tileset"].Value;
                foreach (XmlNode xmlNode in tileLayerNode.ChildNodes)
                {
                    if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "tile")
                    {
                        int x  = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff;
                        int y  = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff;
                        int tx = Convert.ToInt32(xmlNode.Attributes["tx"].Value);
                        int ty = Convert.ToInt32(xmlNode.Attributes["ty"].Value);
                        BackgroundTiles.Add(new Point(x, y), new Tile(Tile.TileType.Air, tx, ty, tileSheetKey));
                    }
                }
            }
            {
                XmlNode tileLayerNode = xmlDocument.DocumentElement.GetElementsByTagName("func_tile_layer")[0];
                string  tileSheetKey  = tileLayerNode.Attributes["tileset"].Value;
                foreach (XmlNode xmlNode in tileLayerNode.ChildNodes)
                {
                    if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "tile")
                    {
                        int x  = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff;
                        int y  = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff;
                        int id = Convert.ToInt32(xmlNode.Attributes["id"].Value);
                        Tiles.Add(new Point(x, y), new Tile((Tile.TileType)id, id, 0, tileSheetKey));
                    }
                }
            }
            {
                XmlNode tileLayerNode = xmlDocument.DocumentElement.GetElementsByTagName("tile_layer")[0];
                string  tileSheetKey  = tileLayerNode.Attributes["tileset"].Value;
                foreach (XmlNode xmlNode in tileLayerNode.ChildNodes)
                {
                    if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "tile")
                    {
                        int x  = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff;
                        int y  = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff;
                        int tx = Convert.ToInt32(xmlNode.Attributes["tx"].Value);
                        int ty = Convert.ToInt32(xmlNode.Attributes["ty"].Value);
                        MidTiles.Add(new Point(x, y), new Tile(Tile.TileType.Air, tx, ty, tileSheetKey));
                    }
                }
            }
            {
                XmlNode tileLayerNode = xmlDocument.DocumentElement.GetElementsByTagName("fore_tile_layer")[0];
                string  tileSheetKey  = tileLayerNode.Attributes["tileset"].Value;
                foreach (XmlNode xmlNode in tileLayerNode.ChildNodes)
                {
                    if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "tile")
                    {
                        int x  = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff;
                        int y  = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff;
                        int tx = Convert.ToInt32(xmlNode.Attributes["tx"].Value);
                        int ty = Convert.ToInt32(xmlNode.Attributes["ty"].Value);
                        ForegroundTiles.Add(new Point(x, y), new Tile(Tile.TileType.Air, tx, ty, tileSheetKey));
                    }
                }
            }

            foreach (XmlNode xmlNode in xmlDocument.DocumentElement.GetElementsByTagName("entities")[0].ChildNodes)
            {
                if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "Player")
                {
                    int x  = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff * Tile.Width;
                    int y  = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff * Tile.Width;
                    int id = Convert.ToInt32(xmlNode.Attributes["id"].Value);
                    player     = new Player(this);
                    player.Pos = new Vector2(x, y);
                    Entities.Add(player);
                }
                else if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "ShellyEnemy")
                {
                    float       x         = float.Parse(xmlNode.Attributes["x"].Value) + levelxoff * Tile.Width;
                    float       y         = float.Parse(xmlNode.Attributes["y"].Value) + levelyoff * Tile.Width;
                    float       patrolPt1 = float.Parse(xmlNode.Attributes["patrolPt1"].Value) + levelxoff * Tile.Width;
                    float       patrolPt2 = float.Parse(xmlNode.Attributes["patrolPt2"].Value) + levelyoff * Tile.Width;
                    ShellyEnemy enemy     = new ShellyEnemy(this, new Vector2(patrolPt1, y), new Vector2(patrolPt2, y));
                    enemy.Pos = new Vector2(x, y);
                    Entities.Add(enemy);
                }
                else if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "BasicSword")
                {
                    int        x    = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff * Tile.Width;
                    int        y    = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff * Tile.Width;
                    ItemEntity item = new ItemEntity(new BasicSword(), this, Images.GetImage("basic_sword"), 32, 32, 0);
                    item.Pos = new Vector2(x, y);
                    Entities.Add(item);
                }
                else if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "BeachWitchNpc")
                {
                    int           x     = Convert.ToInt32(xmlNode.Attributes["x"].Value) + levelxoff * Tile.Width;
                    int           y     = Convert.ToInt32(xmlNode.Attributes["y"].Value) + levelyoff * Tile.Width;
                    BeachWitchNpc witch = new BeachWitchNpc(this, new Sprite(Images.GetImage("beach_witch_npc"), 64, 64, Consts.PlayerAnimFrameLength));
                    witch.Pos = new Vector2(x, y);
                    Entities.Add(witch);
                }
            }
            foreach (XmlNode xmlNode in levelExtraXml.DocumentElement.GetElementsByTagName("foregrounds")[0].ChildNodes)
            {
                if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == "background")
                {
                    string image_key = xmlNode.Attributes["image"].Value;
                    float  xrate     = Convert.ToSingle(xmlNode.Attributes["xrate"].Value);
                    float  yrate     = Convert.ToSingle(xmlNode.Attributes["yrate"].Value);
                    float  xoff      = Convert.ToSingle(xmlNode.Attributes["xoff"].Value);
                    float  yoff      = Convert.ToSingle(xmlNode.Attributes["yoff"].Value);
                    bool   xloops    = Convert.ToBoolean(xmlNode.Attributes["xloops"].Value);
                    bool   yloops    = Convert.ToBoolean(xmlNode.Attributes["yloops"].Value);
                    foregrounds.Add(new Background(Images.GetImage(image_key), xrate, yrate, xoff, yoff, xloops, yloops));
                }
            }
            MediaPlayer.Play(Music.Back);
            return(player);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        {
            this.Exit();
        }
        if (player.isDead == true)
        {
            RunningState.setScore(player.score);
            this.Exit();
            RunningState.set_state(3);
        }

        timeSinceScore += (float)gameTime.ElapsedGameTime.TotalSeconds;

        if (timeSinceScore > 2f)
        {
            player.score  += 100;
            timeSinceScore = 0f;
        }



        input.Update();
        player.Update(gameTime);
        enemy.Update(gameTime);
        UpdateBullets();

        if ((input.IsKeyDown(Keys.Z)))
        {
            player.spriteManager.setCurrentAction("shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Z)) && (input.IsKeyDown(Keys.Left)))
        {
            player.spriteManager.setCurrentAction("run+shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                player.velocity.X = -5 * player.speed;
                player.spriteManager.setCurrentDirection("left");
                player.isLeft = true;
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Z)) && (input.IsKeyDown(Keys.Right)))
        {
            player.spriteManager.setCurrentAction("run+shoot");
            if (input.WasKeyPressed(Keys.Z))
            {
                player.velocity.X = 5 * player.speed;
                player.spriteManager.setCurrentDirection("right");
                player.isLeft = false;
                Shoot();
            }
        }

        else if ((input.IsKeyDown(Keys.Space)))
        {
            player.spriteManager.setCurrentAction("jump");
            if (player.hasJumped == false)
            {
                player.position.Y -= 10f;
                player.velocity.Y  = -9;
                player.hasJumped   = true;
            }
        }

        else if ((input.IsKeyDown(Keys.Left)) && (input.IsKeyDown(Keys.Down)))
        {
            player.velocity.X = -5 * player.speed;
            player.spriteManager.setCurrentDirection("left");
            player.spriteManager.setCurrentAction("slide");
            player.isLeft = true;
        }

        else if ((input.IsKeyDown(Keys.Right)) && (input.IsKeyDown(Keys.Down)))
        {
            player.velocity.X = 5 * player.speed;
            player.spriteManager.setCurrentDirection("right");
            player.spriteManager.setCurrentAction("slide");
            player.isLeft = false;
        }

        else if (input.IsKeyDown(Keys.Left))
        {
            player.velocity.X = -5 * player.speed;
            player.spriteManager.setCurrentDirection("left");
            player.spriteManager.setCurrentAction("run");
            player.isLeft = true;
        }

        else if (input.IsKeyDown(Keys.Right))
        {
            player.velocity.X = 5 * player.speed;
            player.spriteManager.setCurrentDirection("right");
            player.spriteManager.setCurrentAction("run");
            player.isLeft = false;
        }


        else
        {
            player.velocity.X = 0;
            player.spriteManager.setCurrentAction("idle");
        }


        foreach (PlatformTiles tile in map.CollisionTiles)
        {
            player.PlatformCollsion(tile.Rectangle, map.Width, map.Height, camera.bottom_edge, camera.top_edge);
            enemy.Collision(tile.Rectangle, map.Width, map.Height);
            camera.Update(player.position, map.Width, map.Height, gameTime, player);
        }

        //for (int j = 0; j < bullets.Count; j++)
        //{
        //    if (bullets[j].TrapCollsion(bullets[j].rectangle, map.Width, map.Height, map.TrapTiles[j]))
        //    {
        //        BackgroundTiles newTile = new BackgroundTiles("0", map.TrapTiles[j].Rectangle);
        //        map.TrapTiles.RemoveAt(j);
        //        map.BackgroundTiles.Insert(j+1, newTile);

        //    }

        //}
        for (int i = 0; i < map.TrapTiles.Count; i++)
        {
            player.TrapCollsion(map.TrapTiles[i].Rectangle, map.Width, map.Height);
            foreach (Bullet bullet in bullets)
            {
                bullet.TrapCollsion(map.TrapTiles[i].Rectangle, map.Width, map.Height, map.TrapTiles[i], player);
            }
        }

        for (int i = 0; i < map.TrapTiles.Count; i++)
        {
            if (map.TrapTiles[i].isVisible == false)
            {
                BackgroundTiles newTile = new BackgroundTiles("0", map.TrapTiles[i].Rectangle);
                map.TrapTiles.RemoveAt(i);
                map.BackgroundTiles.Insert(i, newTile);
            }
        }



        base.Update(gameTime);
    }
Ejemplo n.º 5
0
    void Start()
    {
        //读取配置文件
        Gfx.Game = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Gameplay"), Atlas.AtlasDataFormat.Packer);
        Gfx.Misc = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Misc"), Atlas.AtlasDataFormat.PackerNoAtlas);

        Gfx.SceneryTiles = new Tileset(Gfx.Game["tilesets/scenery"], 8, 8);
        //读取前景配置文件
        Gfx.BGAutotiler = new Autotiler(Path.Combine("Graphics", "BackgroundTiles.xml"));
        Gfx.FGAutotiler = new Autotiler(Path.Combine("Graphics", "ForegroundTiles.xml"));

        Debug.Log("==加载AreaData文件");
        SaveData.Start(new SaveData
        {
            Name        = "test001",
            AssistMode  = true,
            VariantMode = true
        }, 0);
        //加载区域
        AreaData.Load();

        Debug.Log("==创建Session,读取关卡地图");

        Session session = new Session(new AreaKey(0, AreaMode.Normal), null, null);

        MapData   mapData   = session.MapData;
        LevelData levelData = mapData.Levels[0];

        Debug.Log(levelData);

        Rectangle         tileBounds1 = mapData.TileBounds;
        VirtualMap <char> data1       = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
        VirtualMap <char> data2       = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
        VirtualMap <bool> virtualMap  = new VirtualMap <bool>(tileBounds1.Width, tileBounds1.Height, false);
        Regex             regex       = new Regex("\\r\\n|\\n\\r|\\n|\\r");

        foreach (LevelData level in mapData.Levels)
        {
            Rectangle tileBounds2 = level.TileBounds;
            int       left1       = tileBounds2.Left;
            tileBounds2 = level.TileBounds;
            int      top1      = tileBounds2.Top;
            string[] strArray1 = regex.Split(level.Bg);
            for (int index1 = top1; index1 < top1 + strArray1.Length; ++index1)
            {
                for (int index2 = left1; index2 < left1 + strArray1[index1 - top1].Length; ++index2)
                {
                    data1[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray1[index1 - top1][index2 - left1];
                }
            }

            string[] strArray2 = regex.Split(level.Solids);
            for (int index1 = top1; index1 < top1 + strArray2.Length; ++index1)
            {
                for (int index2 = left1; index2 < left1 + strArray2[index1 - top1].Length; ++index2)
                {
                    data2[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray2[index1 - top1][index2 - left1];
                }
            }
            tileBounds2 = level.TileBounds;
            int left2 = tileBounds2.Left;
            while (true)
            {
                int num1 = left2;
                tileBounds2 = level.TileBounds;
                int right = tileBounds2.Right;
                if (num1 < right)
                {
                    tileBounds2 = level.TileBounds;
                    int top2 = tileBounds2.Top;
                    while (true)
                    {
                        int num2 = top2;
                        tileBounds2 = level.TileBounds;
                        int bottom = tileBounds2.Bottom;
                        if (num2 < bottom)
                        {
                            virtualMap[left2 - tileBounds1.Left, top2 - tileBounds1.Top] = true;
                            ++top2;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ++left2;
                }
                else
                {
                    break;
                }
            }
            Gfx.FGAutotiler.LevelBounds.Add(new Rectangle(level.TileBounds.X - tileBounds1.X, level.TileBounds.Y - tileBounds1.Y, level.TileBounds.Width, level.TileBounds.Height));
        }

        foreach (Rectangle rectangle in mapData.Filler)
        {
            for (int left = rectangle.Left; left < rectangle.Right; ++left)
            {
                for (int top = rectangle.Top; top < rectangle.Bottom; ++top)
                {
                    char ch1 = '0';
                    if (rectangle.Top - tileBounds1.Y > 0)
                    {
                        char ch2 = data2[left - tileBounds1.X, rectangle.Top - tileBounds1.Y - 1];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Left - tileBounds1.X > 0)
                    {
                        char ch2 = data2[rectangle.Left - tileBounds1.X - 1, top - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Right - tileBounds1.X < tileBounds1.Width - 1)
                    {
                        char ch2 = data2[rectangle.Right - tileBounds1.X, top - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0' && rectangle.Bottom - tileBounds1.Y < tileBounds1.Height - 1)
                    {
                        char ch2 = data2[left - tileBounds1.X, rectangle.Bottom - tileBounds1.Y];
                        if (ch2 != '0')
                        {
                            ch1 = ch2;
                        }
                    }
                    if (ch1 == '0')
                    {
                        ch1 = '1';
                    }
                    data2[left - tileBounds1.X, top - tileBounds1.Y]      = ch1;
                    virtualMap[left - tileBounds1.X, top - tileBounds1.Y] = true;
                }
            }
        }
        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_85:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left1       = tileBounds2.Left;
                while (true)
                {
                    int num1 = left1;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int  top = tileBounds2.Top;
                        char ch1 = data1[left1 - tileBounds1.X, top - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                        {
                            data1[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num2 = tileBounds2.Bottom - 1;
                        char ch2  = data1[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                        {
                            data1[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                        }
                        ++left1;
                    }
                    else
                    {
                        break;
                    }
                }
                tileBounds2 = current.TileBounds;
                int num3 = tileBounds2.Top - 4;
                while (true)
                {
                    int num1 = num3;
                    tileBounds2 = current.TileBounds;
                    int num2 = tileBounds2.Bottom + 4;
                    if (num1 < num2)
                    {
                        tileBounds2 = current.TileBounds;
                        int  left2 = tileBounds2.Left;
                        char ch1   = data1[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                        {
                            data1[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num4 = tileBounds2.Right - 1;
                        char ch2  = data1[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                        {
                            data1[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                        }
                        ++num3;
                    }
                    else
                    {
                        goto label_85;
                    }
                }
            }
        }

        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_100:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left        = tileBounds2.Left;
                while (true)
                {
                    int num1 = left;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int top = tileBounds2.Top;
                        if (data2[left - tileBounds1.X, top - tileBounds1.Y] == '0')
                        {
                            for (int index = 1; index < 8; ++index)
                            {
                                virtualMap[left - tileBounds1.X, top - tileBounds1.Y - index] = true;
                            }
                        }
                        tileBounds2 = current.TileBounds;
                        int num2 = tileBounds2.Bottom - 1;
                        if (data2[left - tileBounds1.X, num2 - tileBounds1.Y] == '0')
                        {
                            for (int index = 1; index < 8; ++index)
                            {
                                virtualMap[left - tileBounds1.X, num2 - tileBounds1.Y + index] = true;
                            }
                        }
                        ++left;
                    }
                    else
                    {
                        goto label_100;
                    }
                }
            }
        }
        using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
        {
label_122:
            while (enumerator.MoveNext())
            {
                LevelData current     = enumerator.Current;
                Rectangle tileBounds2 = current.TileBounds;
                int       left1       = tileBounds2.Left;
                while (true)
                {
                    int num1 = left1;
                    tileBounds2 = current.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = current.TileBounds;
                        int  top = tileBounds2.Top;
                        char ch1 = data2[left1 - tileBounds1.X, top - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                        {
                            data2[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num2 = tileBounds2.Bottom - 1;
                        char ch2  = data2[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                        {
                            data2[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                        }
                        ++left1;
                    }
                    else
                    {
                        break;
                    }
                }
                tileBounds2 = current.TileBounds;
                int num3 = tileBounds2.Top - 4;
                while (true)
                {
                    int num1 = num3;
                    tileBounds2 = current.TileBounds;
                    int num2 = tileBounds2.Bottom + 4;
                    if (num1 < num2)
                    {
                        tileBounds2 = current.TileBounds;
                        int  left2 = tileBounds2.Left;
                        char ch1   = data2[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                        {
                            data2[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                        }
                        tileBounds2 = current.TileBounds;
                        int  num4 = tileBounds2.Right - 1;
                        char ch2  = data2[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                        for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                        {
                            data2[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                        }
                        ++num3;
                    }
                    else
                    {
                        goto label_122;
                    }
                }
            }
        }
        Vector2         position        = new Vector2((float)tileBounds1.X, (float)tileBounds1.Y) * 8f;
        BackgroundTiles backgroundTiles = new BackgroundTiles(position, data1);


        //MTexture mTexture = Gfx.Game["tilesets/dirt"];
        //草地等等
        //MTexture mTexture = Gfx.Game["tilesets/scenery"];
        //StartCoroutine(DrawTiles(backgroundTiles.Tiles, Vector3.zero));


        /////////////////////////////////////////////////////
        ///构建BgTiles
        /////////////////////////////////////////////////////
        int  l8     = levelData.TileBounds.Left;
        int  t8     = levelData.TileBounds.Top;
        int  w8     = levelData.TileBounds.Width;
        int  h8     = levelData.TileBounds.Height;
        bool flag14 = !string.IsNullOrEmpty(levelData.BgTiles);

        if (flag14)
        {
            int[,] tiles = Util.ReadCSVIntGrid(levelData.BgTiles, w8, h8);
            backgroundTiles.Tiles.Overlay(Gfx.SceneryTiles, tiles, l8 - tileBounds1.X, t8 - tileBounds1.Y);
        }

        //BackdropRenderer backgroundRenderer = new BackdropRenderer();
        //backgroundRenderer.Backdrops = mapData.CreateBackdrops(mapData.Background);

        //BackdropRenderer foregroundRenderer = new BackdropRenderer();
        //foregroundRenderer.Backdrops = mapData.CreateBackdrops(mapData.Foreground);
        //foreach(Backdrop backdrop in backgroundRenderer.Backdrops)
        //{
        //    if(backdrop is Parallax)
        //    {
        //        ShowSprite((backdrop as Parallax).Texture);
        //    }

        //}
        //StartCoroutine(DrawTiles(backgroundTiles.Tiles, Vector3.zero));



        //foreach (DecalData bgDecal in levelData.BgDecals)
        //{
        //    new Decal(bgDecal.Texture, Vector3.zero + bgDecal.Position, bgDecal.Scale, 9000);
        //}
    }
Ejemplo n.º 6
0
        //加载关卡数据
        private void LoadingThread()
        {
            //MapData表示整个地图的数据
            MapData mapData = this.session.MapData;

            AreaData areaData = AreaData.Get(this.session.Area.ID);

            //if (this.session.Area.ID == 0)
            //    SaveData.Instance.Assists.DashMode = Assists.DashModes.Normal;
            //this.Level.Add((Monocle.Renderer)(this.Level.Background = new BackdropRenderer()));
            //this.Level.Add((Entity)new DustEdges());
            //this.Level.Add((Entity)new WaterSurface());
            //this.Level.Add((Entity)new MirrorSurfaces());
            //this.Level.Add((Entity)new GlassBlockBg());
            //this.Level.Add((Entity)new LightningRenderer());
            //this.Level.Add((Entity)new SeekerBarrierRenderer());
            this.Level.Background           = new BackdropRenderer();
            this.Level.BackgroundColor      = mapData.BackgroundColor;
            this.Level.Background.Backdrops = mapData.CreateBackdrops(mapData.Background);
            foreach (Backdrop backdrop in this.Level.Background.Backdrops)
            {
                backdrop.Renderer = this.Level.Background;
            }
            //加载前景地图
            //this.Level.Foreground.Backdrops = mapData.CreateBackdrops(mapData.Foreground);
            //foreach (Backdrop backdrop in this.Level.Foreground.Backdrops)
            //{
            //    backdrop.Renderer = this.Level.Foreground;
            //}

            Rectangle tileBounds1 = mapData.TileBounds;

            Gfx.FGAutotiler.LevelBounds.Clear();
            VirtualMap <char> data1      = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
            VirtualMap <char> data2      = new VirtualMap <char>(tileBounds1.Width, tileBounds1.Height, '0');
            VirtualMap <bool> virtualMap = new VirtualMap <bool>(tileBounds1.Width, tileBounds1.Height, false);
            Regex             regex      = new Regex("\\r\\n|\\n\\r|\\n|\\r");

            foreach (LevelData level in mapData.Levels)
            {
                Rectangle tileBounds2 = level.TileBounds;
                int       left1       = tileBounds2.Left;
                tileBounds2 = level.TileBounds;
                int      top1      = tileBounds2.Top;
                string[] strArray1 = regex.Split(level.Bg);
                for (int index1 = top1; index1 < top1 + strArray1.Length; ++index1)
                {
                    for (int index2 = left1; index2 < left1 + strArray1[index1 - top1].Length; ++index2)
                    {
                        data1[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray1[index1 - top1][index2 - left1];
                    }
                }

                string[] strArray2 = regex.Split(level.Solids);
                for (int index1 = top1; index1 < top1 + strArray2.Length; ++index1)
                {
                    for (int index2 = left1; index2 < left1 + strArray2[index1 - top1].Length; ++index2)
                    {
                        data2[index2 - tileBounds1.X, index1 - tileBounds1.Y] = strArray2[index1 - top1][index2 - left1];
                    }
                }
                tileBounds2 = level.TileBounds;
                int left2 = tileBounds2.Left;
                while (true)
                {
                    int num1 = left2;
                    tileBounds2 = level.TileBounds;
                    int right = tileBounds2.Right;
                    if (num1 < right)
                    {
                        tileBounds2 = level.TileBounds;
                        int top2 = tileBounds2.Top;
                        while (true)
                        {
                            int num2 = top2;
                            tileBounds2 = level.TileBounds;
                            int bottom = tileBounds2.Bottom;
                            if (num2 < bottom)
                            {
                                virtualMap[left2 - tileBounds1.Left, top2 - tileBounds1.Top] = true;
                                ++top2;
                            }
                            else
                            {
                                break;
                            }
                        }
                        ++left2;
                    }
                    else
                    {
                        break;
                    }
                }
                Gfx.FGAutotiler.LevelBounds.Add(new Rectangle(level.TileBounds.X - tileBounds1.X, level.TileBounds.Y - tileBounds1.Y, level.TileBounds.Width, level.TileBounds.Height));
            }

            foreach (Rectangle rectangle in mapData.Filler)
            {
                for (int left = rectangle.Left; left < rectangle.Right; ++left)
                {
                    for (int top = rectangle.Top; top < rectangle.Bottom; ++top)
                    {
                        char ch1 = '0';
                        if (rectangle.Top - tileBounds1.Y > 0)
                        {
                            char ch2 = data2[left - tileBounds1.X, rectangle.Top - tileBounds1.Y - 1];
                            if (ch2 != '0')
                            {
                                ch1 = ch2;
                            }
                        }
                        if (ch1 == '0' && rectangle.Left - tileBounds1.X > 0)
                        {
                            char ch2 = data2[rectangle.Left - tileBounds1.X - 1, top - tileBounds1.Y];
                            if (ch2 != '0')
                            {
                                ch1 = ch2;
                            }
                        }
                        if (ch1 == '0' && rectangle.Right - tileBounds1.X < tileBounds1.Width - 1)
                        {
                            char ch2 = data2[rectangle.Right - tileBounds1.X, top - tileBounds1.Y];
                            if (ch2 != '0')
                            {
                                ch1 = ch2;
                            }
                        }
                        if (ch1 == '0' && rectangle.Bottom - tileBounds1.Y < tileBounds1.Height - 1)
                        {
                            char ch2 = data2[left - tileBounds1.X, rectangle.Bottom - tileBounds1.Y];
                            if (ch2 != '0')
                            {
                                ch1 = ch2;
                            }
                        }
                        if (ch1 == '0')
                        {
                            ch1 = '1';
                        }
                        data2[left - tileBounds1.X, top - tileBounds1.Y]      = ch1;
                        virtualMap[left - tileBounds1.X, top - tileBounds1.Y] = true;
                    }
                }
            }
            using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
            {
label_85:
                while (enumerator.MoveNext())
                {
                    LevelData current     = enumerator.Current;
                    Rectangle tileBounds2 = current.TileBounds;
                    int       left1       = tileBounds2.Left;
                    while (true)
                    {
                        int num1 = left1;
                        tileBounds2 = current.TileBounds;
                        int right = tileBounds2.Right;
                        if (num1 < right)
                        {
                            tileBounds2 = current.TileBounds;
                            int  top = tileBounds2.Top;
                            char ch1 = data1[left1 - tileBounds1.X, top - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                            {
                                data1[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                            }
                            tileBounds2 = current.TileBounds;
                            int  num2 = tileBounds2.Bottom - 1;
                            char ch2  = data1[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                            {
                                data1[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                            }
                            ++left1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    tileBounds2 = current.TileBounds;
                    int num3 = tileBounds2.Top - 4;
                    while (true)
                    {
                        int num1 = num3;
                        tileBounds2 = current.TileBounds;
                        int num2 = tileBounds2.Bottom + 4;
                        if (num1 < num2)
                        {
                            tileBounds2 = current.TileBounds;
                            int  left2 = tileBounds2.Left;
                            char ch1   = data1[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                            {
                                data1[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                            }
                            tileBounds2 = current.TileBounds;
                            int  num4 = tileBounds2.Right - 1;
                            char ch2  = data1[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                            {
                                data1[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                            }
                            ++num3;
                        }
                        else
                        {
                            goto label_85;
                        }
                    }
                }
            }
            using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
            {
label_100:
                while (enumerator.MoveNext())
                {
                    LevelData current     = enumerator.Current;
                    Rectangle tileBounds2 = current.TileBounds;
                    int       left        = tileBounds2.Left;
                    while (true)
                    {
                        int num1 = left;
                        tileBounds2 = current.TileBounds;
                        int right = tileBounds2.Right;
                        if (num1 < right)
                        {
                            tileBounds2 = current.TileBounds;
                            int top = tileBounds2.Top;
                            if (data2[left - tileBounds1.X, top - tileBounds1.Y] == '0')
                            {
                                for (int index = 1; index < 8; ++index)
                                {
                                    virtualMap[left - tileBounds1.X, top - tileBounds1.Y - index] = true;
                                }
                            }
                            tileBounds2 = current.TileBounds;
                            int num2 = tileBounds2.Bottom - 1;
                            if (data2[left - tileBounds1.X, num2 - tileBounds1.Y] == '0')
                            {
                                for (int index = 1; index < 8; ++index)
                                {
                                    virtualMap[left - tileBounds1.X, num2 - tileBounds1.Y + index] = true;
                                }
                            }
                            ++left;
                        }
                        else
                        {
                            goto label_100;
                        }
                    }
                }
            }
            using (List <LevelData> .Enumerator enumerator = mapData.Levels.GetEnumerator())
            {
label_122:
                while (enumerator.MoveNext())
                {
                    LevelData current     = enumerator.Current;
                    Rectangle tileBounds2 = current.TileBounds;
                    int       left1       = tileBounds2.Left;
                    while (true)
                    {
                        int num1 = left1;
                        tileBounds2 = current.TileBounds;
                        int right = tileBounds2.Right;
                        if (num1 < right)
                        {
                            tileBounds2 = current.TileBounds;
                            int  top = tileBounds2.Top;
                            char ch1 = data2[left1 - tileBounds1.X, top - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, top - tileBounds1.Y - index]; ++index)
                            {
                                data2[left1 - tileBounds1.X, top - tileBounds1.Y - index] = ch1;
                            }
                            tileBounds2 = current.TileBounds;
                            int  num2 = tileBounds2.Bottom - 1;
                            char ch2  = data2[left1 - tileBounds1.X, num2 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left1 - tileBounds1.X, num2 - tileBounds1.Y + index]; ++index)
                            {
                                data2[left1 - tileBounds1.X, num2 - tileBounds1.Y + index] = ch2;
                            }
                            ++left1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    tileBounds2 = current.TileBounds;
                    int num3 = tileBounds2.Top - 4;
                    while (true)
                    {
                        int num1 = num3;
                        tileBounds2 = current.TileBounds;
                        int num2 = tileBounds2.Bottom + 4;
                        if (num1 < num2)
                        {
                            tileBounds2 = current.TileBounds;
                            int  left2 = tileBounds2.Left;
                            char ch1   = data2[left2 - tileBounds1.X, num3 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[left2 - tileBounds1.X - index, num3 - tileBounds1.Y]; ++index)
                            {
                                data2[left2 - tileBounds1.X - index, num3 - tileBounds1.Y] = ch1;
                            }
                            tileBounds2 = current.TileBounds;
                            int  num4 = tileBounds2.Right - 1;
                            char ch2  = data2[num4 - tileBounds1.X, num3 - tileBounds1.Y];
                            for (int index = 1; index < 4 && !virtualMap[num4 - tileBounds1.X + index, num3 - tileBounds1.Y]; ++index)
                            {
                                data2[num4 - tileBounds1.X + index, num3 - tileBounds1.Y] = ch2;
                            }
                            ++num3;
                        }
                        else
                        {
                            goto label_122;
                        }
                    }
                }
            }
            Vector2 position = new Vector2((float)tileBounds1.X, (float)tileBounds1.Y) * 8f;

            RandomUtil.PushRandom(mapData.LoadSeed);
            Level           level1 = this.Level;
            Level           level2 = this.Level;
            BackgroundTiles backgroundTiles1;
            BackgroundTiles backgroundTiles2 = backgroundTiles1 = new BackgroundTiles(position, data1);

            //BackgroundTiles backgroundTiles3 = backgroundTiles1;
            level2.BgTiles = backgroundTiles1;
            //BackgroundTiles backgroundTiles4 = backgroundTiles3;
            //level2.BgTiles = backgroundTiles4;
            //level1.Add((Entity)backgroundTiles4);
            //Level level3 = this.Level;
            //Level level4 = this.Level;
            solidTiles = new SolidTiles(position, data2);
            //level3.Add((Entity)solidTiles4);
            //this.Level.BgData = data1;
            //this.Level.SolidsData = data2;
            RandomUtil.PopRandom();
            //this.Level.FgTilesLightMask = new TileGrid(8, 8, tileBounds1.Width, tileBounds1.Height);
            //this.Level.FgTilesLightMask.Color = Color.black;
            //foreach (LevelData level5 in mapData.Levels)
            //{
            //    int left = level5.TileBounds.Left;
            //    int top = level5.TileBounds.Top;
            //    int width = level5.TileBounds.Width;
            //    int height = level5.TileBounds.Height;
            //    if (!string.IsNullOrEmpty(level5.BgTiles))
            //    {
            //        int[,] tiles = Util.ReadCSVIntGrid(level5.BgTiles, width, height);
            //        backgroundTiles2.Tiles.Overlay(Gfx.SceneryTiles, tiles, left - tileBounds1.X, top - tileBounds1.Y);
            //    }
            //    if (!string.IsNullOrEmpty(level5.FgTiles))
            //    {
            //        int[,] tiles = Util.ReadCSVIntGrid(level5.FgTiles, width, height);
            //        solidTiles.Tiles.Overlay(Gfx.SceneryTiles, tiles, left - tileBounds1.X, top - tileBounds1.Y);
            //        this.Level.FgTilesLightMask.Overlay(Gfx.SceneryTiles, tiles, left - tileBounds1.X, top - tileBounds1.Y);
            //    }
            //}
            //if (areaData.OnLevelBegin != null)
            //    areaData.OnLevelBegin(this.Level);
            //this.Level.StartPosition = this.startPosition;
            //this.Level.Pathfinder = new Pathfinder(this.Level);
            //this.Loaded = true;
        }