Sign in to follow this  
pascalosti

win32 template....

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[i].Get_Active()){
		Bullet[i].create(hwnd, "Bullet.bmp", AirPlane.Get_Position(), FALSE);
		Bullet[i].setFrameCount(2);// yellow
		
		Bullet[i].Set_Active(true);}
	
		break;
		case 2:
		if(! Bullet[i].Get_Active()){
		Bullet[i].create(hwnd, "Bullet1.bmp", AirPlane.Get_Position(), FALSE);
		Bullet[i].setFrameCount(2);// dark red
		
		Bullet[i].Set_Active(true);}
	
		break;
		case 3:
		if(! Bullet[i].Get_Active()){
		Bullet[i].create(hwnd, "Bullet2.bmp", AirPlane.Get_Position(), FALSE);
		Bullet[i].setFrameCount(2);// red
		
		Bullet[i].Set_Active(true);}
		
		break;
		case 4:
		if(! Bullet[i].Get_Active()){
		Bullet[i].create(hwnd, "Bullet3.bmp", AirPlane.Get_Position(), FALSE);
		Bullet[i].setFrameCount(2);// grey
		
		Bullet[i].Set_Active(true);}
		
		break;
		case 5:
		if(! Bullet[i].Get_Active()){
		Bullet[i].create(hwnd, "Bullet4.bmp", AirPlane.Get_Position(), FALSE);
		Bullet[i].setFrameCount(2);// brown
		
		Bullet[i].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

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