Développement SNES > PVSnesLib English section

Adding Collision?

(1/2) > >>

RonaldCoLtd:
I've been trying to figure out how to add collision to your game from quite awhile. I've tried, but most of the time failed. Anyone have any suggestions?

alekmaul:
The best way is to use an hixbox algorythm.
It is not really strict (regarding each sprite look) but really fast. Pixel perfect collision will be too slow for PVSnesLib.
Take a look here : http://en.wikipedia.org/wiki/Hit-testing


--- Citer ---function HitTest(Rectangle r1, Rectangle r2) returns boolean
{
    if ((r1.X + r1.Width >= r2.X) and (r1.X <= r2.X + r2.Width))
    and ((r1.Y + r1.Height >= r2.Y) and (r1.Y <= r2.Y + r2.Height)) then
      return true
    else
      return false
}
--- Fin de citation ---

faeldaniel:
alekmaul not yet started their studies this point however how to adapt this function that you used in the LikeMario for bg collision of 512px X 512px?


--- Code: ---u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);

return (*ptrMap);
}
--- Fin du code ---

RonaldCoLtd:

--- Citation de: faeldaniel le 14 juillet 2013 à 05:33:40 ---alekmaul not yet started their studies this point however how to adapt this function that you used in the LikeMario for bg collision of 512px X 512px?


--- Code: ---u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);

return (*ptrMap);
}
--- Fin du code ---

--- Fin de citation ---

( Sorry I wasn't very descriptive ) I meant sprite by sprite. I.e., Sprite 1 touches Sprite 2 and Sprite 1 disappears.

alekmaul:
You can't use this function, it is only for map , when you want to know which tile is under or near something.
For sprite, you must use hitbox algo with x/y coordinates of each sprite.
Take a look at my previous posts, and adapt it for your sprite (Rectangle r1 is sprite #1 and r2 sprite #2)

Navigation

[0] Index des messages

[#] Page suivante

Sortir du mode mobile