Esempio n. 1
0
        internal void Destroy()
        {
            bool flag = this.Shape.ShapeType == ShapeType.Polygon;

            if (flag)
            {
                ((PolygonShape)this.Shape).Vertices.AttachedToBody = false;
            }
            Debug.Assert(this.ProxyCount == 0);
            this.Proxies         = null;
            this.Shape           = null;
            this.UserData        = null;
            this.BeforeCollision = null;
            this.OnCollision     = null;
            this.OnSeparation    = null;
            this.AfterCollision  = null;
            bool flag2 = this.Body._world.FixtureRemoved != null;

            if (flag2)
            {
                this.Body._world.FixtureRemoved(this);
            }
            this.Body._world.FixtureAdded   = null;
            this.Body._world.FixtureRemoved = null;
            this.OnSeparation = null;
            this.OnCollision  = null;
        }
Esempio n. 2
0
 private void DispatchCollisionEvent(OnCollisionEventHandler delegateFunc, Collision collision)
 {
     if (delegateFunc != null && IsAcceptableCollider(collision.collider))
     {
         delegateFunc(gameObject, collision);
     }
 }
Esempio n. 3
0
        internal void Destroy()
        {
#if DEBUG
            if (ShapeType == ShapeType.Polygon)
            {
                ((PolygonShape)Shape).Vertices.AttachedToBody = false;
            }
#endif

            // The proxies must be destroyed before calling this.
            Debug.Assert(ProxyCount == 0);

            // Free the proxy array.
            Proxies = null;
            Shape   = null;

            //FPE: We set the userdata to null here to help prevent bugs related to stale references in GC
            UserData = null;

            BeforeCollision = null;
            OnCollision     = null;
            OnSeparation    = null;
            AfterCollision  = null;

            if (Body.World.FixtureRemoved != null)
            {
                Body.World.FixtureRemoved(this);
            }

            Body.World.FixtureAdded   = null;
            Body.World.FixtureRemoved = null;
            OnSeparation = null;
            OnCollision  = null;
        }
        private void CreateSantaCollisionComponent()
        {
            OnCollisionEventHandler print_collide = (sender, other, contact) =>
            {
                Debug.WriteLine("entity controlled:" + sender.Body.Tag + " entity collide:" + other.Body.Tag);
                Debug.WriteLine("res" + contact.FixtureA.Restitution);
                //TODO Fix missing/wrong code
                //  var tmp = new RuleManager.EngineMessage();
                // tmp.Action = RuleManager.ActionEngine.Collision;
                // tmp.entitybase = EntityManager.GetAllEntities().Find(i =>  i.Guid == (Guid)sender.Tag);
                //tmp.entityFocus = EntityManager.GetAllEntities().Find(i => i.Guid == (Guid)other.Tag);
                //   RuleManager.EngineAction.Enqueue(tmp);
                return(true);
            };

            santaEnt.AddComponent(CollisionComponentBuilder.CreateNew()
                                  .Init(santaEnt, 25)
                                  .SetBodyType(BodyType.Dynamic)
                                  .SetCollidesWith(Category.All)
                                  .SetCategoriesCollision(Category.Cat1)
                                  //   .SetMass(1f)
                                  // .SetInertia(1f)
                                  .SetLinearVelocity(new Vector2(300, 0))
                                  .SetRestitution(1f)
                                  //  .SetIgnoreCCD(true)
                                  //       .SetForce(100f)
                                  .AddOnCollisionEventHandler(print_collide)
                                  .Build());
        }
Esempio n. 5
0
        internal void Destroy()
        {
            // The proxies must be destroyed before calling this.
            Debug.Assert(ProxyCount == 0);

            // Free the proxy array.
            Proxies = null;
            Shape   = null;

            BeforeCollision = null;
            OnCollision     = null;
            OnSeparation    = null;
            AfterCollision  = null;

            if (Body.World.FixtureRemoved != null)
            {
                Body.World.FixtureRemoved(this);
            }

            //GW: Wtf were this 2 lines present? FixtureAdded is a global callback
            //Body.World.FixtureAdded = null;
            //Body.World.FixtureRemoved = null;

            OnSeparation = null;
            OnCollision  = null;
        }
