public static Entity MakeCharacterEntity(Game game, string name, string image, Vector2 position, Rectangle frame) { var e = new Entity() { Game = game, Name = name }; var renderer = new RenderingAspect() { Name = "renderer" }; e.Aspects.Add(renderer); var sprite = new SpriteAspect() { Name = "sprite", ImageFile = image, ImageFrame = frame, OrientationAspect = "collider", LayerDepth = 0.3f, CoordinateType = CoordinateType.World }; e.Aspects.Add(sprite); var collider = new BoxCollisionAspect() { Name = "collider", Mass = 100, Position = position, IsStatic = false, Dimensions = frame }; e.Aspects.Add(collider); var respawn = new RespawnAspect() { Bounds = new Rectangle(-512, -512, 2048, 1600), RespawnPosition = position }; e.Aspects.Add(respawn); return e; }
protected override void LoadSubclassContent() { var template = new Entity() { IsTemplate = true, Game = Owner.Game, Name = "PROJETILE", Enabled = false }; var projectileSprite = new SpriteAspect() { ImageFile = "Sprites/hobosquirrel", ImageFrame = new Rectangle(0, 154, 19, 12), OwnerID = template.EntityID, OrientationAspect = "orientation", LayerDepth = 0.3f, CoordinateType = CoordinateType.World, Scale = new Vector2(1.5f, 1.5f) }; template.Aspects.Add(projectileSprite); var orientation = new BoxCollisionAspect() { Name = "orientation", OwnerID = template.EntityID, Mass = 50f, CollisionGroup = EntityTemplates.PlayerCollisionGroup, OnCollision = (geom1, geom2, contactList) => { Entity e2 = Entity.GetEntityByID(BoxCollisionAspect.FindEntityByGeomID(geom2.Id)); if (e2 != null && e2.Name == "Enemy1") { e2.Aspects.FindFirst<RespawnAspect>().Respawn(); } return false; } }; template.Aspects.Add(orientation); var rotater = new PinwheelRotaterAspect() { RotationSpeed = .015f, OwnerID = template.EntityID }; template.Aspects.Add(rotater); var age = new AgeAspect() { OwnerID = template.EntityID }; template.Aspects.Add(age); var render = new RenderingAspect() { OwnerID = template.EntityID, Visible = false }; template.Aspects.Add(render); for (int i = 0; i < MaxNumberOfProjectiles; i++) { Projectiles[i] = (Entity)template.Clone(); Projectiles[i].Initialize(); Projectiles[i].LoadContent(); projectileDirections[i] = 1; bool foo = Projectiles[i].Enabled; } }
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; }
public static Entity NewStaticObjectEntity(Game game, string name, string image, Vector2 position, float layerDepth, CoordinateType coordinateType) { Entity e = new Entity(); e.Game = game; e.Name = name; RenderingAspect renderer = new RenderingAspect(); renderer.Name = "renderer"; e.Aspects.Add(renderer); SpriteAspect sprite = new SpriteAspect(); sprite.Name = "sprite"; sprite.ImageFile = image; sprite.OrientationAspect = "collider"; sprite.LayerDepth = layerDepth; sprite.CoordinateType = CoordinateType.World; e.Aspects.Add(sprite); BoxCollisionAspect collider = new BoxCollisionAspect(); collider.Dimensions = sprite.ImageFrame; collider.Name = "collider"; collider.Mass = 100; collider.Position = position; collider.IsStatic = true; e.Aspects.Add(collider); return e; }