Hello guys
I've been busy this week but now I'm getting long holidays and I'll be able to code all night! Right now I'm almost finished creating a very tiny Mario clone. It's nothing but a framework of his motion (no map scrolling, no enemies or dangers (except that you die if you go off the screen)) but I'm still hitting a problem. I managed to get gravity and inertia working fine, but how do I handle Mario's collision with block? I'd know how to do it if his sprite would be a collection of solid visible pixels, but there are many full alpha pixels too! I can explain the whole game cycle more specifically so you could understand me better:
- Draw the level (both sprites (blocks and Mario) are 40x40)
- Handle events and interact with the user.
- Check if any visible pixel of Mario hasn't collided with a with any of the block
- If it has collided, push Mario back to the side of the block and change the values of needed velocities to zero.
How do I make the third step? Any function to do it for me?
I've heard something about function that checks if one rectangle contains the other, but does that function consider the alpha channel? Anyone?
Thanks in advance
I'll be able to send the code and the game later (currently I'm away from home, coming back after ~5 hours).
UPDATE: Found some BIG code snippets here:
https://github.com/SFML/SFML/wiki/Source%3A-Simple-Collision-DetectionWell, this
simple colission doesn't look so simple. Maybe I should turn Mario to perfect square. That would make things much easier...