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?
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
Citationfunction 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
}
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?
u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);
return (*ptrMap);
}
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?
u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);
return (*ptrMap);
}
( Sorry I wasn't very descriptive ) I meant sprite by sprite. I.e., Sprite 1 touches Sprite 2 and Sprite 1 disappears.
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)
Citation de: RonaldCoLtd le 14 Juillet 2013 à 18:31:09
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?
u16 getCollisionTile(u16 x, u16 y) {
u16 *ptrMap = (u16 *) &mapcol + (y>>3)*300 + (x>>3);
return (*ptrMap);
}
( Sorry I wasn't very descriptive ) I meant sprite by sprite. I.e., Sprite 1 touches Sprite 2 and Sprite 1 disappears.
Hixbox algorithm is amazing solution and functional but if you are not understand look at this function:
if((oamGetX(ID_SPRITE_1) == oamGetX(ID_SPRITE_2)) & oamGetY(ID_SPRITE_1) == oamGetY(ID_SPRITE_2) ){
oamSetEx(ID_SPRITE_1, OBJ_SMALL, OBJ_HIDE);
}
The problem for it is that the sprite disappears when the two stay exactly in the same position, remember you need to take into consideration the size of the sprite so this function does not work well