Esempio n. 6
0
        internal void destroy()
        {
#if DEBUG
            if (shape.shapeType == ShapeType.Polygon)
            {
                ((PolygonShape)shape).vertices.attachedToBody = false;
            }
#endif

            // The proxies must be destroyed before calling this.
            Debug.Assert(proxyCount == 0);

            // Free the proxy array.
            proxies = null;
            shape   = null;

            //FPE: We set the userdata to null here to help prevent bugs related to stale references in GC
            userData = null;

            beforeCollision = null;
            onCollision     = null;
            onSeparation    = null;
            afterCollision  = null;

            if (body._world.onFixtureRemoved != null)
            {
                body._world.onFixtureRemoved(this);
            }

            body._world.onFixtureAdded   = null;
            body._world.onFixtureRemoved = null;
            onSeparation = null;
            onCollision  = null;
        }
 public BodyConstructor WithOnCollision(string fixtureName, OnCollisionEventHandler handler)
 {
     if (fixtureBuilderData.ContainsKey(fixtureName))
     {
         var newData = new FixtureData {
             OnCollision = handler
         };
         fixtureBuilderData.Add(fixtureName, newData);
     }
     else
     {
         fixtureBuilderData[fixtureName].OnCollision = handler;
     }
     return(this);
 }
Esempio n. 8
0
 protected override void Recycle(bool isReleasing)
 {
     if (isReleasing)
     {
         BroadphaseProxy.Recycle();
     }
     WorldTransform   = Matrix3.Identity;
     RemoveNextUpdate = false;
     Owner            = null;
     Shape            = null;
     BeforeCollision  = null;
     OnCollision      = null;
     AfterCollision   = null;
     OnSeparation     = null;
     base.Recycle(isReleasing);
 }
Esempio n. 9
0
        internal void Destroy()
        {
            // The proxies must be destroyed before calling this.
            Debug.Assert(ProxyCount == 0);

            // Free the proxy array.
            Proxies = null;
            Shape   = null;

            BeforeCollision = null;
            OnCollision     = null;
            OnSeparation    = null;
            AfterCollision  = null;

            if (Body.World.FixtureRemoved != null)
            {
                Body.World.FixtureRemoved(this);
            }
        }
Esempio n. 10
0
        public CursorModel(ContentManager content, World world, GamepadController pad, 
            SmashBros.Controllers.GamepadController.NavigationKey navigationMethod,
           OnCollisionEventHandler col, OnSeparationEventHandler sep,bool enabled = false)
        {
            Cursor = new Sprite(content, "Cursors/Player" + pad.PlayerIndex, 70, 70, 280 * pad.PlayerIndex + 100, 680);
            Cursor.BoundRect(world, 5, 5, BodyType.Dynamic);
            Cursor.StaticPosition = true;
            Cursor.Category = Category.Cat4;
            Cursor.CollidesWith = Category.Cat5;
            Cursor.Layer = 1002;
            Cursor.Mass = 1;
            Cursor.UserData = pad.PlayerIndex;
            Cursor.BoundBox.IgnoreGravity = true;
            Cursor.Origin = new Vector2(50, 20);

            this.Pad = pad;
            this.Navigation = navigationMethod;
            this.OnCollision = col;
            this.OnSeparation = sep;
            this.Enabled = enabled;
        }
