Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

slippers2k

GBA-related collision detection: how?

This topic is 5729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know that if two sprites touch, collision detection essentially prevents the scenario from occuring. With sprites though, how do you account for the varying sprite sizes? I know a basic example would be Super Mario avoiding a cannon bullet fired across the screen, where if the bullet touches Mario, he either loses a powerup or dies. The x and y usually given to move sprites are not enough on their own for collision detection. Would I need to consult a sprite''s individual attribute of size to define a boundary for the sprite? Thanks in advance for any help... I mean it -slippers2k Attack life''s problems like a Subaru... with all four wheels

Share this post


Link to post
Share on other sites
Advertisement
You can maybe use the size of your sprites to detect collision.
Using your example Super Mario Bros. take the center of the image like x y coords for the object so.

0,0-----------
| |
| |
| x,y |
| |
| |
0,sizey-------sizex, sizey

This is usually called the bounding box, you can check collision with this.

Share this post


Link to post
Share on other sites
The boundary box theory sounds like a plan... unfortunately, I have a real big problem. Attributes 0 and 1 of each sprite I render contain their x and y coordinates. But where are those coordinates on the sprite?

Is the x and y coordinate for each sprite defined at their upper-left corner, in the middle, or somewhere else? (It is incredibly hard to explain this without a picture, I know) If I was doing collision detection for a tile-based maze game, I know that if a player''s next step would take them through a wall, and I knew that wall was stone thick, collision detection would prevent that move from happening.

Likewise, in a racing game, collision detection would obviously keep a car from going through a wall, or another car.

Ultimately, it should be a no-brainer for pong for collision detection, right? Why am I not getting it?

-slippers2k

p.s. please help... thanks!

Attack life''s problems like a Subaru... with all four wheels

Share this post


Link to post
Share on other sites
On the gba the (x,y) co-ordinates you put into OAM are the upper left hand corner of the displayed sprite. For your collisions just define a bounding box as something like this:

x1 = upper left
y1 = upper right
x2 = x1 + width
y2 = y1 + height

And then you can do simple rectangle/rectangle intersection to see if the two sprites are colliding.

Share this post


Link to post
Share on other sites
For future reference, it would help you greatly if you learned how to decide things like this on your own. You asked, for instance, if the sprite location is the center, the upper left hand corner, or what. The easiest way to find that out (and yes, easier than asking here) would be to give a sprite the position (0,0) and test it. If you see only the lower right corner, you know that position is the sprite''s center. If you see the whole sprite at the upper left corner of the screen (which you will), you know the location is the sprite''s upper left corner.

I don''t mean to sound rude. I''m just saying it''ll help you greatly to try some of this stuff.

-Arek the Absolute

Share this post


Link to post
Share on other sites
Arek,

Point well taken. I was trying to get a lot done in one sitting... probably why it sounded like I was whining so much. But thank you for all your help... definitely appreciate the support.

And thanks again to all that contribute...
-slippers2k

Attack life''s problems like a Subaru... with all four wheels

Share this post


Link to post
Share on other sites
Cool! After several tries, I got basic collision detection down (at least, I think).

To start with, I had my collision detection code in the wrong function to begin with (the movesprites function instead of the getinput function where it was supposed to be... think about it for a moment and you''ll understand). With that fixed, I had to fix my logic. (That takes a very long time to explain, so, long story short, checking for collision detection on the x axis is easy, at least for now.)

Take care guys! God bless you all and thank you for all the help you have given me. I''ll keep working on it...

-slippers2k

p.s. I''d include a picture too, but a recent power surge took out my computer''s modem... I''m using my wife''s pc. Maybe later...

Attack life''s problems like a Subaru... with all four wheels

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!