Ok, im surrently working on a scroller. Im trying to implement jumping using the principles from the physics chapter from TOTWGPG. I can make the skelaton move up but i need to make it so that he can only jump while on the ground. Heres my code
// model gravity
skelaton.y+=skelaton.yv;
skelaton.yv+=gravity;
if ((keyboard_state[DIK_SPACE]) && (deb_key==0))
{
skelaton.y-=skelaton.yv;
deb_key=1;
}
if ((keyboard_state[DIK_SPACE]) && (deb_key==1))
skelaton.y+=skelaton.yv;
Using this he cant jump at all. if i add an "else" it can jump even while in the air. So, i added this code to the collision function...
// collision test
while(Collision_Test(skelaton.x,skelaton.y,skelaton.width,skelaton.height,
0,384,SCREEN_WIDTH*2,SCREEN_HEIGHT))
{
skelaton.y-=1;
deb_key=0;
}
This did nothing. And lastly i tried this block of code and this didnt work.
if (skelaton.y <= 383)
deb_key=0;
else
if (skelaton.y > 383)
deb_key=1;
I had similar problems like this before and this technique worked. Now im stuck. Any suggestions??