Esempio n. 11
0
        public CursorModel(ContentManager content, World world, GamepadController pad,
                           SmashBros.Controllers.GamepadController.NavigationKey navigationMethod,
                           OnCollisionEventHandler col, OnSeparationEventHandler sep, bool enabled = false)
        {
            Cursor = new Sprite(content, "Cursors/Player" + pad.PlayerIndex, 70, 70, 280 * pad.PlayerIndex + 100, 680);
            Cursor.BoundRect(world, 5, 5, BodyType.Dynamic);
            Cursor.StaticPosition         = true;
            Cursor.Category               = Category.Cat4;
            Cursor.CollidesWith           = Category.Cat5;
            Cursor.Layer                  = 1002;
            Cursor.Mass                   = 1;
            Cursor.UserData               = pad.PlayerIndex;
            Cursor.BoundBox.IgnoreGravity = true;
            Cursor.Origin                 = new Vector2(50, 20);

            this.Pad          = pad;
            this.Navigation   = navigationMethod;
            this.OnCollision  = col;
            this.OnSeparation = sep;
            this.Enabled      = enabled;
        }
Esempio n. 12
0
 public BodyConstructor WithOnCollision(OnCollisionEventHandler handler)
 {
     anonymousFixtureData.OnCollision = handler;
     return(this);
 }
Esempio n. 13
0
        internal void Destroy()
        {
            // The proxies must be destroyed before calling this.
            Debug.Assert(ProxyCount == 0);

            // Free the proxy array.
            Proxies = null;
            Shape = null;

            BeforeCollision = null;
            OnCollision = null;
            OnSeparation = null;
            AfterCollision = null;

            if (Body.World.FixtureRemoved != null)
            {
                Body.World.FixtureRemoved(this);
            }

            Body.World.FixtureAdded = null;
            Body.World.FixtureRemoved = null;
            OnSeparation = null;
            OnCollision = null;
        }
Esempio n. 14
0
 protected override void Recycle(bool isReleasing)
 {
     if (isReleasing)
         BroadphaseProxy.Recycle();
     WorldTransform = Matrix3.Identity;
     RemoveNextUpdate = false;
     Owner = null;
     Shape = null;
     BeforeCollision = null;
     OnCollision = null;
     AfterCollision = null;
     OnSeparation = null;
     base.Recycle(isReleasing);
 }
        private void dropCurrentPiece()
        {
            if (currentPiece != null)
            {
                if (isCurrentPieceBlocked())
                {
                    currentPiece.body.Position = getSpawnPosition();
                }
                else
                {
                    currentPiece.body.LinearVelocity = Vector2.Zero;
                    currentPiece.body.ResetDynamics();
                    currentPiece.body.OnCollision -= currentPieceCollide;
                    currentPiece.body.OnSeparation -= currentPieceSeparate;
                    if (currentCheat != null)
                    {
                        currentCheat.body.OnCollision -= currentPieceCollide;
                        currentCheat.body.OnSeparation -= currentPieceSeparate;
                    }

                    if (currentPieceRotation != null)
                    {
                        _world.RemoveJoint(currentPieceRotation);
                        currentPieceRotation = null;
                    }

                    currentPiece = null;
                    currentPieceCollide = null;
                    currentCheat = null;

                    Game1.Timers.Create(SPAWN_TIME, false, Spawn);
                }
            }
        }
        private void Spawn(Utility.Timer timer)
        {
            if (nextPiece == null)
            {
                nextPiece = getRandomTetrisPiece();
            }

            currentPiece = nextPiece;
            currentPieceMaxLen = Math.Max(currentPiece.shape.GetLength(0), currentPiece.shape.GetLength(1));
            currentPiece.body.Position = getSpawnPosition();
            currentPieceCollide = new OnCollisionEventHandler(currentPieceCollision);
            currentPieceSeparate = new OnSeparationEventHandler(currentPieceSeparation);
            currentPiece.body.OnCollision += currentPieceCollide;
            currentPiece.body.OnSeparation += currentPieceSeparate;
            currentPieceRotation = JointFactory.CreateFixedAngleJoint(_world, currentPiece.body);
            pieces.Add(currentPiece);
            activePieces.Add(currentPiece);

            currentCheat = null;
            --countdownToCheat;
            if (countdownToCheat < 0)
            {
                currentCheat = new TetrisPiece(_world, tetrisTextures[2], tetrisShapes[2], currentPiece.body.WorldCenter + new Vector2(1, -2));
                currentCheat.body.FixedRotation = true;
                currentCheat.body.Rotation = (float)Math.PI / 2;
                currentCheat.body.OnCollision += currentPieceCollide;
                currentCheat.body.OnSeparation += currentPieceSeparate;
                JointFactory.CreateRevoluteJoint(_world, currentCheat.body, currentPiece.body, currentPiece.body.LocalCenter);
                pieces.Add(currentCheat);
                activePieces.Add(currentCheat);
                countdownToCheat = 5;
            }

            currentPiece.body.Enabled = true;
            if(currentCheat!=null) currentCheat.body.Enabled = true;

            nextPiece = getRandomTetrisPiece();

            //Debug.Print("Spawn new tetris piece at: {0}, {1}", currentPiece.body.Position.X, currentPiece.body.Position.Y);
        }
