/// <summary> /// Tile loading method, reads gleed2d xml-file and sorts out paths and textures /// </summary> protected void LoadTiles() { SpriteClasses.SpriteManager.Content = content; SpriteClasses.SpriteManager.Level = world; finalScore = new List<ArrayList>(); using (Stream stream = TitleContainer.OpenStream("Content/Levels/level1.gleed")) //#1 change gere you level file path { XElement xml = XElement.Load(stream); level = LevelLoader.Load(xml); } tiles = new List<Tile>(); pathTiles = new List<PathTile>(); textures = new List<MyTexture>(); //despawn = new SpriteClasses.BloodControl.BloodDespawner(world, content.Load<Texture2D>("Test/test"), new Vector2(0, 0), new Vector2(0, 0), 1, 1, 2f, 2f); #region update sprites switch/foreach foreach (Layer layer in level.Layers) { String layerName = layer.Properties.Name.ToString(); switch (layerName) { case "Collision": { foreach (LayerItem item in layer.Items) { if (item.Properties is PathItemProperties) { PathItemProperties pathProperties = item.Properties as PathItemProperties; pathTile = new PathTile(pathProperties.LocalPoints, pathProperties.Position, world); pathTiles.Add(pathTile); } if (item.Properties is RectangleItemProperties) { RectangleItemProperties pathProperties = item.Properties as RectangleItemProperties; tile = new Tile(TileCollision.Impassable, pathProperties.Width, pathProperties.Height, pathProperties.Position, pathProperties.Rotation, world); tiles.Add(tile); } } } break; case "LevelTexture": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; string filename = "Levels/" + Path.GetFileNameWithoutExtension(textureProperties.TexturePathRelativeToContentRoot); //3# change here your tile textures' file path Texture2D texture = content.Load<Texture2D>(filename); myTexture = new MyTexture(texture, textureProperties.Position, textureProperties.Rotation, textureProperties.Scale * Globals.GlobalScale, .071f); textures.Add(myTexture); } } } break; case "Finish": { foreach (LayerItem item in layer.Items) { if (item.Properties is CircleItemProperties) { CircleItemProperties textureProperties = item.Properties as CircleItemProperties; Body Ziel = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(textureProperties.Radius), 1.0f); Ziel.Position = new Vector2(ConvertUnits.ToSimUnits(textureProperties.Position.X), ConvertUnits.ToSimUnits(textureProperties.Position.Y)); Ziel.IgnoreGravity = true; Ziel.CollidesWith = Category.Cat5; Ziel.OnCollision += collisionZiel; } } } break; case "Flow": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; velocityRectangles.Add(new VelocityRect(world, textureProperties.Position, textureProperties.Scale, textureProperties.Rotation, player)); } } } break; case "Plasma": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { kills_++; TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; allCells.Add(SpriteClasses.SpriteManager.addPlasmaCell(tempSpawn, new Vector2(0, 0), 'd')); } } } break; case "Player": { foreach (LayerItem item in layer.Items) { if (item.Properties is CircleItemProperties) { CircleItemProperties textureProperties = item.Properties as CircleItemProperties; Vector2 tempSpawn = textureProperties.Position; player = SpriteClasses.SpriteManager.addPlayerCell(tempSpawn); allCells.Add(player); } } } break; case "Makrophage": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; allCells.Add(SpriteClasses.SpriteManager.addMakrophageCell(tempSpawn, new Vector2(0, 0))); } } } break; case "Helper": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { kills_++; TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; allCells.Add(SpriteClasses.SpriteManager.addHilferCell(tempSpawn, new Vector2(0, 0))); } } } break; case "Monozyt": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; allCells.Add(SpriteClasses.SpriteManager.addMonozytCell(tempSpawn, new Vector2(0, 0))); } } } break; case "BloodSpawner": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; float tempScale = textureProperties.Scale.X; tempScale += textureProperties.Scale.Y; tempScale /= 2f; SpriteClasses.BloodControl.BloodSpawner tempBS = new SpriteClasses.BloodControl.BloodSpawner(tempSpawn, textureProperties.Rotation, 70, 17.5f, tempScale); tempBS.nameForLevel = textureProperties.Name; allCells.Add(tempBS); } } } break; case "BloodCellDespawner": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; float tempScale = textureProperties.Scale.X; tempScale += textureProperties.Scale.Y; tempScale /= 2f; SpriteClasses.BloodControl.BloodDespawner tempBS = SpriteClasses.SpriteManager.addBloodDespawner(tempSpawn, textureProperties.Rotation, tempScale); tempBS.nameForLevel = textureProperties.Name; allCells.Add(tempBS); } } } break; case "Gefecht": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; float tempScale = textureProperties.Scale.X; tempScale += textureProperties.Scale.Y; tempScale /= 2f; Vector2 tempSpawn = textureProperties.Position; SpriteClasses.Valves.Gefecht tempGef = SpriteClasses.SpriteManager.addGefecht(tempSpawn, textureProperties.Rotation, tempScale); tempGef.nameForLevel = textureProperties.Name; allCells.Add(tempGef); } } } break; case "Collection": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { collected_++; TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; allCells.Add(SpriteClasses.SpriteManager.addCollectCell(tempSpawn, new Vector2(0, 0))); } } } break; case "Nerve": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; SpriteClasses.NPCSprites.NerveCell tempNerve = SpriteClasses.SpriteManager.addNerveCell(tempSpawn, textureProperties.Rotation); tempNerve.nameForLevel = textureProperties.Name; allCells.Add(tempNerve); } } } break; case "Trigger": { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; Vector2 tempSpawn = textureProperties.Position; SpriteClasses.NPCSprites.TriggerCell tempTrigg = SpriteClasses.SpriteManager.addTriggerCell(tempSpawn, textureProperties.Rotation); tempTrigg.nameForLevel = textureProperties.Name; allCells.Add(tempTrigg); } } } break; default: break; } } #endregion paralaxBG = new SpriteClasses.Parallax.Background(Content.Load<Texture2D>("Levels/level1_bg"), 20f); bloodBG = new SpriteClasses.Parallax.Prop(Content.Load<Texture2D>("Images/BGs/bloodcellparalax"), new Vector2(-1000, 1000), new Vector2(1, -3), 150f, 'R', 1f); bloodBG2 = new SpriteClasses.Parallax.Prop(Content.Load<Texture2D>("Images/BGs/bloodcellparalax"), new Vector2(-2000, -2000), new Vector2(3, 2), 80f, 'B', .7f); bloodBG3 = new SpriteClasses.Parallax.Prop(Content.Load<Texture2D>("Images/BGs/bloodcellparalax"), new Vector2(1000, 1000), new Vector2(-4, -1), 700f, 'W', 3f); veinBG = new SpriteClasses.Parallax.Prop(Content.Load<Texture2D>("Images/BGs/venesParalax"), new Vector2(-1100, -500), new Vector2(0, 0), 50f, 'F', 2f); veinBG.Rotation = (float)(2.0 / Math.PI); alarm = new SpriteClasses.alarmSprite(world, Content.Load<Texture2D>("Images/alarm"), new Vector2(0, 0), new Vector2(0, 0), 4, 1); fadingTest = SpriteClasses.SpriteManager.addFadingSprite(); allCells.Add(paralaxBG); allCells.Add(bloodBG); allCells.Add(veinBG); allCells.Add(bloodBG2); allCells.Add(alarm); allCells.Add(bloodBG3); allCells.Add(fadingTest); }
/// <summary> /// Tile loading method, reads gleed2d xml-file and sorts out paths and textures /// </summary> protected void LoadTiles() { Vector2 playerSpawn = new Vector2(0, 0); using (Stream stream = TitleContainer.OpenStream("Content/Levels/level1.gleed")) //#1 change gere you level file path { XElement xml = XElement.Load(stream); level = LevelLoader.Load(xml); } tiles = new List<Tile>(); pathTiles = new List<PathTile>(); textures = new List<MyTexture>(); foreach (Layer layer in level.Layers) { if (layer.Properties.Name.Equals("Collision")) //2# change here your layer's name { foreach (LayerItem item in layer.Items) { if (item.Properties is PathItemProperties) { PathItemProperties pathProperties = item.Properties as PathItemProperties; pathTile = new PathTile(pathProperties.LocalPoints, pathProperties.Position, world); pathTiles.Add(pathTile); } if (item.Properties is RectangleItemProperties) { RectangleItemProperties pathProperties = item.Properties as RectangleItemProperties; tile = new Tile(TileCollision.Impassable, pathProperties.Width, pathProperties.Height, pathProperties.Position, pathProperties.Rotation, world); tiles.Add(tile); } } } if (layer.Properties.Name.Equals("Textures")) { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; string filename = "Levels/" + Path.GetFileNameWithoutExtension(textureProperties.TexturePathRelativeToContentRoot); //3# change here your tile textures' file path Texture2D texture = content.Load<Texture2D>(filename); myTexture = new MyTexture(texture, textureProperties.Position, textureProperties.Rotation, textureProperties.Scale); textures.Add(myTexture); } } } if (layer.Properties.Name.Equals("Player")) { foreach (LayerItem item in layer.Items) { if (item.Properties is CircleItemProperties) { CircleItemProperties textureProperties = item.Properties as CircleItemProperties; playerSpawn = textureProperties.Position; } } } if (layer.Properties.Name.Equals("Collectibles")) { foreach (LayerItem item in layer.Items) { if (item.Properties is CircleItemProperties) { CircleItemProperties textureProperties = item.Properties as CircleItemProperties; collectibles.Add(new SpriteClasses.CollectCell(world, Content.Load<Texture2D>("Images/collectible2 Kopie"), new Vector2(textureProperties.Position.X, textureProperties.Position.Y), new Vector2(0, 0), 12, 1)); } } } if (layer.Properties.Name.Equals("Path")) { foreach (LayerItem item in layer.Items) { if (item.Properties is TextureItemProperties) { TextureItemProperties textureProperties = item.Properties as TextureItemProperties; velocityRectangles.Add(new VelocityRect(world, textureProperties.Position, textureProperties.Scale, textureProperties.Rotation, player)); } } } } player = new SpriteClasses.PlayerSprite(world, Content.Load<Texture2D>("Test/anim_sp"), playerSpawn, new Vector2(0, 0), 4, 1); blood = new SpriteClasses.NPCSprites.MakrophageCell(world, Content.Load<Texture2D>("Test/enemyspritesheet"), new Vector2(-900, -600), new Vector2(0, 0), 5, 2); helper = new SpriteClasses.NPCSprites.HilferCell(world, Content.Load<Texture2D>("Images/helferzelle_alarm"), new Vector2(200, 200), new Vector2(0, 0), 4, 1); monozyt = new SpriteClasses.NPCSprites.MonozytCell(world, Content.Load<Texture2D>("Images/monozyt spritesheet"), new Vector2(400, 200), new Vector2(0, 0), 14, 1); plasma = new SpriteClasses.NPCSprites.PlasmaCell(world, Content.Load<Texture2D>("Images/plasmacellmoving spritesheet"), new Vector2(400, 300), new Vector2(0, 0), 8, 1); //upper nerve1 = new SpriteClasses.NPCSprites.NerveCell(world, Content.Load<Texture2D>("Test/nerve"), new Vector2(-935, 625), new Vector2(0, 0), 4, 2, "toggle"); nerve1.rotation = 1f; //lower nerve2 = new SpriteClasses.NPCSprites.NerveCell(world, Content.Load<Texture2D>("Test/nerve"), new Vector2(550, -250), new Vector2(0, 0), 4, 2, "toggle"); nerve2.rotation = (float)Math.PI; for (int i = 0; i < collectibles.Count; i++) collectibles[i].body.OnCollision += collectCoin; //lower spawner bloodSpawn1 = new Spawner(Content, 50, .04f, new Vector2(-1100, -33), new Vector2(4.5f, 3f), "bloodcell"); //upper spawner bloodSpawn2 = new Spawner(Content, 50, .04f, new Vector2(1030, -630), new Vector2(-4.5f, 3f), "bloodcell"); player.setupAttack(Content); }