ok... i am making a small shoot em up game much baced on (well sort of) the old game ASTEROIDS but my space ship (space.png) won't shoot its missile (bolt.png) properly. basicall i have a ship and some asteroids in the game. the asteroids fall down at random places wilst rotating through 4 stages of animation (this is the animation you get when you first clck on new dark gdk 2d game) and when i shoot my missile the missile reaches the top of the screen and then it behaves or does exactly what the missiles are doing! please help!!! here is code and attatched is picture.
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
int AC = 50;
dbLoadMusic ( "background music.mp3", 4 );
dbSetDisplayMode ( 1024 , 768 , 32 );
dbSyncOn ( );
dbSyncRate ( 300 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
dbMaximiseWindow();
dbLoadImage ( "background.jpg", 1 );
dbSprite ( 1, 0, 0, 1 );
for ( int i = 3; i < 30; i++ )
{
dbCreateAnimatedSprite ( i, "sprite.png", 4, 4, i );
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
}
int b = 4;
dbLoadImage ("bolt.png", b);
int g = 2;
int XCord=450;
int YCord=460;
dbLoadImage("spaceship.png", g);
dbSprite(g, XCord, YCord, g);//this will display the object
dbPlayMusic(4);
dbLoopMusic(4);
while ( LoopGDK () )
{
for ( int i = 2; i < 30; i++ )
{
// move the sprite down and play its animation
// moving from frame 1 to 16 with a delay of 60 ms
dbMoveSprite ( i, -2 );
dbPlaySprite ( i, 1, 16, 60 );
// check the position of the sprite, if it has gone off scren
// then reposition it back to the top
if ( dbSpriteY ( i ) > 768 )
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
}
if(dbDownKey())//move down
{
YCord++;
YCord++;
YCord++;
YCord++;
YCord++;
}
if(dbUpKey())//move up
{
YCord=YCord-5;
}
if(dbRightKey())//move right
{
XCord++;
XCord++;
XCord++;
XCord++;
XCord++;
}
if(dbLeftKey())//move left
{
XCord=XCord-5;
}
dbSprite(g, XCord, YCord, g);//Set The Cordinates To XCord And YCord
if (XCord > dbScreenWidth())
XCord = 0;
if (XCord < 0)
XCord = dbScreenWidth();
if (YCord > dbScreenHeight())
YCord = 0;
if (YCord < 0)
YCord = dbScreenHeight();
if( dbSpaceKey())
{
if(AC == 50)
{
dbSprite(b, XCord, YCord, b);
AC = 0;
}
}
if(AC < 50)//If the projectile is active,
{
dbMoveSprite(b, 10);//then make it move
AC++;
}
if(AC < 50)//If the projectile is active,
{
dbMoveSprite(b, 10);//then make it move
AC++;
}
// 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 ( );
}
// 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;
}