Ejemplo n.º 1
0
        public PlungerCollider(PlungerComponent comp, PlungerColliderComponent collComp, ColliderInfo info) : this()
        {
            _header.Init(info, ColliderType.Plunger);

            var zHeight = comp.PositionZ;
            var x       = comp.Position.x - comp.Width;
            var y       = comp.Position.y + comp.Height;
            var x2      = comp.Position.x + comp.Width;

            // static
            LineSegBase = new LineCollider(new float2(x, y), new float2(x2, y), zHeight, zHeight + Plunger.PlungerHeight, info);
            JointBase0  = new LineZCollider(new float2(x, y), zHeight, zHeight + Plunger.PlungerHeight, info);
            JointBase1  = new LineZCollider(new float2(x2, y), zHeight, zHeight + Plunger.PlungerHeight, info);

            var frameEnd = comp.Position.y - collComp.Stroke;

            Bounds = new ColliderBounds(_header.Entity, _header.Id, new Aabb(
                                            x - 0.1f,
                                            x2 + 0.1f,
                                            frameEnd - 0.1f,
                                            y + 0.1f,
                                            zHeight,
                                            zHeight + Plunger.PlungerHeight
                                            ));
        }
Ejemplo n.º 2
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            Convert(entity, dstManager);
            var table = gameObject.GetComponentInParent <TableBehavior>().Item;

            transform.GetComponentInParent <Player>().RegisterPlunger(Item, entity, gameObject);

            Item.Init(table);
            var hit = Item.PlungerHit;

            hit.SetIndex(entity.Index, entity.Version);

            dstManager.AddComponentData(entity, new PlungerStaticData {
                MomentumXfer    = data.MomentumXfer,
                ScatterVelocity = data.ScatterVelocity,
                FrameStart      = hit.FrameBottom,
                FrameEnd        = hit.FrameTop,
                FrameLen        = hit.FrameLen,
                RestPosition    = hit.RestPos,
                IsAutoPlunger   = data.AutoPlunger,
                SpeedFire       = data.SpeedFire,
                NumFrames       = Item.MeshGenerator.NumFrames
            });

            dstManager.AddComponentData(entity, new PlungerColliderData {
                JointEnd0    = LineZCollider.Create(hit.JointEnd[0]),
                JointEnd1    = LineZCollider.Create(hit.JointEnd[1]),
                LineSegEnd   = LineCollider.Create(hit.LineSegEnd),
                LineSegSide0 = LineCollider.Create(hit.LineSegSide[0]),
                LineSegSide1 = LineCollider.Create(hit.LineSegSide[1])
            });

            dstManager.AddComponentData(entity, new PlungerMovementData {
                FireBounce     = 0f,
                Position       = hit.Position,
                RetractMotion  = false,
                ReverseImpulse = 0f,
                Speed          = 0f,
                TravelLimit    = hit.FrameTop,
                FireSpeed      = 0f,
                FireTimer      = 0
            });

            dstManager.AddComponentData(entity, new PlungerVelocityData {
                Mech0            = 0f,
                Mech1            = 0f,
                Mech2            = 0f,
                PullForce        = 0f,
                InitialSpeed     = 0f,
                AutoFireTimer    = 0,
                AddRetractMotion = false,
                RetractWaitLoop  = 0,
                MechStrength     = data.MechStrength
            });
        }
        private void GenerateGateCollider(ICollection <ICollider> colliders, float height, float radAngle)
        {
            var halfLength = _data.Length * 0.5f;
            var sn         = math.sin(radAngle);
            var cs         = math.cos(radAngle);
            var v1         = new float2(
                _data.PosX - cs * (halfLength + PhysicsConstants.PhysSkin),
                _data.PosY - sn * (halfLength + PhysicsConstants.PhysSkin)
                );
            var v2 = new float2(
                _data.PosX + cs * (halfLength + PhysicsConstants.PhysSkin),
                _data.PosY + sn * (halfLength + PhysicsConstants.PhysSkin)
                );

            var lineSeg0 = new LineCollider(v1, v2, height, height + 2.0f * PhysicsConstants.PhysSkin, _api.GetColliderInfo());
            var lineSeg1 = new LineCollider(v2, v1, height, height + 2.0f * PhysicsConstants.PhysSkin, _api.GetColliderInfo());

            colliders.Add(new GateCollider(in lineSeg0, in lineSeg1, _api.GetColliderInfo()));
        }
