Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Pixel perfect collision-The saga continues...

Author
Message
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 4th Aug 2004 20:03
Unfortunately I need more help again. I´m trying to do a pixel perfect collision function but I can´t get passed a simple maths problem. I need to figure out the x and y position of a pixel of a sprite. I have the x position and y position of the sprite and I know it´s width and height. I have the image that the sprite uses stored in a memblock. I now need to think up some maths that gives me the pixel´s position given the height, width and size of the sprite. I use a for next loop like this to check the sprites colour and get the pixel´s x and y values:

xsize1=sprite width(sprite1) : ysize1=sprite height(sprite1)

xsize1*ysize1=size1 : xsize2*ysize2=size2
memsize=(size1*4)+12

for imageloop=12 to memsize step 4
if memblock byte(1,imageloop)=255

pixelposx=
pixelposy=
endif
next imageloop

Basically if imageloop=12 then the pixel´s position is the same as the sprites position. If imageloop=16 (step 4) then the pixels x position is one greater than the sprite and it´s y value stays the same and so on and so fourth. How do I tell the computer the rules? Any ideas? If you want me to explain anything more clearly don´t hesitate to say so.
You help is appreciated

P.S: Thank you Freddix for your pixel perfect collision function which I´m basing mine on.


Jam on mother f**ker.
Libera tu mente y te liberaras.
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Aug 2004 08:51
Wouldn't you need two loops - one to check the x-pos and one for the y-position? Like

for loop_y = 0 to height
for loop_x = 0 to width

if pixel is white then pixel_x=loop_x
if pixel is white then pixel_y=loop_y

next loop_x
next loop_y

That would check every pixel from left to right for every row from top to bottom.

Sorry if that's not what you meant.
MiR
20
Years of Service
User Offline
Joined: 13th Jul 2003
Location: Spain
Posted: 6th Aug 2004 00:20
Thank you!! If I could somehow tie your idea to mine it might work. Right. I´ve got alot of programming to do.


Jam on mother f**ker.
Libera tu mente y te liberaras.

Login to post a reply

Server time is: 2024-05-22 09:37:42
Your offset time is: 2024-05-22 09:37:42