now=SDL_GetTicks()/1000.0f;
diff=last-now;
//get input, draw, etc...
last=now;
this is wrong... you should not take the time at the begining of your main loop AND at the end... this is wrong because your OS might decide to take over sometime during the middle of the app, and that last wont be correctly in- sync. (i might have worded that wrong, dont quote me on it).
the proper way would be to do this:
//main game loopwhile(!gameover){PreviousTime = CurrentTime; //start the counter for FPS CurrentTime = SDL_GetTicks(); //end the counter for FPS FrameTime = (CurrentTime - PreviousTime) * 0.001f; //find the time elapsed in milliseconds and convert it to seconds by multiplying by .001//NOW do your whole game loop here!
do you see how this works? immediately in the begining of the loop we take the previous time, then right after we get the current time, then right after that we subtract the second one from the first. the first time this loop runs, there will probably be no difference in the 2 (obviously you would have to initialize current_time). but, when the loop goes around one time, it will get to previous time and assign that value to current_time (which would have happend an entire game loop ago), then current time is assigned the time. the subtracted amount is how much time passed during the game loop. now since each lines of code are right next to each other, the OS wont hog you and screw you over.
now, on to your movement code, yours looked ok but it seemed like you were incrementing it by a low number maybe?
if (direction==UP) { if ((ypos-2)<56) { turbing=false; } else { turbing=true; ypos = yPos + (500 * FrameTime); } }
obviously i hard-coded 500. but you can play around with that value to get the speeds you want. hope i helped.
[edited by - graveyard filla on April 25, 2004 1:23:55 PM] [edited by - graveyard filla on April 25, 2004 1:40:08 PM] [edited by - graveyard filla on April 25, 2004 1:40:47 PM]