GetTickCount()

Started by
21 comments, last by styfir 17 years, 2 months ago
Hi all, Sorry for the embarrassing questio coming up but I have a problem with jumping in a game. It's just a basic reconstruction of the old classic Chucky Egg. By using GetTickCount() I have managed to control the character's left and right smoothly, but, when I press the jump key it jumps far too fast. The test for the jump key is in the same place as the test for the left and right keys and they seem to be fine. Why is the jumping action acting like theres no delay at all?? Please can someone help and keep in mind that I'm very new to gaming in c++. styfir.
Advertisement
You need to provide some more details. Most of us aren't psychic and hence fail to magically know how your code works.
When you press Jump, there really exist delay. But they're still too short. Game will continually get keypress message.

You can add an int to lengthen this delay.

//game initint lendelay=0;//game main loop//key press check partif (keypressed(jump)&&(lendelay==0)){//do something herelendelay = 10; //maybe some larger number}//at the end of game loopif (lendelay>0) lendelay--;
ok heres the code then

#include "Globals.h"

void Main_Loop()
{

HDC hdc;
hdc = GetDC(GameHandle);

if (KEYDOWN(VK_ESCAPE))
{
SendMessage(GameHandle, WM_CLOSE, 0,0);
}


chuckyendtime=(GetTickCount()-chuckystarttime);
if ((int)chuckyendtime>chuckyspeed)
{
if (KEYDOWN(VK_SPACE) && (lenDelay==0))
{
for(int i=1; i<60; i++)
{
Clear_Chucky();
py=py-gravity;
Draw_Chucky();

//gravity+=1;
}
gravity=1;
lenDelay=100;
}

while(GetPixel(hdc,px+3,py+35)==RGB(0,0,0))
{
Clear_Chucky();
py=py+gravity;
Draw_Chucky();

//gravity+=1;

}

if (KEYDOWN(VK_RIGHT))
{
if (px<757)
{
Clear_Chucky();
px+=3;

// when moving right check to see if theres a ladder //
if(GetPixel(hdc,px+27,py)==RGB(60,60,60)) // ladder color
{
contact=true;
}
if(contact)
{
Redraw_Ladder(); // go and redraw corresponding ladder
}
Draw_Chucky();
}
}

if (KEYDOWN(VK_LEFT))
{
if (px>3)
{
Clear_Chucky();
px-=3;

// when moving left check to see if theres a ladder //
if(GetPixel(hdc,px-27,py)==RGB(60,60,60)) // ladder color
{
contact=true;
}
if(contact)
{
Redraw_Ladder(); // go and redraw corresponding ladder
}
Draw_Chucky();
}
}

}
chuckystarttime=GetTickCount();
ReleaseDC(GameHandle,hdc);


}






See if you can find the problem I'd be really grateful Ta
Quote:
lendelay=100;


maybe it's just too large. the number here, take 100 as example, means you multiply delay by 100.
Ive tried smaller numbers like 50 and 25 but still, no effect on the speed - I just dont know...

thanks anyway,

styfir.

BTW how do you post code and have it all nice and indented?
[ source ] [ /source ] tags.
use [souce] and [/source] tag
Thank you

any more thoughts on the problem at hand??

styfir.
granted I might have missed something, but lenDelay doesn't do anything as far as I can see in the code you posted. It's tested for zero in an if, and if it is, it's set to 100. Also, you have a for loop that does nothing but run through the code in the loop 60 times, as fast as it can. No timing is involved in the loop, so that's why it looks like GetTickCount has no effect on it, 'cause it doesn't. Again, I might have missed something, but that's what I can gather.

If you've modified the code at all (and even if you haven't) post it up properly so that the indentation/formatting is seen, it's a lot easier to see an error that way, for us and for you.

This topic is closed to new replies.

Advertisement