Sign in to follow this  

game speed

This topic is 3678 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

I've been searching for hours for stuff on gamespeed. I just made a 2d game with a player and an enemy, with 10 levels. Well, it works awesomely well on my laptop, but runs insanely fast on my desktop. I'm planning to distribute it for $3-$5 when it's polished, so I can't easily go to a customer's house and change all the variables for movement :D I've tried a few methods, and here's my latest, that doesn't work...
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	done=FALSE;								// Bool Variable To Exit Loop
timer = GetTickCount();

	// Ask The User Which Screen Mode They Prefer
	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							// Windowed Mode
	}

	// Create Our OpenGL Window
	if (!CreateGLWindow("side-scroller",640,480,16,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while(!done)									// Loop That Runs While done=FALSE
	{                                                
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if (active)								// Program Active?
			{
				if (keys[VK_ESCAPE])				// Was ESC Pressed?
				{
					done=TRUE;						// ESC Signalled A Quit
				}
				else								// Not Time To Quit, Update Screen
				{
					DrawGLScene();					// Draw The Scene
					SwapBuffers(hDC);				// Swap Buffers (Double Buffering)


   
if(GetKeyState(VK_LEFT))
{
    player.x-=0.05*shipmovementval;
}
if(GetKeyState(VK_RIGHT))
{
   player.x+=0.05*shipmovementval;
}
    if(pcounter==20)
    {
	if((GetKeyState(VK_SPACE) & 0x80))
	{
        if(a<1001)
        {
        bullets[a].x=player.x;
        bullets[a].y=player.y; 
        bullets[a].active=true; 
            PlaySound("Data/laser.wav", NULL, SND_ASYNC);             
        a++;
        }
    } 
}                  
     if(direction==1)
   {
      enemy[levelnumber].x+=0.13*shipmovementval;
      }   
      if(direction==0)
   {
      enemy[levelnumber].x-=0.13*shipmovementval;
      } 
      if(enemy[levelnumber].x>7)
      {
        direction=0;
        }
             if(enemy[levelnumber].x<-7)
      {
        direction=1;
        } 
        if(counter==40)
        {
           badbullets[b].active=true;
           badbullets[b].x=enemy[levelnumber].x+.25;
           badbullets[b].y=enemy[levelnumber].y-.5;
           b++;           
           }
       counter++;  
       pcounter++;                   				
}
if(pcounter==21)
{
pcounter=0;
}
if(counter==41)
{
   counter=0;
}
if(enemy[levelnumber].health<=0)
{
   levelnumber++;
}

}        


			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow("Alien Invasion",640,480,16,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
		}
//first determine how many seconds elapsed
timerdiff = GetTickCount()-timer;

//the function reads in milliseconds so convert to seconds by dividing by 1000
secsperframe=(float)(timerdiff/1000.0f);
//now compute the movement value
shipmovementval = (float)(60*secsperframe);
bulletmovementval = (float)(90*secsperframe);

//get the new time
timer = GetTickCount();


	}

I removed some stuff such as transitioning from the splash to playing, but that is irrelevant. Help is greatly appreciated. Hoping to get this down and have it done tomorrow as a Thanksgiving present to me and some family.

Share this post


Link to post
Share on other sites

This topic is 3678 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this