Posted: 13th Nov 2010 05:42
Edited at: 13th Nov 2010 15:33
Need to make it so a sprite spawns in a point on the other sprite. Its to be like space invaders where you shoot at the gun on the ship. Its where my issue is. If anyone can please help me.
oops didn't include the code...
#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);
}*/
}
Attachments
Login to view attachments