Auteur Sujet: Adding Collision?  (Lu 5046 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne RonaldCoLtd

  • Newbie
  • *
  • Messages: 2
    • Voir le profil
    • E-mail
Adding Collision?
« le: 10 juillet 2013 à 22:28:31 »
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?

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Adding Collision?
« Réponse #1 le: 12 juillet 2013 à 06:10:15 »
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
}

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Adding Collision?
« Réponse #2 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);
}

Hors ligne RonaldCoLtd

  • Newbie
  • *
  • Messages: 2
    • Voir le profil
    • E-mail
Re : Re : Adding Collision?
« Réponse #3 le: 14 juillet 2013 à 18:31:09 »
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.

Hors ligne alekmaul

  • Administrator
  • Hero Member
  • *****
  • Messages: 1149
    • Live Messenger (MSN) - alekmaul@hotmail.fr
    • Voir le profil
    • PortableDev
    • E-mail
Re : Adding Collision?
« Réponse #4 le: 15 juillet 2013 à 07:35:39 »
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)

Hors ligne faeldaniel

  • Newbie
  • *
  • Messages: 34
    • Voir le profil
Re : Re : Re : Adding Collision?
« Réponse #5 le: 15 juillet 2013 à 20:59:26 »
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