TGC Codebase Backup



pwned 2d game by DeadTomGC

3rd Aug 2010 16:54
Summary

exciting multiplayer game



Description

player1
use 1 and 2 to move s and d to rotate and left ctrl to fire

player2
use k and l to move 9 and 0 to rotate and / to fire

Shoot the rocks to make them bounc around. If you get hit by a rock you will move up.
Last to the top wins!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    /////////////method.h//////////////
#include "DarkGDK.h"

bool dropok=true;
int newshot=0;
int newrock=0;
int newsprite=10;
float shots[100][3];
float rocks[100][4];
float temp=0;
float temptwo=0;
int startr=0;
int finishr=0;
int starts=0;
int finishs=0;
int update=0;
int updatetwo=0;
float movement=0;
float movementr=0;
float xone=0;
float yone=0;

float xtwo=0;
float ytwo=0;

bool fire1=false;
bool fire2=false;
bool hold1=false;
bool hold2=false;

int score1=0;
int score2=0;

bool safe=false;
void dropper( void );

void dropper( void ){
////////////////
	if(dbKeyState(57)){
		if(safe==false){

dropok =true;
dbDeleteSprite(rocks[newrock][0]);
rocks[newrock][0]=0;


		}
safe=true;

	}else{
safe=false;

	}
	////////////////////////
	if( dropok ==true){

newrock=newrock+1;
if(newrock>99){
newrock=0;



}
rocks[newrock][0]=newsprite;
newsprite++;
	dbCreateAnimatedSprite ( rocks[newrock][0], "sprite.bmp", 4, 4, 9 );

       dbSprite ( rocks[newrock][0], dbRnd ( dbScreenWidth() -dbSpriteWidth(rocks[newrock][0])/2), -dbSpriteHeight(rocks[newrock][0]), 9 );

	   dbScaleSprite(rocks[newrock][0],20);
  dbSprite ( rocks[newrock][0], dbRnd ( dbScreenWidth() -dbSpriteWidth(rocks[newrock][0])/2), -dbSpriteHeight(rocks[newrock][0]), 9 );
dbScaleSprite(rocks[newrock][0],10);
rocks[newrock][1]=0;
rocks[newrock][2]=2;
    finishr=newrock;



	}


	if(dbSpriteY(rocks[newrock][0])>0 || rocks[newrock][0]==0){
dropok=true;

	}else{
dropok=false;
	}


}

void updaterock( void);

void updaterock( void ){
update=startr-1;
while(update!=finishr){
update++;
if(update>99){

update=0;
}
if(rocks[update][0]!=0){
dbSprite (rocks[update][0], dbSpriteX(rocks[update][0])+rocks[update][1],dbSpriteY(rocks[update][0])+rocks[update][2],dbSpriteImage(rocks[update][0]) );
			dbPlaySprite ( rocks[update][0], 1, 16, 60 );
			if(dbSpriteY(rocks[update][0])>dbScreenHeight()-dbSpriteHeight(rocks[update][0]) && rocks[update][3]==0){

dbDeleteSprite(rocks[update][0]);
rocks[update][0]=0;

}
///////////////

			if(rocks[update][3]==1){

if(dbSpriteY(rocks[update][0])<0 || dbSpriteY(rocks[update][0])>dbScreenHeight()-dbSpriteHeight(rocks[update][0])){

	rocks[update][2]=rocks[update][2]*-1;


}
if(dbSpriteX(rocks[update][0])<0 || dbSpriteX(rocks[update][0])>dbScreenWidth()-dbSpriteWidth(rocks[update][0])){

	rocks[update][1]=rocks[update][1]*-1;


}
/////////////


updatetwo=startr-1;
while(updatetwo!=finishr){
updatetwo++;
if(updatetwo>99){

updatetwo=0;
}
		if(rocks[updatetwo][0]!=0 && rocks[update][0]!=rocks[updatetwo][0]){
if(dbSpriteCollision(rocks[updatetwo][0],rocks[update][0])){

//dbDeleteSprite(rocks[update][0]);
//rocks[update][0]=0;

rocks[updatetwo][3]=1;

temp=rocks[updatetwo][1];
temptwo=rocks[updatetwo][2];

rocks[updatetwo][1]=rocks[update][1];
rocks[updatetwo][2]=rocks[update][2];

rocks[update][1]=temp*-1;
rocks[update][2]=temptwo*-1;

//dbDeleteSprite(rocks[updatetwo][0]);
//rocks[updatetwo][0]=0;



}
		}

}


///////////

			}

			////////////


			

			if(dbSpriteCollision(rocks[update][0],2)){

dbDeleteSprite(rocks[update][0]);
rocks[update][0]=0;
yone=yone-20;
score2++;




			}
if(dbSpriteCollision(rocks[update][0],3)){

dbDeleteSprite(rocks[update][0]);
rocks[update][0]=0;
ytwo=ytwo-20;
score1++;



			}

			


}




			if(rocks[update][0]==0 && update==startr){
startr++;
if(startr>99){
startr=0;		
}
			}


}

}



