Jump to content
  • Advertisement
Sign in to follow this  

GetTickCount()

This topic is 4131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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 init
int lendelay=0;

//game main loop
//key press check part
if (keypressed(jump)&&(lendelay==0))
{
//do something here
lendelay = 10; //maybe some larger number
}

//at the end of game loop
if (lendelay>0) lendelay--;


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!