public static void LoadMap(string loadMapName) { //if the current map is loaded //note: make map, mapname and objectlayer a struct called level for easy access if (loadMapName != currentLevel.MapName) { foreach (var map in availableMaps) { var nameToComapre = ""; map.Map.Properties.TryGetValue("MapName", out nameToComapre); if (nameToComapre == loadMapName) { //map found in available maps currentLevel = map; objectLayer = currentLevel.ObjectLayer; //set parameters from objects in map foreach (var entity in objectLayer.Objects) { //camerastart parameter if (entity.Name == "CameraStart") { Camera.camera.Position = entity.Position; } } } } } }
void ReadObjectLayers(ContentReader input, TiledMap map) { var layersCount = input.ReadInt32(); var layers = new TiledMapObjectLayer[layersCount]; for (var i = 0; i < layersCount; i += 1) { var layer = new TiledMapObjectLayer(); ReadLayer(input, layer); layer.DrawingOrder = (TiledMapObjectDrawingOrder)input.ReadByte(); layer.Color = input.ReadColor(); var objectsCount = input.ReadInt32(); var objects = new TiledObject[objectsCount]; for (var k = 0; k < objectsCount; k += 1) { objects[k] = ReadObject(input, map); } layer.Objects = objects; layers[i] = layer; } map.ObjectLayers = layers; }
private static Player MakeWorldAndPlayer(params Rectangle[] immovables) { var world = new World(); var map = new TiledMap("TestMap", Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight, TiledMapTileDrawOrder.RightDown, TiledMapOrientation.Orthogonal); var bottomLayer = new TiledMapTileLayer(Dungeon.BottomLayerName, Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight); for (int y = 0; y < bottomLayer.Height; ++y) { for (int x = 0; x < bottomLayer.Width; ++x) { bottomLayer.SetTile((ushort)x, (ushort)y, 1); } } map.AddLayer(bottomLayer); var collidables = new TiledMapRectangleObject[immovables.Length]; int i = 0; foreach (Rectangle immovable in immovables) { // Note: Object IDs for Tiled maps start at 1, not 0. collidables[i] = new TiledMapRectangleObject(i + 1, "collidable" + (i + 1), new Size2(immovable.Width, immovable.Height), new Vector2(immovable.X, immovable.Y)); ++i; } var collisionLayer = new TiledMapObjectLayer(Dungeon.CollisionLayerName, collidables); map.AddLayer(collisionLayer); var dungeon = new Dungeon(world, map, null); world.Dungeons.Add(dungeon); var player = new Player(dungeon, new Point(Room.Width / 2, Room.Height / 2), Direction.Down); world.Player = player; return(player); }
public Level(TiledMap map) { Map = map; map.Properties.TryGetValue("MapName", out MapName); ObjectLayer = map.GetLayer <TiledMapObjectLayer>("GameObjects"); NavigationMatrix = new int[map.Width, map.Height]; ElevationMatrix = new int[map.Width, map.Height]; Characters = new List <Character>(); }
/// <summary> /// Goes through the current level file and loads all of the collision objects, so that they can be returned and added to the list of active GameObjects. Note that all collision object must be on a layer /// named "collision" that is set to be an object layer, and not a normal tile layer (normal tiles don't have a position member). /// </summary> /// <returns></returns> public List <GameObject> getCollisionObjects() { List <GameObject> collisionObjects = new List <GameObject>(); TiledMapObjectLayer objectLayer = currentMap.GetLayer <TiledMapObjectLayer>("collision"); //Get the collision layer to start with TiledMapLayer debugLayer = currentMap.GetLayer <TiledMapLayer>("collision"); Console.WriteLine(debugLayer.ToString()); GameObject tempObject; //Make an object reference to hold objects we'll construct later, and then add properties to try { foreach (TiledMapPolygonObject tile in objectLayer.Objects) //Go through all of the tiles in the map { tempObject = new GameObject(); tempObject.transform.SetPosition(tile.Position); //Set the collision object's position //Get the vertices of this collision object Vector2[] vertices; vertices = new Vector2[tile.Points.Count()]; //Set the vertices to be the same count as that of the tile object's for (int i = 0; i < tile.Points.Count(); i++) { vertices[i] = new Vector2(tile.Points[i].X, tile.Points[i].Y); //The Points are already the displacement from an origin, so this will match the Hitbox constructor later } Hitbox hitbox = new Hitbox(vertices, tempObject); //Create a hitbox for this tile tempObject.AddComponent(hitbox); //Give the tile the hitbox tempObject.AddComponent(new CollisionComponent(null, hitbox)); //Add collision to the tile with the given hitbox and no physics component collisionObjects.Add(tempObject); //Now that the tile object has collision and a hitbox mask, add it to the list of GameObjects that we want to return } } catch (Exception e) //In case the collision layer is null { Console.WriteLine("Error encountered in getCollisionObjects(): " + e.Message); } //DEBUG Let's make sure that it's correctly adding the tile objects Console.WriteLine("Number of collision objects = " + collisionObjects.Count); return(collisionObjects); }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here _playerTexture = Content.Load <Texture2D>("ball"); _map = Content.Load <TiledMap>("Plazas/sample"); _tiledMapRenderer = new TiledMapRenderer(GraphicsDevice, _map); _borders = _map.GetLayer <TiledMapTileLayer>("Obstacles"); _objects = _map.GetLayer <TiledMapObjectLayer>("Objects"); var pos = _objects?.Objects?.FirstOrDefault(o => { o.Properties.TryGetValue("player", out string playerPos); return(int.Parse(playerPos) == 1); }); _startPosition = pos.Position; }
protected virtual void BuildLayerCache() { layers.Clear(); layerMap.Clear(); for (var layerIndex = 0; layerIndex < Map.Layers.Count; layerIndex++) { var mooseLayer = Map.Layers[layerIndex] switch { TiledMapTileLayer tileLayer => new TiledMooseTileLayer(tileLayer), TiledMapObjectLayer objectLayer => new TiledMooseObjectLayer(objectLayer, Width, Height), _ => null as ILayer }; if (mooseLayer != null) { AddLayer(mooseLayer); } } BuildFullBlockingMap(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // load player playerSprite = Content.Load <Texture2D>("Imgs/player"); player = new Player(200f, playerSprite.Width, playerSprite.Height, playerSprite); // import tmx map map = Content.Load <TiledMap>("maps/terrain"); // grab bottom, middle and top layers bottomLayer = map.GetLayer <TiledMapLayer>("bottomLayer"); middleLayer = map.GetLayer <TiledMapLayer>("middleLayer"); topLayer = map.GetLayer <TiledMapLayer>("topLayer"); overLapLayer = map.GetLayer <TiledMapLayer>("overLapLayer"); mapRenderer = new TiledMapRenderer(GraphicsDevice); mapRenderer.LoadMap(map); // collision variables objectLayer = map.GetLayer <TiledMapObjectLayer>("collision"); }
public static TiledMapObjectLayer ParseObjectLayer(XmlNode layerXml, bool parseBase = true) { var layer = new TiledMapObjectLayer(); if (parseBase) // This is done for tiles, which have objects. Their objectgroup doesn't need any base layer stuff. { ParseBaseLayer(layerXml, layer); } if (layerXml.Attributes["color"] != null) { layer.Color = XmlHelper.StringToColor(layerXml.Attributes["color"].Value); } if (XmlHelper.GetXmlStringSafe(layerXml, "draworder") == "index") { layer.DrawingOrder = TiledMapObjectDrawingOrder.Manual; } else { layer.DrawingOrder = TiledMapObjectDrawingOrder.TopDown; } // Parsing objects. var objectsXml = layerXml.SelectNodes("object"); var objects = new List <TiledObject>(); foreach (XmlNode obj in objectsXml) { objects.Add(ParseObject(obj)); } layer.Objects = objects.ToArray(); // Parsing objects. return(layer); }
protected override void LoadContent() { map = content.Load <TiledMap>(@"Levels\MHForestTest"); nodeLayer = map.GetLayer <TiledMapObjectLayer>("Node"); nodes = nodeLayer.Objects; pathLayer = map.GetLayer <TiledMapObjectLayer>("Path"); pathNodes = pathLayer.Objects; hideLayer = map.GetLayer <TiledMapObjectLayer>("Hiding"); hideNodes = hideLayer.Objects; SetUpGraph setUp = new SetUpGraph(pathNodes); Graph pathGraph = setUp.MakeGraph(); setUp = new SetUpGraph(hideNodes); Graph hideGraph = setUp.MakeGraph(); Texture2D spriteSheet = content.Load <Texture2D>(@"Sprites\MonsterSprite"); //Texture2D healthBar = content.Load<Texture2D>(@"Misc\enemy_health_bar_000"); Texture2D healthContainer = content.Load <Texture2D>(@"Misc\enemy_health_bar_000"); Texture2D chargeIcon = content.Load <Texture2D>(@"Misc\IconBlue"); Texture2D inviIcon = content.Load <Texture2D>(@"Misc\IconRed"); SpriteFont font = content.Load <SpriteFont>(@"Fonts\HealthFont"); player = new Player(GameRef, "iiio", false, spriteSheet, font, healthContainer, chargeIcon, inviIcon); collisionHandler = new CollisionHandler(player); Texture2D enemSprite = content.Load <Texture2D>(@"Sprites\PoliceSprite"); foreach (TiledMapObject obj in nodes) { if (obj.Type == "PoliceNode") { //EnemPolis Polis = new EnemPolis(GameRef, enemSprite, pathGraph, GameRef.PolisAnimations); //Polis.Position = obj.Position; //Polis.Player = player; //Polis.OnMap = map; //Polis.Initialize(); ////Polis.BulletRef = bullets; //collisionHandler.LoadEntities(Polis.Sprite); //polis.Add(Polis); } else if (obj.Type == "CivilianNode") { EnemCiv Civ = new EnemCiv(GameRef, enemSprite, hideGraph, GameRef.CivAnimations); Civ.Position = obj.Position; Civ.Player = player; Civ.OnMap = map; Civ.Initialize(); collisionHandler.LoadEntities(Civ.Sprite); civilians.Add(Civ); } else if (obj.Type == "PlayerNode") { player.Position = obj.Position; } } }
public void LoadLevel(ContentManager content, GraphicsDeviceManager graphics, List <GameObject> objects, string levelNumber, string roomNumber, bool restartMusic) { bgMusic = content.Load <SoundEffect>("Sounds/Music/J04"); if (soundEffectInstance != null && levelNumber != levelNumberHolder) { soundEffectInstance.Stop(true); soundEffectInstance.Dispose(); } if (restartMusic) { soundEffectInstance = bgMusic.CreateInstance(); soundEffectInstance.Play(); } levelNumberHolder = levelNumber; //Load and Draw the map and walls wallMap.Load(content); tiledMap = content.Load <TiledMap>("TiledMaps/m_level_" + levelNumber); renderer = new TiledMapRenderer(graphics.GraphicsDevice); //access walls in map var tiledMapWallsLayer = tiledMap.GetLayer <TiledMapTileLayer>("Wall"); //access stairs in map var tiledMapInteractLayer = tiledMap.GetLayer <TiledMapTileLayer>("Interact"); //access objects in map objectLayer = tiledMap.GetLayer <TiledMapObjectLayer>("Room_" + roomNumber); if (objectLayer != null) { for (int i = 0; i < objectLayer.Objects.Length; i++) { // create player if (objectLayer.Objects[i].Type == "Player" && objects.Count == 0) { if (Door.transitionDirection == "StairTransition") { if (objectLayer.Objects[i].Name == "PlayerStartStairs") { objects.Add(new Player(new Vector2(objectLayer.Objects[i].Position.X, objectLayer.Objects[i].Position.Y))); } } else if (Door.transitionDirection != "StairTransition" && objectLayer.Objects[i].Name == "PlayerStart") { if (Game1.levelNumber != "Overworld") { objects.Add(new Player(new Vector2(objectLayer.Objects[i].Position.X, objectLayer.Objects[i].Position.Y))); } else { objects.Add(new PlayerOverworld(new Vector2(objectLayer.Objects[i].Position.X, objectLayer.Objects[i].Position.Y))); } } //if the player exist, initialize and load if (objects.Count > 0) { objects[0].Initialize(); objects[0].Load(content); } } //create enemies if (objectLayer.Objects[i].Type == "Enemy") { objects.Add(new PatrolEnemy(new Vector2(objectLayer.Objects[i].Position.X, objectLayer.Objects[i].Position.Y))); } // create camera and min max values if (objectLayer.Objects[i].Type == "Camera") // set camera max and min { if (objectLayer.Objects[i].Name == "cameraMin") { Camera.cameraMin = objectLayer.Objects[i].Position + Camera.cameraOffset; roomMin = objectLayer.Objects[i].Position; } if (objectLayer.Objects[i].Name == "cameraMax") { Camera.cameraMax = objectLayer.Objects[i].Position - Camera.cameraOffset; roomMax = objectLayer.Objects[i].Position; } } if (objectLayer.Objects[i].Type == "Door") // make doors { wallMap.doors.Add(new Door(new Rectangle((int)objectLayer.Objects[i].Position.X, (int)objectLayer.Objects[i].Position.Y, (int)objectLayer.Objects[i].Size.Width, (int)objectLayer.Objects[i].Size.Height), objectLayer.Objects[i].Name)); } } } // draw the walls if (tiledMapWallsLayer != null) { for (var i = 0; i < tiledMapWallsLayer.Width; i++) { for (var j = 0; j < tiledMapWallsLayer.Height; j++) { if ((i > (roomMin.X - tiledMapWallsLayer.TileWidth) / tiledMapWallsLayer.TileWidth && j > (roomMin.Y - tiledMapWallsLayer.TileHeight) / tiledMapWallsLayer.TileHeight) && (i <= (roomMax.X + tiledMapWallsLayer.TileWidth) / tiledMapWallsLayer.TileWidth && j <= (roomMax.Y + tiledMapWallsLayer.TileHeight) / tiledMapWallsLayer.TileHeight)) { if (tiledMapWallsLayer.TryGetTile(i, j, out TiledMapTile? tile)) { if (tile.Value.GlobalIdentifier == 1) // make walls { wallMap.walls.Add(new Wall(new Rectangle(i * tiledMapWallsLayer.TileWidth, j * tiledMapWallsLayer.TileHeight, tiledMapWallsLayer.TileWidth, tiledMapWallsLayer.TileHeight))); } } if (tiledMapInteractLayer != null) { if (tiledMapInteractLayer.TryGetTile(i, j, out TiledMapTile? itile)) { if (itile.Value.GlobalIdentifier == 2) // make stairs { //use for stair directions if (!itile.Value.IsFlippedHorizontally) { wallMap.stairs.Add(new Stair(new Rectangle(i * tiledMapInteractLayer.TileWidth, j * tiledMapInteractLayer.TileHeight, tiledMapInteractLayer.TileWidth, tiledMapInteractLayer.TileHeight))); } else { wallMap.stairs.Add(new Stair(new Rectangle(i * tiledMapInteractLayer.TileWidth, j * tiledMapInteractLayer.TileHeight, tiledMapInteractLayer.TileWidth, tiledMapInteractLayer.TileHeight), false)); } } } } } } } } //load objects LoadObjects(content, objects); }
/// <summary> /// Loads MapObjects for the Active Map, iterates through them, and instantiates objects /// based on the information found in the Map ObjectLayers /// </summary> private void LoadMapObjectLayers() { TiledMapObjectLayer _mapEntityObjectLayer = MapCurrent.GetLayer <TiledMapObjectLayer>("Entity Layer"); TiledMapObjectLayer _mapCollisionLayer = MapCurrent.GetLayer <TiledMapObjectLayer>("Collision Layer"); TiledMapObjectLayer _mapAreaDefinitionLayer = MapCurrent.GetLayer <TiledMapObjectLayer>("Area Definitions"); foreach (TiledMapObject _entityObject in _mapEntityObjectLayer.Objects) { switch (_entityObject.Name) { case "mapPlayerSpawn": { // Run Player Spawn Code Here PlayerSpawnX = Convert.ToInt32(_entityObject.Position.X); PlayerSpawnY = Convert.ToInt32(_entityObject.Position.Y); IsPlayerSpawn = true; break; } case "mapTransition": { // Create Transition Objects float destinationX, destinationY; destinationX = Convert.ToInt32(_entityObject.Properties["mapDestinationX"]); destinationY = Convert.ToInt32(_entityObject.Properties["mapDestinationY"]); MapTransitionHandler mapTransition = new MapTransitionHandler(contentManager, _entityObject.Properties["mapDestination"], new Vector2((float)destinationX, (float)destinationY), new Rectangle((int)_entityObject.Position.X, (int)_entityObject.Position.Y, (int)_entityObject.Size.Width, (int)_entityObject.Size.Height), _entityObject.Properties["mapDestinationArea"], _entityObject.Properties["mapDestinationFacing"]); MapObjects.Add(mapTransition); break; } case "mapEntitySpawn": { // Get AssetManager Data AnimationLibrary _animationLibrary = AssetManager.GetAnimationLibrary(_entityObject.Properties["AnimationLibraryName"]); // Spawn the Entity bool isSolid = Convert.ToBoolean(_entityObject.Properties["IsSolid"]); MapEntityStatic _mapEntity = new MapEntityStatic(isSolid, new Vector2(_entityObject.Position.X, _entityObject.Position.Y), (int)_entityObject.Size.Width, (int)_entityObject.Size.Height, _entityObject.Properties["AnimationLibraryName"]); _mapEntity.ConstructAnimationLibrary(_animationLibrary.Name, _entityObject.Properties["CurrentAnimation"]); Entities.Add(_mapEntity); break; } } } foreach (TiledMapObject _collisionObject in _mapCollisionLayer.Objects) { switch (_collisionObject.Name) { case "solidStatic": { MapCollisionSolidStatic solid = new MapCollisionSolidStatic(_collisionObject.Position, (int)_collisionObject.Size.Width, (int)_collisionObject.Size.Height); CollisionObjects.Add(solid); break; } } } foreach (TiledMapObject _areaDefintion in _mapAreaDefinitionLayer.Objects) { MapAreaDefinition area = new MapAreaDefinition(_areaDefintion.Name, new Vector2((int)_areaDefintion.Position.X, (int)_areaDefintion.Position.Y), new Rectangle((int)_areaDefintion.Position.X, (int)_areaDefintion.Position.Y, (int)_areaDefintion.Size.Width, (int)_areaDefintion.Size.Height)); Areas.Add(area); } }
public TiledMooseObjectLayer(TiledMapObjectLayer layer, int width, int height) : base(layer.Name, width, height) => Layer = layer;
public Level(TiledMap map) { Map = map; map.Properties.TryGetValue("MapName", out MapName); ObjectLayer = map.GetLayer <TiledMapObjectLayer>("GameObjects"); }
/// <summary> /// Loads TiledMap into memory, releasing old CollisionMasks, if present /// </summary> /// <param name="mapID">ID of Map to Load</param> /// <returns></returns> public void LoadMap(string mapID) { SceneObjectLoader loader = new SceneObjectLoader(); if (ActiveMap != null) { loader.SaveSceneObjects(MapID, TileSceneObjects); } if (CollisionSolids.Count > 0) { for (int i = CollisionSolids.Count - 1; i >= 0; i--) { CollisionSolids.RemoveAt(i); } } if (TransitionHandlers.Count > 0) { for (int i = TransitionHandlers.Count - 1; i >= 0; i--) { TransitionHandlers.RemoveAt(i); } } MapID = mapID; string assetPath = Global.GetMapAssetPathByID(MapID); MapToLoad = Content.Load <TiledMap>(assetPath); TiledMapObjectLayer collisionLayer = MapToLoad.GetLayer <TiledMapObjectLayer>("CollisionMasks"); TiledMapObjectLayer transitionLayer = MapToLoad.GetLayer <TiledMapObjectLayer>("Transitions"); TiledMapObjectLayer interactive = MapToLoad.GetLayer <TiledMapObjectLayer>("Interactive"); if (collisionLayer.Objects.Length > 0 && collisionLayer != null) { foreach (TiledMapObject _sceneObject in collisionLayer.Objects) { switch (_sceneObject.Name) { case "CollisionSolid": { EntityCollisionSolid _newCollisionObject = new EntityCollisionSolid(_sceneObject.Position, (int)_sceneObject.Size.Width, (int)_sceneObject.Size.Height); CollisionSolids.Add(_newCollisionObject); break; } case "CollisionSolidAngle": { EntityCollisionSolid _newCollision = new EntityCollisionSolid(_sceneObject.Position, (int)_sceneObject.Size.Width, (int)_sceneObject.Size.Height, float.Parse(_sceneObject.Properties["Tilt"])); CollisionSolids.Add(_newCollision); break; } } } } if (transitionLayer.Objects.Length > 0 && transitionLayer != null) { foreach (TiledMapObject _transition in transitionLayer.Objects) { switch (_transition.Name) { case "TransitionDoor": { TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height); TransitionHandlers.Add(transition); break; } case "TransitionDoorLocked": { TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height); if (_transition.Properties["LockType"] == "Key") { transition.LockWithKey(Global.GetSceneObjectBYID(_transition.Properties["KeyShortname"]), int.Parse(_transition.Properties["KeyQuantity"])); } if (_transition.Properties["LockType"] == "Trigger") { transition.LockWithTrigger(_transition.Properties["TriggerKey"]); } TransitionHandlers.Add(transition); break; } case "TransitionSilent": { TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height); transition.SetAsSilent(); TransitionHandlers.Add(transition); break; } } } } if (interactive != null && interactive.Objects.Length > 0) { foreach (TiledMapObject _interactive in interactive.Objects) { switch (_interactive.Name) { case "InteractiveLadder": { EntityLadder ladder = new EntityLadder(_interactive.Position, (int)_interactive.Size.Width, (int)_interactive.Size.Height); InteractiveEntities.Add(ladder); break; } } } } ActiveMap = MapToLoad; TileSceneObjects = new List <TileEntitySceneObject>(loader.LoadSceneObjects(mapID)); BoundingBox = new Rectangle(0, 0, ActiveMap.WidthInPixels, ActiveMap.HeightInPixels); OnMapLoaded(); }
public void LevelLoader(ContentManager content, GraphicsDevice graphics, List <GameObject> _objects, string levelNumber, string roomNumber, bool restartMusic) { bgMusic = content.Load <SoundEffect>("Audio/Music/Level_" + levelNumber); if (soundEffectInstance != null && levelNumber != levelNumberHolder) { soundEffectInstance.Stop(true); soundEffectInstance.Dispose(); } if (restartMusic) { soundEffectInstance = bgMusic.CreateInstance(); soundEffectInstance.Play(); } soundEffectInstance.IsLooped |= levelNumber != "GameOver"; HUD.rupeeDisplay = HUD.rupeeCount; levelNumberHolder = levelNumber; map.Load(content); _map = content.Load <TiledMap>("Maps/Level_" + levelNumber); _renderer = new TiledMapRenderer(graphics, _map); foreach (var tileLayer in _map.TileLayers) { for (var x = 0; x < tileLayer.Width; x++) { for (var y = 0; y < tileLayer.Height; y++) { var tile = tileLayer.GetTile((ushort)x, (ushort)y); if (tile.GlobalIdentifier == 16) { var tileWidth = _map.TileWidth; var tileHeight = _map.TileHeight; map.walls.Add(new Wall(new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight))); } } } } //parsing in objects from object layer _objectLayer = _map.GetLayer <TiledMapObjectLayer>("Room" + roomNumber); for (int i = 0; i < _objectLayer.Objects.Length; i++) { if (_objectLayer.Objects[i].Type == "player" && _objects.Count == 0) { //create player if none exists if (_objectLayer.Objects[i].Name == "playerStart") { _objects.Add(new Player(new Vector2(_objectLayer.Objects[i].Position.X, _objectLayer.Objects[i].Position.Y - 7))); _objects[0].Initialize(); _objects[0].Load(content); } if (_objectLayer.Objects[i].Name == "playerOverworld" + Game1.previousLevel) { _objects.Add(new PlayerOverworld(_objectLayer.Objects[i].Position)); _objects[0].Initialize(); _objects[0].Load(content); } } } for (int i = 0; i < _objectLayer.Objects.Length; i++) { if (_objectLayer.Objects[i].Type == "camera") { //set camera max and min per room if (_objectLayer.Objects[i].Name == "cMin" + roomNumber) { Camera.cameraMin = _objectLayer.Objects[i].Position + Camera.cameraOffset; } if (_objectLayer.Objects[i].Name == "cMax" + roomNumber) { Camera.cameraMax = _objectLayer.Objects[i].Position - Camera.cameraOffset; } } //create doors if (_objectLayer.Objects[i].Type == "door") { map.doors.Add(new Door(new Rectangle((int)_objectLayer.Objects[i].Position.X, (int)_objectLayer.Objects[i].Position.Y, (int)_objectLayer.Objects[i].Size.Width, (int)_objectLayer.Objects[i].Size.Height), _objectLayer.Objects[i].Name)); } //create enemies if (_objectLayer.Objects[i].Type == "enemy") { _objects.Add(EnemyLookUp.EnemyLUT(_objectLayer.Objects[i].Name, _objectLayer.Objects[i].Position, _objectLayer.Objects[i].Identifier)); } //create npcs if (_objectLayer.Objects[i].Type == "npc") { _objects.Add(NPCLookUp.NpcLUT(_objectLayer.Objects[i].Name, _objectLayer.Objects[i].Position)); } //create map objects if (_objectLayer.Objects[i].Type == "object") { _objects.Add(MapObjectLookUp.MapObjLUT(_objectLayer.Objects[i].Name, new Rectangle((int)_objectLayer.Objects[i].Position.X, (int)_objectLayer.Objects[i].Position.Y, (int)_objectLayer.Objects[i].Size.Width, (int)_objectLayer.Objects[i].Size.Height))); } } if (_objects.Count > 0) { if (_objects[0].objectType == "player") { _objects.Add(new HUD()); } } LoadObjects(content, _objects); //despawn enemies for (int i = 0; i < _objects.Count; i++) { for (int j = 0; j < Game1._destroyedObjects.Count; j++) { if (_objects[i].objectType + _objects[i].objectId + Game1.levelNumber + Game1.checkPoint == Game1._destroyedObjects[j]) { _killObjects.Add(_objects[i]); } } } //despawn permanent destroyed items/enemies for (int i = 0; i < _objects.Count; i++) { for (int j = 0; j < Game1._destroyedPermanent.Count; j++) { if (_objects[i].objectType + _objects[i].objectId + Game1.levelNumber + Game1.checkPoint == Game1._destroyedPermanent[j]) { _killObjects.Add(_objects[i]); } } } foreach (GameObject o in _killObjects) { _objects.Remove(o); } }