void playerone(void);

void playerone(void){
if(dbKeyState ( 2 )==0 && dbKeyState ( 3 )==0){
movement=0;


	}
	if(dbKeyState ( 2 ) ){
movement=-3;


	}
if(dbKeyState ( 3 ) ){
movement=3;


	}
if(dbKeyState ( 29 )){
	if(hold1==false){

fire1=true;

	}else{
fire1=false;

	}
hold1=true;
}else{
hold1=false;
fire1=false;
}





// 22 25 55
xone=xone+movement;
dbSprite(2,xone,dbSpriteY(2),2);

movement=0;

if(dbKeyState ( 31 )){
movementr=-3;


	}

if(dbKeyState ( 32 )){
movementr=3;


	}
if(dbKeyState ( 31 )==0 && dbKeyState ( 32 )==0){
movementr=0;


	}
xone=xone+39*dbSin(dbSpriteAngle(2)-27+movementr)-39*dbSin(dbSpriteAngle(2)-27);
yone=yone-39*dbCos(dbSpriteAngle(2)-27+movementr)+39*dbCos(dbSpriteAngle(2)-27);
dbSprite(2,xone,yone,2);


dbRotateSprite(2,dbSpriteAngle(2)+movementr);


} //27 130




//////////////////////////
void blasterone( void );

void blasterone( void ){
	if(fire1==true){
shots[newshot][0]=newsprite;
newsprite++;
dbSprite(shots[newshot][0],dbSpriteX(2)+dbCos(dbSpriteAngle(2))*(dbSpriteWidth(2)/2-dbSpriteWidth(shots[newshot][0])/2),dbSpriteY(2)+dbCos(dbSpriteAngle(2))*(dbSpriteWidth(2)/2-dbSpriteWidth(shots[newshot][0])/2),4);
dbScaleSprite(shots[newshot][0],15);
dbSprite(shots[newshot][0],dbSpriteX(2)+dbCos(dbSpriteAngle(2))*(dbSpriteWidth(2)/2-dbSpriteWidth(shots[newshot][0])/2),dbSpriteY(2)+dbCos(dbSpriteAngle(2))*(dbSpriteWidth(2)/2-dbSpriteWidth(shots[newshot][0])/2),4);

shots[newshot][1]=10*dbSin(dbSpriteAngle(2));
shots[newshot][2]=10*dbCos(dbSpriteAngle(2));

newshot=newshot+1;
if(newshot>99){
newshot=0;


}
finishs=newshot;


	}

}

///////////////////////////////////////////////////

void playertwo(void);

