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 / platform collisions

Author
Message
Gatorules
17
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 28th Jul 2010 01:46
I want the character to fall until hitting the platform then stop and also stop when colliding with walls but my code doesn't seem to work and i'm confused.


MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 28th Jul 2010 01:50
Can you include media so i can see exactly whats happening?

metal is not music but a way of life...all hail to the reigning king METALLICA!!!
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 28th Jul 2010 04:50 Edited at: 28th Jul 2010 04:53
I didn't look over your code but I can help. Each loop you need to check for left,right,top,bottom collisions seperately and deal with them seperately. For bottom collision, check the pixel color value 1 pixel below your sprite. If it's the color of your platform, enter a while loop where the sprite is moved a pixel up each time untile it is above the platform. Do this for each side so for example for left side collision, check the color of the pixel to the left of your sprite and if it is the platform color enter the while loop to move it out. you need to check however two pixels on eachside so collision will be detected for the corners also.
Heres a diagram of where to check.
The box is your sprite and the numbers are where you check.

NOTE: No position checked should be at a corner or else collision will be detected for multiple sides even if only one side is hit.
So positions would be calculated by
pos1=(sprite x,sprite y+sprite height+1)
pos2=(sprite x+sprite width+1,sprite y+sprite height+1)
pos3=(sprite x-1,sprite y-1)
pos4=(sprite x+sprite width+1,sprite y-1)
ect...

I used this teqnique for a simple platformer I programed in C++ last week.
Hope I helped.

If it hasn't exploded yet, I haven't touched it.
Gatorules
17
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 28th Jul 2010 05:18
@Madscientist: That's kind of like the technique that I tried using but I'm not sure if it would be more effective to test for the color of the platform than the location. Thanks for the input though, I'll try it out and see if it helps.

Here's the code again with media attached.

MASTER OF PUPPETS
22
Years of Service
User Offline
Joined: 9th Jun 2004
Location: Trapped Under Ice
Posted: 28th Jul 2010 11:36
i have not figured everything out yet but i have noticed, so far, when checking for "touchingbottom" the if/then does not work...

if oldy<scrolly#.....

i changed it to.....

if oldy=scrolly#....

and that seems to allow the program to read the code between "if" and "then".

also if you remove that first part to make it look like this....

if sprite y(2)+sprite height(2)>=sprite y(ITloop)//bottom

it also seems to work.

so your problem appears to be that the "oldy" and "scrolly#" are the same rather than "oldy" always being one step behind.

go over your code make some changes and let me know if that helped at all.if not, i will continue to look it over.

metal is not music but a way of life...all hail to the reigning king METALLICA!!!

Login to post a reply

Server time is: 2026-07-25 07:01:24
Your offset time is: 2026-07-25 07:01:24