public static void Run( Ecs.Registry registry, ContentManager contentManager ) { HashSet <Ecs.Entity> entities = registry.GetEntities( typeof(Comps.Character), typeof(Comps.Orientations.Cardinal) ); foreach (Ecs.Entity entity in entities) { var characterComp = registry .GetComponentUnsafe <Comps.Character>(entity); var orientationComp = registry .GetComponentUnsafe <Comps.Orientations.Cardinal>(entity); CompsExt.Visibles.Sprite sprite = CreateVisibleComp( characterComp, orientationComp, contentManager ); registry.AssignComponent( entity, sprite ); } }
public static void Run( Ecs.Registry ecsRegistry, SpriteBatch spriteBatch, Camera camera ) { HashSet <Ecs.Entity> entities = ecsRegistry.GetEntities( typeof(SpriteComp), typeof(PositionComp) ); foreach (Ecs.Entity entity in entities) { SpriteComp spriteComp = ecsRegistry .GetComponentUnsafe <SpriteComp>(entity); PositionComp positionComp = ecsRegistry .GetComponentUnsafe <PositionComp>(entity); if (camera.IsInRange(positionComp.data)) { Render(spriteComp, positionComp, spriteBatch, camera); } } }
public static void Run( Ecs.Registry registry, ContentManager contentManager ) { HashSet <Ecs.Entity> entities = registry.GetEntities( typeof(Comps.Projectile), typeof(Comps.Orientations.Cardinal) ); foreach (Ecs.Entity entity in entities) { var projectileComp = registry .GetComponentUnsafe <Comps.Projectile>(entity); if (!IsVisible(projectileComp.kind)) { continue; } var orientationComp = registry .GetComponentUnsafe <Comps.Orientations.Cardinal>(entity); CompsExt.Visibles.Sprite sprite = CreateVisibleComp( projectileComp, orientationComp, contentManager ); registry.AssignComponent( entity, sprite ); } }
public static void Run( Ecs.Registry registry, ContentManager contentManager ) { HashSet <Ecs.Entity> entities = registry.GetEntities( typeof(ItemComp) ); foreach (Ecs.Entity entity in entities) { var itemComp = registry .GetComponentUnsafe <ItemComp>(entity); VisibleComp sprite = CreateVisibleComp( itemComp, contentManager ); registry.AssignComponent( entity, sprite ); } }
public static void Run( Ecs.Registry registry, ContentManager contentManager ) { HashSet <Ecs.Entity> entities = registry.GetEntities( typeof(Comps.Door) ); foreach (Ecs.Entity entity in entities) { var obstacleComp = registry .GetComponentUnsafe <Comps.Door>(entity); CompsExt.Visibles.Sprite sprite = CreateVisibleComp( obstacleComp, contentManager ); registry.AssignComponent( entity, sprite ); } }
public static Entity Create( Comps.Projectile.Kind kind, Entity owner, Ecs.Registry registry ) { // Assume that `owner` has position and orientation // components var playerPositionComp = registry .GetComponentUnsafe <Comps.Position>(owner); var playerRectangleComp = registry .GetComponentUnsafe <Comps.Shapes.Rectangle>(owner); var playerOrientationComp = registry .GetComponentUnsafe <Comps.Orientations.Cardinal>(owner); var playerPosRectangle = new Physical.PosRectangle( playerPositionComp.data, playerRectangleComp.data ); // Create projectile Physical.Rectangle rectangle = new Physical.Rectangle( 16.0f * 4, 16.0f * 4 ); PhysicalVector2 position = GetStartingPosition( playerPosRectangle, playerOrientationComp.data, rectangle ); var projectileEntity = registry.CreateEntity(); registry.AssignComponent( projectileEntity, new Comps.Shapes.Rectangle { data = rectangle } ); registry.AssignComponent( projectileEntity, new Comps.Position { data = position } ); registry.AssignComponent( projectileEntity, (Comps.Orientations.Cardinal)playerOrientationComp.Clone() ); PhysicalVector2 velocity = playerOrientationComp.data.GetPhysicalVector2() * GetStartingSpeed(kind); registry.AssignComponent( projectileEntity, new Comps.Velocity { data = velocity, decay = 1.0f } ); registry.AssignComponent( projectileEntity, new Comps.Projectile { kind = kind, ownerId = owner.id } ); if (IsDamaging(kind)) { registry.AssignComponent( projectileEntity, new Comps.Damaging { damage = 1, attackerId = owner.id } ); } registry.AssignComponent( projectileEntity, new Comps.Lifetime { ticks = GetLifetime(kind) } ); registry.AssignComponent( projectileEntity, new Comps.Solid { ephemeral = true } ); return(projectileEntity); }