Ejemplo n.º 4
0
        public SpinnerCollider(SpinnerComponent component, float height, ColliderInfo info) : this()
        {
            _header.Init(info, ColliderType.Spinner);

            var halfLength = component.Length * 0.5f;

            var radAngle = math.radians(component.Rotation);
            var sn       = math.sin(radAngle);
            var cs       = math.cos(radAngle);

            var v1 = new float2(
                component.Position.x - cs * (halfLength + PhysicsConstants.PhysSkin),                 // through the edge of the
                component.Position.y - sn * (halfLength + PhysicsConstants.PhysSkin)                  // spinner
                );
            var v2 = new float2(
                component.Position.x + cs * (halfLength + PhysicsConstants.PhysSkin),                 // oversize by the ball radius
                component.Position.y + sn * (halfLength + PhysicsConstants.PhysSkin)                  // this will prevent clipping
                );

            LineSeg0 = new LineCollider(v1, v2, height, height + 2.0f * PhysicsConstants.PhysSkin, info);
            LineSeg1 = new LineCollider(v2, v1, height, height + 2.0f * PhysicsConstants.PhysSkin, info);

            Bounds = LineSeg0.Bounds;
        }
Ejemplo n.º 5
0
        public static void Create(BlobBuilder builder, HitObject src, ref BlobPtr <Collider> dest)
        {
            switch (src)
            {
            case KickerHit kickerHit:
                CircleCollider.Create(builder, kickerHit, ref dest, ColliderType.KickerCircle);
                break;

            case TriggerHitCircle triggerHitCircle:
                CircleCollider.Create(builder, triggerHitCircle, ref dest, ColliderType.TriggerCircle);
                break;

            case TriggerHitLineSeg triggerHitLine:
                LineCollider.Create(builder, triggerHitLine, ref dest, ColliderType.TriggerLine);
                break;

            case BumperHit bumperHit:
                CircleCollider.Create(builder, bumperHit, ref dest, ColliderType.Bumper);
                break;

            case HitCircle hitCircle:
                CircleCollider.Create(builder, hitCircle, ref dest);
                break;

            case LineSegSlingshot lineSegSlingshot:
                LineSlingshotCollider.Create(builder, lineSegSlingshot, ref dest);
                break;

            case FlipperHit flipperHit:
                FlipperCollider.Create(builder, flipperHit, ref dest);
                break;

            case GateHit gateHit:
                GateCollider.Create(builder, gateHit, ref dest);
                break;

            case LineSeg lineSeg:
                LineCollider.Create(builder, lineSeg, ref dest);
                break;

            case HitLine3D hitLine3D:
                Line3DCollider.Create(builder, hitLine3D, ref dest);
                break;

            case HitLineZ hitLineZ:
                LineZCollider.Create(builder, hitLineZ, ref dest);
                break;

            case HitPoint hitPoint:
                PointCollider.Create(builder, hitPoint, ref dest);
                break;

            case HitPlane hitPlane:
                PlaneCollider.Create(builder, hitPlane, ref dest);
                break;

            case PlungerHit plungerCollider:
                PlungerCollider.Create(builder, plungerCollider, ref dest);
                break;

            case SpinnerHit spinnerHit:
                SpinnerCollider.Create(builder, spinnerHit, ref dest);
                break;

            case HitTriangle hitTriangle:
                TriangleCollider.Create(builder, hitTriangle, ref dest);
                break;

            default:
                Logger.Warn("Unsupported collider {0}, skipping.", src.GetType().Name);
                break;
            }
        }