Sprite to Background Collision by Licaon6th Oct 2003 12:53
|
---|
Summary A background to sprite collision detection (pixel perfect) Description It checks the collision between a sprite and an image, assuming: Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Function BackGround_Collision (spr , img , color) rem asume que el sprite esta contenido en una imagen y que sus coordenadas son relativas a la rem coordenada 0,0 (top,left) de la imagen de 32 bits rem rem SPR =sprite to check rem IMG =image to check rem Color = Transparent Color Colision=0 anch = sprite width(spr) alto = sprite height(spr) posx = sprite x(spr) posy = sprite y(spr) spriteimage=254 backimage=255 imagesource = sprite image (spr) make memblock from image spriteimage,imagesource make memblock from image backimage,img ancho_imagen = memblock dword (backimage,0) alto_image = memblock dword (backimage,4) base=12 for x=0 to anch -1 for y=0 to alto -1 ColorSpr= memblock dword (spriteimage,12+x*4+y*anch*4) ColorImage=memblock dword (backimage,12+(x+posx)*4+(y+posy)*ancho_imagen*4) if colorspr<>colr and colorimage<>colr then colision=1 if colision=1 y=alto-1 x=anch-1 endif next y next x delete memblock 255 delete memblock 254 endfunction Colision |