void playertwo(void){

	if(dbKeyState ( 37 ) ){
movement=-3;


	}
if(dbKeyState ( 38 )){
movement=3;


	}
if(dbKeyState ( 53 )){
	if(hold2==false){

fire2=true;

	}else{
fire2=false;

	}
hold2=true;
}else{
hold2=false;
fire2=false;
}

if(dbKeyState ( 37 )==0 && dbKeyState ( 38 )==0){
movement=0;


	}



// 22 25 55
xtwo=xtwo+movement;
dbSprite(3,xtwo,dbSpriteY(3),3);

movement=0;

if(dbKeyState ( 10 )){
movementr=-3;


	}

if(dbKeyState ( 11 )){
movementr=3;


	}
if(dbKeyState ( 10 )==0 && dbKeyState ( 11 )==0){
movementr=0;


	}
xtwo=xtwo+39*dbSin(dbSpriteAngle(3)-27+movementr)-39*dbSin(dbSpriteAngle(3)-27);
ytwo=ytwo-39*dbCos(dbSpriteAngle(3)-27+movementr)+39*dbCos(dbSpriteAngle(3)-27);
dbSprite(3,xtwo,ytwo,3);


dbRotateSprite(3,dbSpriteAngle(3)+movementr);


} //27 130





//////////////////////////////////////////////////////
void blastertwo( void );

void blastertwo( void ){
	if(fire2==true){
shots[newshot][0]=newsprite;
newsprite++;
dbSprite(shots[newshot][0],dbSpriteX(3)+dbCos(dbSpriteAngle(3))*(dbSpriteWidth(3)/2-dbSpriteWidth(shots[newshot][0])/2),dbSpriteY(3)+dbCos(dbSpriteAngle(3))*(dbSpriteWidth(3)/2-dbSpriteWidth(shots[newshot][0])/2),4);
dbScaleSprite(shots[newshot][0],15);
dbSprite(shots[newshot][0],dbSpriteX(3)+dbCos(dbSpriteAngle(3))*(dbSpriteWidth(3)/2-dbSpriteWidth(shots[newshot][0])/2),dbSpriteY(3)+dbCos(dbSpriteAngle(3))*(dbSpriteWidth(3)/2-dbSpriteWidth(shots[newshot][0])/2),4);

shots[newshot][1]=10*dbSin(dbSpriteAngle(3));
shots[newshot][2]=10*dbCos(dbSpriteAngle(3));

newshot=newshot+1;
if(newshot>99){
newshot=0;


}
finishs=newshot;


	}

}

void updateshots( void );

void updateshots( void ){
update=starts;
while(update!=finishs){

	if(shots[update][0]!=0){

dbSprite(shots[update][0],dbSpriteX(shots[update][0])+shots[update][1],dbSpriteY(shots[update][0])-shots[update][2],dbSpriteImage(shots[update][0]));

if(dbSpriteX(shots[update][0])<0 || dbSpriteX(shots[update][0])>dbScreenWidth() || dbSpriteY(shots[update][0])<0 || dbSpriteY(shots[update][0])>dbScreenHeight()){
dbDeleteSprite(shots[update][0]);
shots[update][0]=0;
	
	
	}

updatetwo=startr-1;
while(updatetwo!=finishr){
updatetwo++;
if(updatetwo>99){

updatetwo=0;
}
		if(rocks[updatetwo][0]!=0 && shots[update][0]!=0){
if(dbSpriteCollision(rocks[updatetwo][0],shots[update][0])){

dbDeleteSprite(shots[update][0]);
shots[update][0]=0;
//dbDeleteSprite(rocks[updatetwo][0]);
//rocks[updatetwo][0]=0;
rocks[updatetwo][3]=1;
rocks[updatetwo][1]=rocks[updatetwo][1]+shots[update][1];
rocks[updatetwo][2]=rocks[updatetwo][2]-shots[update][2];

}
		}
		

}







}


if(update==starts && shots[update][0]==0){
	starts++;
	if(starts>99){
starts=0;

	}

	}

update++;
if(update>99){

update=0;

}
}






}
/////////////////////////main.h//////////////////////////

// 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"
#include "method.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
	// in this application a backdrop is loaded and then several
	// animated sprites are displayed on screen
