www.pudn.com > sxdl.zip > Game.cpp


#include "Game.h" 
 
Game game ; 
 
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) 
{ 
    return game.FrameworkRun ( hInst ) ; 
} 
 
 
Resource Game::Resources [ ] =  
{ 
	{ MidiMusic ,	Resource::Music   , NULL , true , "onestop.mid" } ,   
	{ Player    ,   Resource::Texture , NULL , true , "player1.png" } ,   
	{ Player_bis,   Resource::Texture , NULL , true , "player2.png" } ,   
	{ Projectile,   Resource::Texture , NULL , true , "projectile.png" } ,   
	{ Ball      ,   Resource::Texture , NULL , true , "ball.png" } ,   
	{ Explode   ,   Resource::Texture , NULL , true , "explode.png" } ,  	 
	{ Wall      ,   Resource::Texture , NULL , true , "wall.png" } ,  	 
	{ Life      ,   Resource::Texture , NULL , true , "life.png" } , 
	{ Bonus     ,   Resource::Texture , NULL , true , "bonus.png" } , 
	{ Eclat     ,   Resource::Texture , NULL , true , "eclat.png" } , 
	// Must end with a zero id  
	{ Null , Resource::Null , NULL , false , NULL } ,   
} ;  
 
 
void Game::OnStartup ( void )  
{ 
	FrameworkName ( TEXT ( "Pang Remake by abyssahx" ) ) ;  
	//FrameworkMode ( FullScreen ) ;  
	//FrameworkWindow ( 1024 , 768 , false ) ;  
	FrameworkWindow ( 760 , 620 , false ) ;  
	Media.Table ( Resources ) ;  
} 
 
 
void Game::OnCreateGame ( void )  
{ 
	Timing.Speed ( 1.0f ) ; // game time is real time 
	Music.Play ( ( int ) MidiMusic ) ;  
	 
	Font = new CFont ( _T("Impact"), 24 , CFont::Bold ) ; 
 
//Création des sprites	 
	//  Animation pour le joueur 
	// Left; Right; Up; Down 
	PlayerSprites [ 0 ] = new CMovieSprite ( Player, 0x90FFFFFF, 8, 8,  0,  0, 30, 32, false ) ; 
	PlayerSprites [ 1 ] = new CMovieSprite ( Player, 0x90FFFFFF, 8, 8,  0, 33, 30, 32, false ) ; 
	PlayerSprites [ 2 ] = new CMovieSprite ( Player, 0x90FFFFFF, 1, 1,  0, 67, 32, 32, false ) ; 
	PlayerSprites [ 3 ] = new CMovieSprite ( Player, 0x90FFFFFF, 1, 1, 32, 67, 32, 32, false ) ;	 
	 
	Player2Sprites [ 0 ] = new CMovieSprite ( Player_bis, 0x90FFFFFF, 8, 8,  0,  0, 30, 32, false ) ; 
	Player2Sprites [ 1 ] = new CMovieSprite ( Player_bis, 0x90FFFFFF, 8, 8,  0, 33, 30, 32, false ) ; 
	Player2Sprites [ 2 ] = new CMovieSprite ( Player_bis, 0x90FFFFFF, 1, 1,  0, 67, 32, 32, false ) ; 
	Player2Sprites [ 3 ] = new CMovieSprite ( Player_bis, 0x90FFFFFF, 1, 1, 32, 67, 32, 32, false ) ;	 
 
	BonusSprites [ 0 ] = new CMovieSprite ( Bonus, 0x90FFFFFF, 8, 8, 0, 64, 32, 32, false ) ;	 
	BonusSprites [ 1 ] = new CMovieSprite ( Bonus, 0x90FFFFFF, 8, 8, 0,  0, 32, 32, false ) ;	 
	 
	ProjectileSprites = new CBasicSprite ( Projectile, 0x90FFFFFF, 0, 8, 14, 32) ; 
	 
	WallSprites = new CBasicSprite ( Wall, 0x90FEFEFE, 0, 0, 64, 64) ; 
 
	EclatSprites = new CBasicSprite ( Eclat, 0x90FEFEFE, 0, 0, 64, 64) ; 
	 
	LifeSprites = new CBasicSprite ( Life, 0x90FFFFFF, 0, 0, 32, 32) ; 
 
	// define white blue, red, gold, green, etc colors for sprites, all with about 50% alpha  
	Color Colors [ 10 ] =  
	{  
		0x9000EECC , 0x9022EE00 , 0x90CC0033 , 0x90AA0099 , 0x90EEAA00 ,  
		0x9022AA77 , 0x90118833 , 0x90AA1111 , 0x90881166 , 0x90AA7711  
	} ; 	 
	 
	// On crée des sprites balle de diferentes couleurs 
	for ( int i = 0 ; i < 10 ; ++ i )  
	{  
		BallSprites [ i ] = new CBasicSprite ( Ball , Colors [ i ] ,  0 ,  0 , 48 , 40 ) ;  
	} ; 	 
	 
/////////////// Gestion a faire par un menu !!!!!!!!!!!!!!	 
	PlayerNb = 1; 
	 
// Gestion des joueurs 
	Player1 = new CPlayer ( PlayerSprites , 0);  
 
	// disable mouse and joystick axis input  
	Input.EnableMouseAxis ( false ) ;  
	Input.EnableJoystickAxis ( false ) ;  
	// Send player #1 keys to only one guy  
	Input.Register ( Player1 , CInput::UpDown_1 ) ;  
	Input.Register ( Player1 , CInput::LeftRight_1 ) ;  
	Input.Register ( Player1 , CInput::FirePrimary ) ;  
	 
	// Mode 2 joueur 
	if (PlayerNb > 1) 
	{ 
		Player2 = new CPlayer ( Player2Sprites , 1);  
		// Turn input into multiplayer mode 
		Input.SetMode ( CInput::TwoPlayers ) ; 		 
		 
		// Send player #2 keys to the other guy  
		Input.Register ( Player2 , CInput::UpDown_2 ) ;  
		Input.Register ( Player2 , CInput::LeftRight_2 ) ;  
		Input.Register ( Player2 , CInput::FireSecondary ) ;  
	} 
 
//Pour que les balles rebondissent de moins en moins haut 
	World.Viscosity = 0.04f ; 
 
//gestion de collision 
	ColliderPlayerBall     = new CCollider ( FPlayer     , FBall ) ;  
	ColliderProjectileBall = new CCollider ( FProjectile , FBall ) ;  
	ColliderBallWall       = new CCollider ( FBall       , FWall ) ; 
	ColliderPlayerWall     = new CCollider ( FPlayer     , FWall ) ; 
	ColliderPlayerBonus    = new CCollider ( FPlayer     , FBonus ) ; 
	ColliderPlayerPlayer   = new CCollider ( FPlayer     , FPlayer ) ; 
	 
	ColliderPlayerBall->Enable ( ) ; 
	ColliderProjectileBall->Enable ( ) ; 
	ColliderBallWall->Enable ( ) ; 
	ColliderPlayerWall->Enable ( ) ; 
	ColliderPlayerBonus->Enable ( ) ; 
	 
	ColliderPlayerPlayer->Enable ( ) ; 
	 
	 
// On crée les mur 
	new CWall ( WallSprites, -300 ,    0 ,  20 , 620 ) ;  
	new CWall ( WallSprites,  300 ,    0 ,  20 , 620 ) ;  
	new CWall ( WallSprites,    0 , -300 , 620 ,  20 ) ;  
	new CWall ( WallSprites,    0 ,  300 , 620 ,  20 ) ; 	 
	 
// C'est parti ... 
	BallCount = 0; 
	GameMode = true ;  
	Timing.SetTimer ( Start , 1.0f , true ) ; // one shot 	 
	Level = 0; 
} 
 
 
bool Game::OnQuitMenu ( float ElapsedTime , float AbsoluteTime )  
{ 
// Au revoir ...	 
	UserInterface.Exit ( ) ;  
	return false ;  
 }  
 
  
