public static Entity Create( Comps.Item.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = registry.CreateEntity(); registry.AssignComponent( result, new Comps.Item { kind = kind } ); registry.AssignComponent( result, new Comps.Position { data = position } ); // TODO: Figure out what shape to assign registry.AssignComponent( result, new Comps.Shapes.Rectangle { data = new Physical.Rectangle(64.0f, 64.0f) } ); return(result); }
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 ); } }
private static void Drop( Comps.Inventory inventoryComp, Comps.Position positionComp, Ecs.Registry registry ) { foreach (KeyValuePair <Comps.Item.Kind, StorageInfo> pair in inventoryComp.data) { Comps.Item.Kind itemKind = pair.Key; StorageInfo storageInfo = pair.Value; for (int i = 0; i < storageInfo.Count; i++) { Entity itemEntity = Factories.Item.Create( itemKind, positionComp.data, registry ); registry.AssignComponent( itemEntity, new Comps.Velocity { data = 20 * Global.random.NextPhysicalVector2(), decay = 0.8f } ); } } }
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 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 Entity Create( Comps.Character.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = registry.CreateEntity(); registry.AssignComponent( result, new Comps.Position { data = position } ); registry.AssignComponent( result, new Comps.Orientations.Cardinal { data = Physical.Orientation.Cardinal.Right } ); registry.AssignComponent( result, GetInventory(kind) ); registry.AssignComponent( result, new Comps.Velocity() { data = PhysicalVector2.Zero } ); registry.AssignComponent( result, new Comps.Solid() ); registry.AssignComponent( result, new Comps.Character { kind = kind } ); registry.AssignComponent( result, new Comps.Shapes.Rectangle { data = GetShape(kind) } ); return(result); }
public static Entity Create( Comps.Door.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = registry.CreateEntity(); registry.AssignComponent( result, new Comps.Door { kind = kind } ); registry.AssignComponent( result, new Comps.Solid { unmovable = true } ); registry.AssignComponent( result, new Comps.Position { data = position } ); registry.AssignComponent( result, new Comps.Shapes.Rectangle { data = new Physical.Rectangle(32.0f * 6, 32.0f * 2) } ); return(result); }
public static Entity CreateEnemy( Comps.Character.Kind kind, PhysicalVector2 position, Ecs.Registry registry ) { var result = Create(kind, position, registry); registry.AssignComponent( result, GetAutonomous(kind) ); return(result); }
public static Entity CreatePlayer( Comps.Character.Kind kind, PhysicalVector2 position, ClientId clientId, Ecs.Registry registry ) { var result = Create(kind, position, registry); registry.AssignComponent( result, new Comps.Playable { clientId = clientId } ); return(result); }
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); }