When making a game, many problems come from collisions of objects. Most of games use simple bounding boxes, but they are not useful in all situations.
Well, what I'm showing here are not pixel-perfect colliders, but still they are pretty useful. To standard bounding box I added a circular collision, but this would be too simple. So I made the boxes rotating.
I based on this:
http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604And this:
http://www.migapro.com/circle-and-rotated-rectangle-collision-detection/So our rectangles and circles can now collide with themselves upon any angle. They are just helper classes to attach to object and then check if they intersect.
The code is here:
http://pastebin.com/Yxu9NTEyJust copy it to your project and use the classes.
Example is attached to post.
initialize
method of
Collision_Box takes x, y, width, height and angle of box in degrees
And
Collision_Ball takes x,y and radius
Both classes provide methods called
set
for setting position of collider and
move
which moves collider (well, rather useless one)
And of course, to check collision, you use
collides?
method passing another collider as argument.
Well, enjoy.
EDIT:
I forgot to mention that boxes can be rotated only around center.
EDIT2:
Added Collision_Group. Shapes in Collision_Group move relatively to group and any of them triggers collision of whole group.
EDIT3:
Now all objects from group rotate around group origin.