public CollisionArgs(IEntityPhysics collidingObject, IEntity hitObject, float hitAngle, float penetration) { this.hitObject = hitObject; this.collidingObject = collidingObject; this.hitObjectAngle = hitAngle; this.penetration = penetration; }
private static bool checkCollisions(IEntityPhysics moveableEntity, IEntity otherEntity) { Shape moveableEntityBoundingBox = moveableEntity.boundingBox(); Shape otherEntityBoundingBox = otherEntity.boundingBox(); if (moveableEntityBoundingBox is Circle && otherEntityBoundingBox is Circle) { Circle movingEntityCircle = (Circle)moveableEntityBoundingBox; Circle otherEntityCircle = (Circle)otherEntityBoundingBox; float penetration; if ((penetration = circleCollision(movingEntityCircle, otherEntityCircle)) > 0) { float hitAngle = MyMathHelper.angleBetween(otherEntityCircle.origin, movingEntityCircle.origin); EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, otherEntity, hitAngle, penetration)); return true; } } else if (moveableEntityBoundingBox is Circle && otherEntityBoundingBox is QuadCollection) { Circle movingEntityCircle = (Circle)moveableEntityBoundingBox; QuadCollection quadCollection = (QuadCollection)otherEntityBoundingBox; foreach (Quad quad in quadCollection.quads) { KeyValuePair<float?, float> collisionAngle; if ((collisionAngle = quadCircleCollision(quad, movingEntityCircle)).Key != null) { EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, otherEntity, (float)collisionAngle.Key, collisionAngle.Value)); return true; } } } else { Debug.Assert(false, "No Collision defined for types " + moveableEntityBoundingBox.GetType() + " " + otherEntityBoundingBox.GetType()); } return false; }
static bool wallCollision(IEntityPhysics moveableEntity) { if (moveableEntity.boundingBox().leftMostPoint() < 0) { EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, null, MathHelper.Pi, MathHelper.Distance(0, moveableEntity.boundingBox().leftMostPoint()))); return true; } else if (moveableEntity.boundingBox().rightMostPoint() > Game1.graphics.GraphicsDevice.Viewport.Width) { EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, null, 0, MathHelper.Distance(Game1.graphics.GraphicsDevice.Viewport.Width, moveableEntity.boundingBox().rightMostPoint()))); return true; } else { return false; } }