void Game::OnTimer ( int TimerId )  
{ 
	int i; 
	switch ( TimerId )  
	{ 
//Debut du jeu/nouveau niveau		 
	case Start :  
		for(i=0;iInvincible = false; 
		break; 
	case P2NoInvincible : 
		// Si 2 joueur  
		if (PlayerNb > 1) 
			Player2->Invincible = false; 
		break;		 
	}  
}  
 
void Game::OnNewLevel ( void )  
{ 
// Niveau suivant	 
	Level ++ ;  
 
// Tout les 3 niveaux, une grosse balle	 
	if ((Level+1)%3 == 0) 
		Timing.SetTimer ( StartBoss , 1.0f , true ) ; 
// Sinon normal		 
	else 
		Timing.SetTimer ( Start , 1.0f , true ) ; 
	 
} 
 
 
void Game::OnRenderText ( float ElapsedTime , float AbsoluteTime )  
{ 
	D3DCOLOR fontColor = D3DCOLOR_ARGB(200,128,255,200 ); 
 
	TCHAR szMsg[MAX_PATH] ; 
	//_sntprintf( szMsg, MAX_PATH, _T("Level: %d - Score: %d"), Level , game.Player1->point ) ; 
	//Font->DrawTextScaled ( -0.2f , 0.95f , 0.07f , 0.07f , fontColor, szMsg ); 
 
	_sntprintf( szMsg, MAX_PATH, _T("Player 1 - Score: %d"), game.Player1->point ) ; 
	Font->DrawTextScaled ( -0.75f , 0.90f , 0.07f , 0.07f , fontColor, szMsg ); 
 
	if (game.PlayerNb > 1) 
	{ 
		_sntprintf( szMsg, MAX_PATH, _T("Player 2 - Score: %d"), game.Player2->point ) ; 
		Font->DrawTextScaled ( 0.05f , 0.90f , 0.07f , 0.07f , fontColor, szMsg ); 
	} 
 
}  
 
///////////////////////////// 
 
 
CWall::CWall ( CBasicSprite * Sprite, int x , int y , int cx , int cy )  
{ 
	Family   = ( int ) Game::FWall ;  
	Mass     = 0.0f ;  
	Position = Vector3 ( ( float )  x , ( float )  y , 0.0f ) ;  
// Normal : Direction pour les rebonds	 
	Normal   = - Position ;  
	D3DXVec3Normalize ( & Normal , & Normal ) ;  
	Scale    = Vector3 ( ( float ) cx , ( float ) cy , 0.0f ) ;  
	WillRenderLike ( Sprite ) ;  
	DoWorldMatrix ( ) ;  
 
// On l'affiche mais il bouge pas ! 
	Activate ( true , true ) ;  
}  
 
void CWall::OnCollide ( CEntity * CollidingEntity )  
{ 
// les collisions sont gerées ailleurs!! 
}