------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------


#pragma once

// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple 2D project that uses Dark GDK
// it can be used as a starting point in making your own 2D games

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"


class DgApp
{
public:
	DgApp(void);
	~DgApp(void);
	enum ID 
	{
		ID_IMG_BACK=1,
		ID_IMG_SHOOTER=2,
		ID_SPRITE1=1,
		T=2,
		S=3,
		P=4,
		SCREEN_X=625,
		SCREEN_Y=460,
	};
	void OnExecute();

	void OnInit();
	void OnInitLoadImg();

	void OnLoop();
	
	void OnLoopTarget();
	void OnLoopShooter();
	void OnLoopProjectile();
	void OnLoopHitMiss();

	void OnLoopCrash();


	void OnRender();
	void OnCleanup();

	int D ;
	int R ;
	int M ;
	int AC;
	int BC ;
	//
	int DIF; // 2, 5, 10, or 50
};
#include "DgApp.h"

DgApp::DgApp(void)
{
	D = 0;
	R = 1;
	M = 200;
	AC = 50;
	BC = 4 ;

	// 
	DIF=2;
}

DgApp::~DgApp(void)
{
}

void DgApp::OnInit(void)
{
	// in this application a backdrop is loaded and then several
	// sprites are loaded, the sprites are targets!

	//Turn on Sync
	dbSyncOn   ( ); 
	
	// Set Sync Rate for screen:
	// The lower it is, the faster the game runs but the visual effects will be bad.
	// The higher the setting - the opposite will occour!
	dbSyncRate ( 100 ); 

	//disable the "escape" key
	dbDisableEscapeKey ( ); 

	//use the clock to obtian random numbers more effieciently
	dbRandomize ( dbTimer() ); 

	//this will load our game image
	OnInitLoadImg();


}
void DgApp::OnInitLoadImg(void)
{
	// this will load our background onto the game
	// ------------------
	// Load Back - 1000 x 1000
	dbLoadImage ( "Media/backdrop.bmp", ID_IMG_BACK ); 

	// sprite used for the background

	//void dbSprite ( int iSprite, int iX, int iY, int iImage ) 
	dbSprite ( ID_SPRITE1, 0, 0, ID_IMG_BACK ); 


	// Set the transparency color of the sprites, 
	// in this case, it will be bright pink
	dbSetImageColorKey ( 255, 0, 255 );

	// ------------------
	// load the target
	dbLoadImage("Media/target.bmp",T);

	// display the target
	dbSprite(T, 250,0, T );

	// ------------------
	// load the shooter
	dbLoadImage("Media/Shooter.bmp",S);

	// display the shooter
	dbSprite(S,200,460,S); 

	// ------------------
	// begin the animation loop
	// load the Projectile sprite
	dbLoadImage("Media/PROJ.bmp",P);


}
void DgApp::OnLoopTarget(void)
{
	//START the animation of the target//

	// The difficulty of the game, 
	// Make sure this number is either 2, 5, 10, or 50!;
	//int DIF = 5;

	if(R == 1) // RIGHT       >>>>>>
	{
		dbSprite(T, D, 1, T);

		D = D + DIF;

		if(D >= SCREEN_X)
		{
			R = 0;
		}
	}
	else if(R == 0) // LEFT     <<<<<<<<<
	{
		dbSprite(T,D,1,T);

		D = D - DIF;

		if(D <= 0)
		{
			R = 1;
		}
	}
	//END target animation//
}

void DgApp::OnLoopShooter(void)
{
	
	//SCREEN_X=625,
	//SCREEN_Y=460,
	if( dbRightKey() && !(M > SCREEN_X))
	{
		dbSprite(S, M, SCREEN_Y, S);
		M = M + 2;
	}
	if( dbLeftKey() && !(M <= 0))
	{
		dbSprite(S, M, SCREEN_Y, S);
		M = M - 2;
	}
}

void DgApp::OnLoopProjectile(void)
{
	if( dbSpaceKey())
	{
		if(AC == 50)
		{
			dbSprite(P, M, 425, P);
			AC = 0;
		}
	}
	if(AC < 50)//If the projectile is active,
	{
		dbMoveSprite(P, 10);//then make it move
		AC++;
	}
}

void DgApp::OnLoopHitMiss(void)
{
	//START Target hit/missed controls//
	if(AC < 50)
	{
		if((dbSpriteY(P) >= 0 && dbSpriteY(P) <= 10))
		{
			if((dbSpriteX(P) <= (dbSpriteX(T) + 20) 
				&& (dbSpriteX(P) >= (dbSpriteX(T) - 20))))
			{
				//dbDeleteSprite(T);
				OnLoopCrash();
		   }
		}
	}
	//END Target hit/missed controls//
}

void DgApp::OnLoopCrash(void)
{
	//MessageBox(NULL, 
		//"You Won!, Click OK to exit.", "Congrats!", MB_OK);
	//break;
	switch (DIF)
	{
	case 2:
		DIF=5;
		MessageBox(NULL, 
		"Hit!, Click OK to Next Stage.", "Hit!", MB_OK);
		break;
	case 5:
		DIF=10;
		MessageBox(NULL, 
		"Hit!, Click OK to Next Stage.", "Hit!", MB_OK);

		break;
	case 10:
		DIF=20;
		MessageBox(NULL, 
		"Hit!, Click OK to Next Stage.", "Hit!", MB_OK);

		break;
	case 20:
		DIF=50;
		MessageBox(NULL, 
		"Hit!, Click OK to Next Stage.", "Hit!", MB_OK);

		break;
	case 50:
		DIF=50;

		dbDeleteSprite(T);
		
		MessageBox(NULL, 
		"You Won!, Click OK to exit.", "Congrats!", MB_OK);
		break;
	
	}
}
void DgApp::OnLoop(void)
{

	OnLoopTarget();

	//START user input controls//
	OnLoopShooter();
	OnLoopProjectile();
	//END User input controls//

	OnLoopHitMiss();

}
void DgApp::OnRender(void)
{

	// here we make a call to update the contents of the screen
	dbSync ( );

}

void DgApp::OnCleanup(void)
{

	// close the program //

	// delete all the sprites
	for ( int i = 1; i < 30; i++ )
		dbDeleteSprite ( i );

	// delete the backdrop image
	dbDeleteImage ( ID_IMG_BACK );

	dbDeleteImage ( ID_IMG_SHOOTER );

	dbDeleteImage ( T );
	dbDeleteImage ( S );
	dbDeleteImage ( P );


}
void DgApp::OnExecute(void)
{

	OnInit();

	// now we come to our main loop, we call LoopGDK so some internal
	// work can be carried out by the GDK
	while ( LoopGDK ( ) )
	{

		OnLoop();

		// here we check if the escape key has been pressed, when it has
		// we will break out of the loop
		if ( dbEscapeKey ( ) )
			break;


		OnRender();
	}

	OnCleanup();

}

// the main entry point for the application is this function
void DarkGDK ( void )
{
	DgApp app;
	app.OnExecute();

	// and now everything is ready to return back to Windows
	return;
}

'온라인게임' 카테고리의 다른 글

RAID(레이드)의 종류와 개념  (0) 2015.04.28
Dark GDK - Asteroid / 2D  (0) 2011.10.28
DarkGDK - Sprite Animation / 2D  (0) 2011.10.28
Dark GDK - Terrain / 3D  (0) 2011.10.27
Dark GDK - FPS 게임 화면 만들기 / 3D  (3) 2011.10.26

+ Recent posts