TGC Codebase Backup



Planet Defender by LostNightRecon

12th Nov 2010 23:27
Summary

I am using this for a final project for my programming class. It is a basic code using original art trying to make something like space invaders.



Description

I need some help with a few things on it and it isn't finished. I was hoping to ask questions on it. If anyone can help me please don't hesitate. I'm still new to the program, I welcome any advice.



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

//Funcition prototypes
void MoveShip(int &);
void Setup();
void Fire();

//global constants
int Shipx = 320;
int Shipy = 250;
int x = Shipx/2 ;
int y = Shipy + 10;

//Sprite Constants
const int Ship = 1;
const int Space = 2;
const int Planet = 3;
const int Shot = 5;

void DarkGDK()
{
	//Show the name of the game
	dbSetWindowTitle("Planet Defender");

	//Display the intro screen then wait for the key press
	dbLoadImage("Intro.bmp", 1);
	dbPasteImage(1, 0, 0);                                                                                                                                                          
	dbWaitKey();

	//run the set up program
	Setup();

	//screen refresh
	dbSyncOn();
	dbSyncRate(60);

	//Game Loop
	while ( LoopGDK () )
	{
		//clear the screen
		dbCLS();

		//detect motion for the ship then move it
		MoveShip(Shipx);
		dbSprite(Ship, Shipx, Shipy, 4);

		//Shoot on space to hit an object
		Fire();

		//resync the screen
		dbSync();
	}

	dbWaitKey();

}


void Setup()
{

	//set in the intro screen then the space with the planet.
	dbLoadImage("Planet.bmp", 2);
	dbLoadImage("Space.bmp", 3);
	dbLoadImage("Ship.bmp", 4);
	dbLoadImage("Shot.bmp", 5);

	//Create the sprites
	dbSprite(Space, 0, 0, 3);
	dbSprite(Planet, 0, 300, 2);
	dbSprite(Ship, Shipx, Shipy, 4);
	dbSprite(Shot, x, y, 5);

	//hide sprites that are not needed full time
	dbHideSprite(Shot);
}

void MoveShip (int &Shipx)
{
	if ( dbLeftKey() )
	{
		if(Shipx !=0 )
		{
			Shipx--;
		}
	}
	if ( dbRightKey() )
	{
		if(Shipx != 589)
		{
			Shipx++;
		}
	}
}
void Fire()
{
	//turn off the sync
	dbSyncOff();

	//show the shot
	if(dbReturnKey())
	{
		dbSprite(Shot, x, y, 5);
	}

	dbMoveSprite(Shot, 1);

/*	if()
	{
		dbHideSprite(Shot);
	}*/
}