public void ParseObjects(Core core) { foreach (var layer in Layers) { var objectLayer = layer as MapObjectLayer; if (objectLayer == null) { continue; } foreach (var mapObject in objectLayer.Objects) { if (mapObject.Type == "SquadStart") { var soldier = new Soldier(ref core.Squad); soldier.Name = "Derp"; // HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91) var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); soldier.X = mapObjectGridPos.X; soldier.Y = mapObjectGridPos.Y; core.Squad.Add(soldier); } if (mapObject.Type == "MonsterSpawn" || mapObject.Type == "EnemySpawn") { var enemy = new MonsterSpawn("Monster", 14, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "AmbushMonsterSpawn" || mapObject.Type == "AmbushEnemySpawn") { var enemy = new MonsterSpawn("Monster", 2, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "DelayedMonsterSpawn" || mapObject.Type == "DelayedEnemySpawn") { var enemy = new MonsterSpawn("Monster", 200, 4, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "BossSpawn") { var enemy = new MonsterSpawn("BUB", 12, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "Door") { var door = new Door(true); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); door.X = mapObjectGridPos.X; door.Y = mapObjectGridPos.Y; } } } }
public void ParseObjects(Core core) { foreach (var layer in Layers) { var objectLayer = layer as MapObjectLayer; if (objectLayer == null) continue; foreach (var mapObject in objectLayer.Objects) { if (mapObject.Type == "SquadStart") { var soldier = new Soldier(ref core.Squad); soldier.Name = "Derp"; // HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91) var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); soldier.X = mapObjectGridPos.X; soldier.Y = mapObjectGridPos.Y; core.Squad.Add(soldier); } if (mapObject.Type == "MonsterSpawn" || mapObject.Type == "EnemySpawn") { var enemy = new MonsterSpawn("Monster", 14, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "AmbushMonsterSpawn" || mapObject.Type == "AmbushEnemySpawn") { var enemy = new MonsterSpawn("Monster", 2, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "DelayedMonsterSpawn" || mapObject.Type == "DelayedEnemySpawn") { var enemy = new MonsterSpawn("Monster", 200, 4, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "BossSpawn") { var enemy = new MonsterSpawn("BUB", 12, 0, ref core.Swarm); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); enemy.X = mapObjectGridPos.X; enemy.Y = mapObjectGridPos.Y; } if (mapObject.Type == "Door") { var door = new Door(true); var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y); var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos); door.X = mapObjectGridPos.X; door.Y = mapObjectGridPos.Y; } } } }