dbSetDisplayMode ( 1024+24+24+24+24+24+24+24+24+24+24 , 768-24 , 32 );
dbMaximiseWindow();
	// when starting a Dark GDK program it is useful to set global
	// application properties, we begin by turning the sync rate on,
	// this means we control when the screen is updated, we also set
	// the maximum rate to 60 which means the maximum frame rate will
	// be set at 60 frames per second
	dbSyncOn   ( );
	dbSyncRate ( 60 );

	// a call is made to this function so we can stop the GDK from
	// responding to the escape key, we can then add in some code in our
	// main loop so we can control what happens when the escape key is pressed
	

	// now we will set the random seed value to the timer, this will
	// help us to get more random values each time we run the program
	dbRandomize ( dbTimer ( ) );

	// we are going to display a backdrop for the scene, to do this
	// we load our image and give it an ID number of 1, this particular
	// image is of a sky at night with stars
	dbLoadImage ( "backdrop.bmp", 1 );

	// the next step is to create a sprite that uses this image, this
	// is achieved by calling dbSprite and passing in a value of 1 for the
	// sprites ID, 0 for the X coordinate, 0 for the Y coordinates and a
	// value of 1 for the image
	dbSprite ( 1, 0, 0, 1 );
dbSizeSprite(1,1024+24+24+24+24+24+24+24+24+24+24 ,768-24);
	// next we will load in some animated sprites, before doing this
	// we need to adjust the image color key, by using this function we
	// can make a specific color be transparent, in our case we want this
	extern float xone;
extern float yone;

extern float xtwo;
extern float ytwo;
xone=0;
 yone=dbScreenHeight()-dbSpriteHeight(2);

 xtwo=200;
ytwo=dbScreenHeight()-dbSpriteHeight(3);



// to be bright pink

	dbSetImageColorKey ( 255, 0, 255 );
dbLoadImage("sprite.bmp",9);
dbLoadImage("ship1.bmp",2);
dbSprite(2,0,dbScreenHeight()-dbSpriteHeight(2),2);
dbScaleSprite(2,30);

///////////////initilize x and y
dbSprite(2,0,dbScreenHeight()-dbSpriteHeight(2),2);
dbLoadImage("ship2.bmp",3);
dbSprite(3,0,dbScreenHeight()-dbSpriteHeight(3),3);
dbScaleSprite(3,30);
dbSprite(3,200,dbScreenHeight()-dbSpriteHeight(3),3);
//////////
xone=0;
 yone=dbScreenHeight()-dbSpriteHeight(2);

 xtwo=200;
ytwo=dbScreenHeight()-dbSpriteHeight(3);

dbLoadImage("shot.bmp",4);
	// in this loop we're going to create some animated sprites, the image
	// we load contains frames of animation for an asteroid
	
		// create an animated sprite and give it the ID number from the
		// variable i, next is the filename, now we come to how many frames
		// across and down, in our case this is 4, finally we come to the image
		// ID that the sprite will use, again we use i
		dbPerformChecklistControlDevices();
//dbSetControlDevice ( dbChecklistString(dbChecklistQuantity()-1) ) ;

		// position our sprite at a random location
		
	

	// now we come to our main loop, we call LoopGDK so some internal
	// work can be carried out by the GDK
	while ( LoopGDK ( ) )
	{dropper();
		// run a loop through all our sprites
		updaterock();
playerone();
blasterone();
playertwo();
 blastertwo();

updateshots( );

dbText(0,0,dbGetControlDevice ());
		// here we check if the escape key has been pressed, when it has
		// we will break out of the loop
		if ( dbEscapeKey ( ) )
			break;
dbText(200,200,dbStr(dbScanCode (  ) ));
		// here we make a call to update the contents of the screen
		dbSync ( );
	}

	// when the user presses escape the code will break out to this location
	// and we can free up any previously allocated resources
	
	// delete all the sprites
	for ( int i = 1; i < 30; i++ )
		dbDeleteSprite ( i );

	// delete the backdrop image
	dbDeleteImage ( 1 );

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