示例#1
0
        public void LoadWorld(int id)
        {
            Logger.Log("Loading world id " + id, true);

            //Clear ALL enemies/projectiles/tiles/etc
            entityLivings.Clear();
            tiles.Clear();

            if (id == 0)
            {
                player = Player.CreatePlayer(new Vector2(0, 0), 1);

                TileStatic.CreateTileStatic(new Rectangle(0, 0, 512, 512), Assets.tile_grass1, 0);
                TileStatic.CreateTileStatic(new Rectangle(512, 0, 64, 512), Assets.tile_rockwall, 4, true, Directions.West);
                TileStatic.CreateTileStatic(new Rectangle(0, 512, 512, 64), Assets.tile_rockwall, 4, true, Directions.North);
                TileStatic.CreateTileStatic(new Rectangle(512, 512, 64, 64), Assets.tile_rockwall, 4, true, Directions.NorthWest);
                //TileTrigger.CreateTileTrigger(new Rectangle(64, 0, 64, 64), true, 5, "<intro_3>");
                TileTrigger.CreateTileTriggerDialogue(new Rectangle(64, 0, 64, 64), false, "<default>");
                TileTrigger.CreateTileTriggerKillBox(new Rectangle(128, 0, 64, 64), false);

                ItemEntity.CreateItemEntity(new Vector2(576 + 64, 576), Vector2.Zero, ItemStack.CreateItemStack(ItemWeapon.CreateItemWeapon(0), 1), 1);
                ItemEntity.CreateItemEntity(new Vector2(576 + 128, 576 - 36), Vector2.Zero, ItemStack.CreateItemStack(ItemWeapon.CreateItemWeapon(1), 58), 1);

                Enemy.CreateEnemy(new Vector2(576, 0), 2, 0);

                ambientColor = new Color(25, 25, 50, 100);
            }

            if (id == 1)
            {
                player = Player.CreatePlayer(Vector2.Zero, 1);
                Enemy.CreateEnemy(new Vector2(500, 300), 1, 0);
                Enemy.CreateEnemy(new Vector2(300, 500), 1, 1);

                TileStatic.CreateTileStatic(new Rectangle(128, 128, 64, 64), "tile_grass1", 0);
                TileStatic.CreateTileStatic(new Rectangle(128, 360, 128, 64), "tile_grass1", 0);
            }
            drawnTileRenderTarget = false;
        }
示例#2
0
        public void LoadWorldFromFile(string mapFilePath, bool playerDefaultPos = true)
        {
            tiles.Clear();
            entityLivings.Clear();
            itemEntities.Clear();

            player = Player.CreatePlayer(new Vector2(0, 0), 1);

            string[] data = Utilities.ReadFile(mapFilePath, "<data>");

            int numberTiles    = Int32.Parse(data[0]),
                numberEntities = Int32.Parse(data[1]);

            for (int i = 0; i < numberTiles; i++)
            {
                string[] tileData = Utilities.ReadFile(mapFilePath, "<tile" + (i + 1) + ">");
                string   type     = tileData[0];

                switch (type)
                {
                case "static":
                {
                    Rectangle bounds      = Utilities.CreateRectangleFromStrings(tileData[1].Split(','));
                    string    texName     = tileData[2];
                    int       createLayer = Int32.Parse(tileData[3]);
                    string    rawisWall   = tileData[4];
                    bool      isWall      = rawisWall == "true" ? true : false;
                    TileStatic.CreateTileStatic(bounds, texName, createLayer, isWall, ParseDirections.ParseStringToDirections(tileData[5]));

                    break;
                }

                case "trigger":
                {
                    string triggerType = tileData[1];

                    string[] bounds = tileData[2].Split(',');

                    switch (triggerType)
                    {
                    case "dialogue":
                    {
                        string rawtriggerOnce = tileData[3];
                        bool   triggerOnce    = rawtriggerOnce == "true" ? true : false;

                        string dialogueKey = tileData[4];

                        TileTrigger.CreateTileTriggerDialogue(Utilities.CreateRectangleFromStrings(bounds), triggerOnce, dialogueKey);
                        break;
                    }

                    case "damage":
                    {
                        TileTrigger.CreateTileTriggerDamageBox(Utilities.CreateRectangleFromStrings(bounds), false, 0);                 //todo implement damage tile trigger
                        break;
                    }

                    case "kill":
                    {
                        TileTrigger.CreateTileTriggerKillBox(Utilities.CreateRectangleFromStrings(bounds), false);
                        break;
                    }
                    }
                    break;
                }
                }
            }

            for (int i = 0; i < numberEntities; i++)
            {
                string[] entityData = Utilities.ReadFile(mapFilePath, "<entity" + (i + 1) + ">");

                string type = entityData[0];

                int id = Int32.Parse(entityData[1]);

                Vector2 pos   = Utilities.CreateVector2FromStrings(entityData[2].Split(','));
                int     layer = Int32.Parse(entityData[3]);
                switch (type)
                {
                case "enemy":
                {
                    Enemy.CreateEnemy(pos, layer, id);
                    break;
                }

                case "item":
                {
                    //ItemEntity.CreateItemEntity(pos, )
                    break;
                }
                }
            }
        }