
-----------------------------------
Aange10
Tue Jan 31, 2012 7:05 pm

[Module] Collision 2
-----------------------------------
Reposted with permission (so it will be much neater):

Features
 This Collision module includes algorithms for detecting Collision for a variety of situations. This Module's functions are shown under Syntax.

How it Works
 Essentially, the module will take in coordinates that you input between any two objects (or points) and see if they are within collision range.

Syntax
 The syntaxes are as followed:

% Points
Collision.isPointInCircle (pointX, pointY, circleX, circleY, circleRadius : int) : boolean
Collision.isPointInOval (pointX, pointY, circleX, circleY, circleXRadius, circleYRadius : int) : boolean
Collision.isPointInRectangle (pointX, pointY, rectangleX1, rectangleY1, rectangleX2, rectangleY2 : int) : boolean
Collision.are2PointsWithinDistance (point1X, point1Y, point2X, point2Y, distance : int) : boolean
% Collision
Collision.circleToCircle (circle1X, circle1Y, circle1Radius, circle2X, circle2Y, circle2Radius : int) : boolean
Collision.circleToOval (circleX, circleY, circleRadius, ovalX, ovalY, ovalXRadius, ovalYRadius : int) : boolean
Collision.rectangleToRectangle (box1_x1, box1_y1, box1_x2, box1_y2, box2_x1, box2_y1, box2_x2, box2_y2 : int) : boolean
Collision.circleToRectangle (circleX, circleY, circleRadius, recX1, recY1, recX2, recY2 : int) : boolean
Collision.ovalToRectangle (ovalX, ovalY, ovalXRadius, ovalYRadius, recX1, recY1, recX2, recY2 : int) : boolean
Collision.ovalToOval (oval1X, oval1Y, oval1XRadius, oval1YRadius, oval2X, oval2Y, oval2XRadius, oval2YRadius : int) : boolean
% Drawing (Collision)
Collision.drawOvalToOval (oval1X, oval1Y, oval1XRadius, oval1YRadius, oval2X, oval2Y, oval2XRadius, oval2YRadius : int)
Collision.drawOvalToRectangle (ovalX, ovalY, ovalXRadius, ovalYRadius, recX1, recY1, recX2, recY2 : int)
Collision.drawCircleToRectangle (circleX, circleY, radius,recX1, recY1, recX2, recY2 : int)
Collision.drawRectangleToRectangle (box1_x1, box1_y1, box1_x2, box1_y2, box2_x1, box2_y1, box2_x2, box2_y2 : int)
Collision.drawCircleToOval (circleX, circleY, circleRadius, ovalX, ovalY, ovalXRadius, ovalYRadius : int)
Collision.drawCircleToCircle (circle1X, circle1Y, circle1Radius, circle2X, circle2Y, circle2Radius : int) 


Instructions
Simply import the file at the top of the program, and access to all of these methods will be yours. Call the methods with syntax given above.

To import the file, simply place the Collision.tu file into the file of whatever project you are working on, and at the top of your sourcecode (on the VERY FIRST line) type "import "Collision.tu"

The Module
The module is attached below.

Working Example
A working example is also attached below.
