GP32 Sprite Control & Collision Detection


solarice

Member
Joined
Jan 29, 2004
Messages
120
Location
UK
Website
Visit site
Hi,

Two not so quick questions.

Question 1 - Collision Detection.

To make this work can i use a transparent image of the walls etc that i dont want to be able to go through and layer that on top, or should i split the walls from my main image and layer that on top - so you have the floor being drawn then on top of that the walls, which id then add code to stop being able to pass through it. Or do i have to go about it a totally different way.

Question 2 - Sprite Control.

Im wanting to rotate sprites with button presses and have been been looking at the sin & cos sites amongst others. I understand the principal of it put putting it into practise is whats getting me. Ive read that the code should really be put in a "Fix Class" <-- what is this? and what does it look like.

another site says you should learn how to use floats before heading into classes. So which should i attempt to do and how do i go about it, just so you know the sprite in question will be the only moving object on screen.


Thanks Alot in Advance.
 
I cannot help you with the rotation part, I myself tried that several times and always failed at maths ;)
For the collision question, I dont fully understand what you want to achieve, but collision techniques depend on the type of game you make, or its engine. If the engine is tile-based, then you use a tile-map with stored information about the tiles, which one is accessible, which one can be shot thhrough etc. This allows you to make rough collision detection, which for some games is good. Another way is to use pixel perfect collisions, which is more cpu consuming and may be more demanding on calculating the position in your masking bitmap.
 
Thanks for that, im looking through your tutorials now.

Just to clarify my collision thinking. Ive got one big image that i was just gonna display to the screen, without splitting them into tilesizes so no tile engine. what i was wondering was whether because of this i could just overlay the same image with just the boundaries and make that full image a barrier. Hope that helps others understand what im on about.

Its a top down view game.

as for the pesky rotation problem, i think ive nearly figured it out....but if anyone does know how to do it, dont hesitate to place it in this topic :D

If i get it working i'll let you's know.
 
A simple way to do the collision is to have a bitmask. Make a black and white image which represents the collision areas of your background. Load these into an array of bools. Now all you have to do is check this array once per frame. If you need more types of collision, you can then upgrade your array to chars and you will have 256 settings per pixel.

You may not even need to have your collision mask at the same resolution as the background. You could make each collision map pixel represent 4 real screen pixels. Saving a lot of memory. It depends what you need.

BTW, I would recommend looking into using a tile engine, it will allow you to have a lot larger background without running into memory constraints.
 
For rotation, you don't need to use floats, and the classes thing is for c++...

You don't need floats, but you need to keep values that you will mul with some sin values, which are beetween 0 and 1...

To do that, you need tu use what is called fixed point values which are in fact values * a constant value (for example you would use 1000 or something like that, but in this case we use 2^16, because you just need a shift to get your final value).

You'll also need a sin table, because if you make the gp32 use standard c routines to get each value it will ruin the speed.

MrSpiv has some rotation routines on his website : http://www.cs.helsinki.fi/u/jikorhon/condev/gp32/
 
Back
Top