public static void LoadFirstLevel(Level level, Game game) { //Using prefab entity creation methods Entity platform = NewStaticObjectEntity(game, "platform1", "Sprites/platform", new Vector2(300, 350), 0.2f, CoordinateType.World); Entity platform2 = NewStaticObjectEntity(game, "platform2", "Sprites/platform", new Vector2(864, 400), 0.2f, CoordinateType.World); Entity platform3 = NewStaticObjectEntity(game, "platform3", "Sprites/crate", new Vector2(1408, 420), 0.2f, CoordinateType.World); Entity player = EntityTemplates.MakePlayerEntity(game, "PLAYER", "Sprites/hobosquirrel", new Vector2(60, 10), new Rectangle(0, 0, 30, 56)); PlayerID = player.EntityID; //Constructing backdrop entity Entity backdrop = new Entity(); backdrop.Game = game; backdropID = backdrop.EntityID; SpriteAspect sprite = new SpriteAspect(); sprite.OwnerID = backdrop.EntityID; sprite.Name = "sprite"; sprite.OrientationAspect = "orientation"; backdrop.Aspects.Add(sprite); OrientationAspect orientation = new OrientationAspect(); orientation.OwnerID = backdrop.EntityID; orientation.Name = "orientation"; backdrop.Aspects.Add(orientation); RenderingAspect render = new RenderingAspect(); render.OwnerID = backdrop.EntityID; render.Name = "renderer"; backdrop.Aspects.Add(render); backdrop.Aspects.FindFirst<SpriteAspect>().CoordinateType = CoordinateType.World; backdrop.Aspects.FindFirst<SpriteAspect>().ImageFile = "Sprites/Blue hills"; backdrop.Aspects.FindFirst<SpriteAspect>().Scale = new Vector2(2.0f, 2.0f); backdrop.Aspects.FindFirst<SpriteAspect>().LayerDepth = 0.1f; //Constructing physics debug view entity Entity physicsDebugger = new Entity(); physicsDebugger.Game = game; PhysicsDebugAspect phydebug = new PhysicsDebugAspect(); phydebug.OwnerID = physicsDebugger.EntityID; phydebug.Name = "farseer"; phydebug.LayerDepth = 1; physicsDebugger.Aspects.Add(phydebug); physicsDebugger.Name = "PHYDEBUGGER"; level.Entities.Add(physicsDebugger); //Add Entities to level platform.Name = "PLATFORM1"; platform2.Name = "PLATFORM2"; platform3.Name = "PLATFORM3"; backdrop.Name = "BACKDROP"; Entity enemy = EntityTemplates.MakeEnemyEntity(game, "Enemy1", "Sprites/funnycaveman", new Vector2(350, 60), new Rectangle(0, 0, 70, 46)); level.Entities.Add(enemy); level.Entities.Add(platform); level.Entities.Add(platform2); level.Entities.Add(platform3); level.Entities.Add(player); level.Entities.Add(backdrop); //Load level (initialize entities) //level.Load(); //DO IT YOURSELF //Ignore this crap, I was playing with sprite ordering //((RenderingAspect)player.Aspects.FindFirst<RenderingAspect>()).Visible = false; //((RenderingAspect)platform.Aspects.FindFirst<RenderingAspect>()).Visible = false; //((RenderingAspect)backdrop.Aspects.FindFirst<RenderingAspect>()).Visible = false; //((RenderingAspect)player.Aspects.FindFirst<RenderingAspect>()).DrawOrder = 3; //((RenderingAspect)platform.Aspects.FindFirst<RenderingAspect>()).DrawOrder = 2; //((RenderingAspect)backdrop.Aspects.FindFirst<RenderingAspect>()).DrawOrder = 1; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { camera = new BasicCamera(GraphicsDevice.Viewport); RenderingService.AddCamera(camera); camera.MoveSpeed = 5f; #if EDITOR switch (levelMode) { case SAVE_MODE: level = new Level(); FirstLevel.LoadFirstLevel(level, this); break; case OPEN_MODE: //Level level2 = new Level(); //level2.game = this; //FirstLevel.LoadFirstLevel(level2, this); // HACK stupid hack to read in Aspect types, won't need in the future //FileStream file = new FileStream("../../../xmlTest.xml", FileMode.Open); //XmlSerializer xml = new XmlSerializer(typeof(Level), SerializerInfo.GetTypes()); //level = (Level)xml.Deserialize(file); level = Content.Load<Level>("xnaXmlTest"); break; } #else level = Content.Load<Level>("xnaXmlTest2"); #endif level.Load(this); Entity player = level.GetFirstEntityByName("PLAYER"); camera.FollowSprite(player.Aspects.FindFirst<SpriteAspect>()); }