Esempio n. 17
0
 public void AddCollisionHandler(OnCollisionEventHandler eventHandler)
 {
     m_body.OnCollision += eventHandler;
 }
Esempio n. 18
0
 public CollisionComponentBuilder AddOnCollisionEventHandler(OnCollisionEventHandler collisionEventHandler)
 {
     _collisionComponent.AddOnCollisionHandler(collisionEventHandler);
     return(this);
 }
Esempio n. 19
0
 public void setOnCollisionFunction(OnCollisionEventHandler onCollisionFunc)
 {
     RigidBody.OnCollision += onCollisionFunc;
 }
Esempio n. 20
0
        internal void Destroy()
        {
#if DEBUG
            if (ShapeType == ShapeType.Polygon)
                ((PolygonShape)Shape).Vertices.AttachedToBody = false;
#endif

            // The proxies must be destroyed before calling this.
            Debug.Assert(ProxyCount == 0);

            // Free the proxy array.
            Proxies = null;
            Shape = null;

            //FPE: We set the userdata to null here to help prevent bugs related to stale references in GC
            UserData = null;

            BeforeCollision = null;
            OnCollision = null;
            OnSeparation = null;
            AfterCollision = null;

            if (Body.World.FixtureRemoved != null)
            {
                Body.World.FixtureRemoved(this);
            }

            Body.World.FixtureAdded = null;
            Body.World.FixtureRemoved = null;
            OnSeparation = null;
            OnCollision = null;
        }
