TGC Codebase Backup



Tank Game by Lysander610

6th Mar 2012 11:01
Summary

My Basic Tank Game with the tank and a projectile (no targets yet)



Description



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

// constant for dbSync 
const int RATE = 10;

//constants for sprites
const int TANK_IMG = 1;
const int TANK_SPRITE = 1;
const int PROJ_IMG = 2;
const int PROJ_SPRITE = 2;
//tank starting points
const int START_X = 0;
const int START_Y = 300;


int tankx = START_X;
int tanky = START_Y;

//prototypes
void getTankCoordinates(int &,int &);
void setUp();

void DarkGDK(){

dbSyncOn();
dbSyncRate(RATE);

while( LoopGDK() ){
	
	setUp();
	getTankCoordinates(tankx,tanky);
	dbSprite(TANK_SPRITE,tankx,tanky,TANK_IMG);
	

	int projx = tankx+170;
	int projy = tanky-20;
	if (dbSpaceKey() ){

		
		dbSprite(PROJ_SPRITE,projx,projy,PROJ_IMG);
		dbRotateSprite(PROJ_SPRITE,315);	

//THIS IS WERE MY PROBLEM IS 
	while (projx<0&&projy<0){
		projx-=10;
		projy-=10;

			}
	dbSprite(PROJ_SPRITE,projx,projy,PROJ_IMG);

	}






dbSync();

}


}


void setUp() {
	dbSetImageColorKey(0,255,0);
	dbLoadImage("proj3.bmp",PROJ_IMG);
	dbLoadImage("tank2.bmp",TANK_IMG);
	dbSprite(TANK_SPRITE,START_X,START_Y,TANK_IMG);
	dbScaleSprite(TANK_SPRITE,75);
}
void getTankCoordinates(int &x,int &y)
    {
		if(y>-20){
		if( dbUpKey() ) y--;
		if(dbUpKey()&&dbShiftKey() ) y-=5;
		
		
			}
	if(y<400){
		if (dbDownKey() ) y++;
		if(dbDownKey()&&dbShiftKey() ) y+=5; 
					}
	if(x>0){
		if( dbLeftKey() ) x--;
		if(dbLeftKey()&&dbShiftKey() ) x-=5; 
		
			}
	if(x<580){
		if( dbRightKey() ) x++;
		if(dbRightKey()&&dbShiftKey() ) x+=5; 
		
			}
	}