Alright I'm working on a vertical shooter using the Dark Gdk.My main problem is the enemy planes in the game.The movement is simple enough they move from the top of the screen to the bottom in a straight line..The planes are suppose to shoot a bullet at a random moment as they move down the screen.The Bullet will move straight down relative to the position of the plane that fired it.The problem right now is that for some reason only one plane will fire.Usually quite early in the game.After that one fires none of the other planes will fire.I can't figure out how to get it to fire again... Ok here is the code I have so far...
enemy.h- controls the creation of enemies as well as the firing of bullets
CODE
void enemy()
{
// in this loop we're going to create some enemy sprites
for ( int i = 5; i < 9; i++ )
{
dbLoadImage ("enemy.bmp", i );
// position our sprite at a random location
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
dbScaleSprite(i,50); //scale the sprite by half
}
}
void enemyFire()
{
for (int i =5; i <9; i++)
{
int fire = dbRnd(100); //set a random value to fire
if(fire >85) //if fire is greater than 85
{
for(int j = 10; j < 15; j++)
{
//Create Bullets at the sprite
dbSprite(j,dbSpriteX(i), dbSpriteY(i),4);
spriteX=dbSpriteX(i);
spriteY=dbSpriteY(i);
spriteshot=true;
}
}
}
}
moving.h- handles player movement, bullet and enemy movement
CODE
void moving()
{
if(dbLeftKey() == 1) //If Left key is pressed
{
dbRotateSprite(2,90);
dbMoveSprite(2,-3);
dbRotateSprite(2,0);
}
if(dbRightKey() == 1) //If Right key has been pressed
{
dbRotateSprite(2,90);
dbMoveSprite(2,3);
dbRotateSprite(2,0);
}
if(dbUpKey() == 1) //If the up key has been pressed
{
dbMoveSprite(2,3);
}
if(dbDownKey() == 1) //If the Down Key has been pressed
{
dbMoveSprite(2,-3);
}
dbMoveSprite(3,5); //Move our bullet up the screen
for ( int i = 5; i < 9; i++ )
{
dbMoveSprite(i,-3); //move our enemy sprite down the screen
}
for(int j = 10; j < 15; j++)
{
dbMoveSprite(j, -5); //Move our enemy bullets down the screen
}
}
void collision()
{
for(int i =5; i <9; i++)
{
if(dbSpriteCollision(3,i))
{
dbDeleteSprite(3);
dbDeleteSprite(i);
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
dbScaleSprite(i,50);
}
}
}
void shooting()
{
if(dbSpriteCollision(3,0) == 0) //If the bullet isn't collising with anything
{
if(dbSpaceKey() ==1) //If the shift key is being pressed
{
dbStopSound(2);
dbSprite(3,dbSpriteX(2)+ 25,dbSpriteY(2)+ 25,3);
dbPlaySound(2);
}
}
}
void border()
{
for(int i =5; i <9; i++)
{
if(dbSpriteY(i) > 600)
{
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
dbScaleSprite(i,50);
}
}
}
and finally
main.cpp file
CODE
#include "DarkGDK.h"
//make these global
bool spriteshot;
int spriteX;
int spriteY; //these can also be floats
//---------------
#include "setup.h"
#include "moving.h"
#include "enemy.h"
#include "music.h"
// the main entry point for the application is this function
//---------------
void DarkGDK ( void )
{
setup();
load();
create();
enemy();
enemyFire();
music();
playmusic();
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
moving();
collision();
border();
shooting();
// here we check if the escape key has been pressed, when it has
// we will break out of the loop
if ( dbEscapeKey ( ) )
break;
// here we make a call to update the contents of the screen
dbSync ( );
}
// delete the backdrop image
dbDeleteImage ( 1 );
// and now everything is ready to return back to Windows
return;
}
The part I think is the culprit is in the enemy.h file... the enemyFire() function but I can't quite figure out what to do about it.If anyone has a solution I would gladly try any suggestions on what to do.