/** Remove a joint from physics world.*/ public virtual void RemoveJoint(CCPhysicsJoint joint, bool destroy = true) { if (joint.World != this) { if (destroy) { cp.AssertWarn("physics warnning: the joint is not in this world, it won't be destoried utill the body it conntect is destoried"); } return; } RemoveJointOrDelay(joint); Joints.Remove(joint); joint._world = null; // clean the connection to this joint if (destroy) { if (joint.BodyA != null) { joint.BodyA.RemoveJoint(joint); } if (joint.BodyB != null) { joint.BodyB.RemoveJoint(joint); } // test the distraction is delaied or not if (DelayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } }
public void Move(Direction direction, bool eat) { Point nextPoint; var mod = ApplicationSettings.MatrixSize - 1; switch (direction) { case Direction.Up: var y = (Head.Y - 1) % mod; if (y < 0) { y = mod; } nextPoint = new Point(Head.X, y); break; case Direction.Right: nextPoint = new Point((Head.X + 1) % mod, Head.Y); break; case Direction.Down: nextPoint = new Point(Head.X, (Head.Y + 1) % mod); break; case Direction.Left: var x = (Head.X - 1) % mod; if (x < 0) { x = mod; } nextPoint = new Point(x, Head.Y); break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } if (State[nextPoint.X, nextPoint.Y]) { throw new GameOverException("Invalid coordinate"); } State[nextPoint.X, nextPoint.Y] = true; if (direction != CurrentDirection) { Joints.Insert(0, new Joint(Head, direction)); } if (!eat) { var count = Joints.Count; var end = Joints[count - 1]; State[end.Point.X, end.Point.Y] = false; switch (end.Direction) { case Direction.Up: end.Point.Y--; break; case Direction.Right: end.Point.X++; break; case Direction.Down: end.Point.Y++; break; case Direction.Left: end.Point.X--; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } if (count > 2 && Joints[count - 2].Point.Equals(end.Point)) { Joints.Remove(end); } } Head = nextPoint; }