Esempio n. 1
0
        public void invoke(PositionChangeRequestEvent eventObject)
        {
            Vector2 distance = Vector2.Zero;

            for (int shapeIndex = 0; shapeIndex < BodyList.Count; shapeIndex++)
            {
                CollisionBody currentShape = this.BodyList[shapeIndex];
                XboxHashSet<CollisionBody> shapeGroup = CollisionManager.Instance.GetBodyGroup(currentShape);

                //for (int secondShapeIndex = 0; secondShapeIndex < shapeGroup.Count; secondShapeIndex++)
                //{
                foreach (CollisionBody secondShape in shapeGroup)
                {
                    //CollisionBody secondShape = shapeGroup[secondShapeIndex];

                    if (secondShape == currentShape) continue;
                    if (this.BodyList.Contains(secondShape)) continue;

                    CollisionResult result = currentShape.Intersect(secondShape, ref distance);

                    if (!result.willIntersect) continue;
                    EventManager.Instance.fireEvent(CollisionEvent.Create(this, currentShape.Owner, secondShape.Owner, result));
                }
            }
        }
Esempio n. 2
0
        public void invoke(PositionChangeRequestEvent eventObject)
        {
            Vector2 movementDistance = eventObject.ProjectedDistance;
            Vector2 totalMovementDistance = Vector2.Zero;

            if (BodyList.Count == 0)
            {
                totalMovementDistance = eventObject.ProjectedDistance;
            }

            for (int shapeIndex = 0; shapeIndex < bodyList.Count; shapeIndex++)
            {
                CollisionBody currentShape = this.bodyList[shapeIndex];
                XboxHashSet<CollisionBody> shapeGroup = CollisionManager.Instance.GetBodyGroup(currentShape);

                //for (int secondShapeIndex = 0; secondShapeIndex < shapeGroup.Count; secondShapeIndex++)
                //{
                foreach (CollisionBody secondShape in shapeGroup)
                {
                    //CollisionBody secondShape = shapeGroup[secondShapeIndex];

                    if (secondShape == currentShape || this.bodyList.Contains(secondShape))
                    {
                        continue;
                    }

                    CollisionResult result = currentShape.Intersect(secondShape, ref movementDistance);

                    if (result.willIntersect)
                    {
                        EventManager.Instance.fireEvent(CollisionEvent.Create(this, currentShape.Owner, secondShape.Owner, result));
                        if (currentShape.Solid && secondShape.Solid)
                        {
                            Vector2.Add(ref movementDistance, ref result.minimumTranslationVector, out movementDistance);
                        }
                    }
                }

                if (movementDistance.X != 0.0f || movementDistance.Y != 0.0f)
                {
                    for (int i = 0; i < bodyList.Count; i++)
                    {
                        CollisionBody shape = this.bodyList[i];
                        CollisionManager.Instance.removeContainer(shape);
                        shape.Offset(movementDistance.X, movementDistance.Y);
                        CollisionManager.Instance.addContainer(shape);
                    }
                }

                Vector2.Add(ref totalMovementDistance, ref movementDistance, out totalMovementDistance);
                movementDistance = Vector2.Zero;
            }

            Vector2 currentPosition = eventObject.CurrentPosition;
            EventManager.Instance.fireEvent(PositionChangedEvent.Create(this.owner, ref currentPosition, ref totalMovementDistance));
        }