Ejemplo n.º 1
0
        private static void HandleCollision(
            Ecs.Registry registry,
            Queue <Entity> toRemove,
            Entity entity,
            Comps.Solid solidComp,
            Comps.Position positionComp,
            Comps.Shapes.Rectangle rectangleComp,
            PhysicalVector2 tilePosition,
            Rectangle tileRectangle
            )
        {
            if (solidComp.ephemeral)
            {
                toRemove.Enqueue(entity);
            }
            else
            {
                PhysicalVector2 correction = GetMinCorrection(
                    rectangleComp.data, positionComp.data,
                    tileRectangle, tilePosition
                    );

                positionComp.data += correction;
            }
        }
Ejemplo n.º 2
0
        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
                    }
                        );
                }
            }
        }
Ejemplo n.º 3
0
        private static void HandleCollision(
            Ecs.Registry registry,
            Queue <Entity> toRemove,
            Entity entity1,
            Comps.Solid entity1Solid,
            Comps.Position entity1Pos,
            Comps.Shapes.Rectangle entity1Rect,
            Entity entity2,
            Comps.Solid entity2Solid,
            Comps.Position entity2Pos,
            Comps.Shapes.Rectangle entity2Rect
            )
        {
            if (entity1Solid.ephemeral)
            {
                toRemove.Enqueue(entity1);
                return;
            }

            if (entity2Solid.ephemeral)
            {
                toRemove.Enqueue(entity2);
                return;
            }

            Vector2 correction = GetMinCorrection(
                entity1Rect.data, entity1Pos.data,
                entity2Rect.data, entity2Pos.data
                );

            // Ignore the case where both are unmovable
            if (entity1Solid.unmovable)
            {
                entity2Pos.data -= correction;
            }
            else if (entity2Solid.unmovable)
            {
                entity1Pos.data += correction;
            }
            else
            {
                entity1Pos.data += correction / 2f;
                entity2Pos.data -= correction / 2f;
            }
        }