• Advertisement
Sign in to follow this  

win32 template....

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

Im making a 2d game, something pretty simple bomber flying drops bombs, background scrolls. Ive gotten the plane flying and shooting, the thing is the code is getting very long and ugly, and most of the code is in the first page (main). Does anyone have a template i can start with, were there is only one or two functions to windows. The template i used here is from before vs6++. Below is a sample of how my code looks like. (Some of the problems i had the buffer would not work in function, or passing hwnd, and some of the other windows stuff i dont understand, yeah im using lots of globals right now too). Im hoping someone can give me some code that i can use for a good starting base.
void OnPaint(HWND hwnd)
{

	AirPlane.move((SpeedX), 0, 2);
	AirPlane.move(0,(SpeedY), 2);


	HDC hdc = GetDC( hwnd );
	HDC memDC = CreateCompatibleDC(hdc);
	 PictureXpos -= 5;
	 if( PictureXpos < -1500)
		  PictureXpos = 0;


	 PictureYpos =kHeight /2 - (AirPlane.Get_Y() );
	 if(PictureYpos < -200)
		 PictureYpos = -200;

	 if(PictureYpos > g_bmBackground.m_nHeight -  kHeight)
		 PictureYpos = g_bmBackground.m_nHeight - kHeight;


	 BitBlt( g_bmBuffer.m_hdcImage,  PictureXpos , 0,g_bmBackground.m_nWidth,g_bmBackground.m_nHeight, g_bmBackground.m_hdcImage, 0, 0, SRCCOPY );
	
	// Next the sprite


	if(! Bullet[1].Get_Active() && Bullet[1].Get_OutOfRange()){
		Shooting = 0;
		Bullet[1].Set_OutOfRange(false);
	}

	
	if(Shooting >= BulletAmount)
		Shooting = 0;

	
// create bullet
int i = Shooting;
switch(Shooting){
		case 1:
		if(! Bullet.Get_Active()){
		Bullet.create(hwnd, "Bullet.bmp", AirPlane.Get_Position(), FALSE);
		Bullet.setFrameCount(2);// yellow
		
		Bullet.Set_Active(true);}
	
		break;
		case 2:
		if(! Bullet.Get_Active()){
		Bullet.create(hwnd, "Bullet1.bmp", AirPlane.Get_Position(), FALSE);
		Bullet.setFrameCount(2);// dark red
		
		Bullet.Set_Active(true);}
	
		break;
		case 3:
		if(! Bullet.Get_Active()){
		Bullet.create(hwnd, "Bullet2.bmp", AirPlane.Get_Position(), FALSE);
		Bullet.setFrameCount(2);// red
		
		Bullet.Set_Active(true);}
		
		break;
		case 4:
		if(! Bullet.Get_Active()){
		Bullet.create(hwnd, "Bullet3.bmp", AirPlane.Get_Position(), FALSE);
		Bullet.setFrameCount(2);// grey
		
		Bullet.Set_Active(true);}
		
		break;
		case 5:
		if(! Bullet.Get_Active()){
		Bullet.create(hwnd, "Bullet4.bmp", AirPlane.Get_Position(), FALSE);
		Bullet.setFrameCount(2);// brown
		
		Bullet.Set_Active(true);}
		
		break;
}// end switch

// move bullet forward
	for(int counter = 1; counter < BulletAmount; counter++){
		if(Bullet[counter].Get_Active() ){//&& (!Bullet[counter].Get_OutOfRange())){
	    Bullet[counter].move(12, 0, 1);
		Bullet[counter].draw( g_bmBuffer.m_hdcImage );
		if(Bullet[counter].Get_X() > kWidth){
		Bullet[counter].Set_OutOfRange(true);
		Bullet[counter].Set_Active(false);}
		}

	}// for loop
	
	AirPlane.draw( g_bmBuffer.m_hdcImage );
	// Now we copy the composed image into the main window.
	BitBlt( hdc, 0, PictureYpos, kWidth, kHeight, g_bmBuffer.m_hdcImage, 0, 0, SRCCOPY );
	
	ReleaseDC( hwnd, hdc );




}



Share this post


Link to post
Share on other sites
Advertisement
If it's fine unser VS6, then it should at least come close to compiling under VS7/8. By the sounds of things, you've forgotten to #include <Windows.h>.

Admiral

Share this post


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

  • Advertisement