Esempio n. 21
0
        internal void Update(ContactManager contactManager)
        {
            Body body  = this.FixtureA.Body;
            Body body2 = this.FixtureB.Body;
            bool flag  = this.FixtureA == null || this.FixtureB == null;

            if (!flag)
            {
                bool flag2 = !ContactManager.CheckCollisionConditions(this.FixtureA, this.FixtureB);
                if (flag2)
                {
                    this.Enabled = false;
                }
                else
                {
                    Manifold manifold = this.Manifold;
                    this.Enabled = true;
                    bool isTouching = this.IsTouching;
                    bool flag3      = this.FixtureA.IsSensor || this.FixtureB.IsSensor;
                    bool flag4      = flag3;
                    bool flag5;
                    if (flag4)
                    {
                        Shape shape  = this.FixtureA.Shape;
                        Shape shape2 = this.FixtureB.Shape;
                        flag5 = Collision.TestOverlap(shape, this.ChildIndexA, shape2, this.ChildIndexB, ref body._xf, ref body2._xf);
                        this.Manifold.PointCount = 0;
                    }
                    else
                    {
                        this.Evaluate(ref this.Manifold, ref body._xf, ref body2._xf);
                        flag5 = (this.Manifold.PointCount > 0);
                        for (int i = 0; i < this.Manifold.PointCount; i++)
                        {
                            ManifoldPoint manifoldPoint = this.Manifold.Points[i];
                            manifoldPoint.NormalImpulse  = 0f;
                            manifoldPoint.TangentImpulse = 0f;
                            ContactID id = manifoldPoint.Id;
                            for (int j = 0; j < manifold.PointCount; j++)
                            {
                                ManifoldPoint manifoldPoint2 = manifold.Points[j];
                                bool          flag6          = manifoldPoint2.Id.Key == id.Key;
                                if (flag6)
                                {
                                    manifoldPoint.NormalImpulse  = manifoldPoint2.NormalImpulse;
                                    manifoldPoint.TangentImpulse = manifoldPoint2.TangentImpulse;
                                    break;
                                }
                            }
                            this.Manifold.Points[i] = manifoldPoint;
                        }
                        bool flag7 = flag5 != isTouching;
                        if (flag7)
                        {
                            body.Awake  = true;
                            body2.Awake = true;
                        }
                    }
                    this.IsTouching = flag5;
                    bool flag8 = !isTouching;
                    if (flag8)
                    {
                        bool flag9 = flag5;
                        if (flag9)
                        {
                            bool flag10 = true;
                            bool flag11 = true;
                            bool flag12 = this.FixtureA.OnCollision != null;
                            if (flag12)
                            {
                                Delegate[] invocationList = this.FixtureA.OnCollision.GetInvocationList();
                                for (int k = 0; k < invocationList.Length; k++)
                                {
                                    OnCollisionEventHandler onCollisionEventHandler = (OnCollisionEventHandler)invocationList[k];
                                    flag10 = (onCollisionEventHandler(this.FixtureA, this.FixtureB, this) & flag10);
                                }
                            }
                            bool flag13 = this.FixtureB.OnCollision != null;
                            if (flag13)
                            {
                                Delegate[] invocationList2 = this.FixtureB.OnCollision.GetInvocationList();
                                for (int l = 0; l < invocationList2.Length; l++)
                                {
                                    OnCollisionEventHandler onCollisionEventHandler2 = (OnCollisionEventHandler)invocationList2[l];
                                    flag11 = (onCollisionEventHandler2(this.FixtureB, this.FixtureA, this) & flag11);
                                }
                            }
                            this.Enabled = (flag10 & flag11);
                            bool flag14 = (flag10 & flag11) && contactManager.BeginContact != null;
                            if (flag14)
                            {
                                this.Enabled = contactManager.BeginContact(this);
                            }
                            bool flag15 = !this.Enabled;
                            if (flag15)
                            {
                                this.IsTouching = false;
                            }
                        }
                    }
                    else
                    {
                        bool flag16 = !flag5;
                        if (flag16)
                        {
                            bool flag17 = this.FixtureA != null && this.FixtureA.OnSeparation != null;
                            if (flag17)
                            {
                                this.FixtureA.OnSeparation(this.FixtureA, this.FixtureB);
                            }
                            bool flag18 = this.FixtureB != null && this.FixtureB.OnSeparation != null;
                            if (flag18)
                            {
                                this.FixtureB.OnSeparation(this.FixtureB, this.FixtureA);
                            }
                            bool flag19 = contactManager.EndContact != null;
                            if (flag19)
                            {
                                contactManager.EndContact(this);
                            }
                        }
                        else
                        {
                            bool flag20 = contactManager.StayContact != null;
                            if (flag20)
                            {
                                contactManager.StayContact(this);
                            }
                        }
                    }
                    bool flag21 = flag3;
                    if (!flag21)
                    {
                        bool flag22 = contactManager.PreSolve != null;
                        if (flag22)
                        {
                            contactManager.PreSolve(this, ref manifold);
                        }
                    }
                }
            }
        }
 public BodyConstructor WithOnCollision(OnCollisionEventHandler handler)
 {
     anonymousFixtureData.OnCollision = handler;
     return this;
 }
 public BodyConstructor WithOnCollision(string fixtureName, OnCollisionEventHandler handler)
 {
     if (fixtureBuilderData.ContainsKey(fixtureName))
     {
         var newData = new FixtureData { OnCollision = handler };
         fixtureBuilderData.Add(fixtureName, newData);
     }
     else
         fixtureBuilderData[fixtureName].OnCollision = handler;
     return this;
 }