oh, this is a 2d game.
Ok here is the code for a program that fires up to 200 bullets.
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple 2D project that uses Dark GDK
// it can be used as a starting point in making your own 2D games
// 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 )
{
// in this application a backdrop is loaded and then several
// animated sprites are displayed on screen
// when starting a Dark GDK program it is useful to set global
// application properties, we begin by turning the sync rate on,
// this means we control when the screen is updated, we also set
// the maximum rate to 60 which means the maximum frame rate will
// be set at 60 frames per second
dbSyncOn ( );
dbSyncRate ( 60 );
// a call is made to this function so we can stop the GDK from
// responding to the escape key, we can then add in some code in our
// main loop so we can control what happens when the escape key is pressed
dbDisableEscapeKey ( );
// now we will set the random seed value to the timer, this will
// help us to get more random values each time we run the program
dbRandomize ( dbTimer ( ) );
// we are going to display a backdrop for the scene, to do this
// we load our image and give it an ID number of 1, this particular
// image is of a sky at night with stars
dbLoadImage ( "backdrop.bmp", 1 );
// the next step is to create a sprite that uses this image, this
// is achieved by calling dbSprite and passing in a value of 1 for the
// sprites ID, 0 for the X coordinate, 0 for the Y coordinates and a
// value of 1 for the image
dbSprite ( 1, 0, 0, 1 );
// next we will load in some animated sprites, before doing this
// we need to adjust the image color key, by using this function we
// can make a specific color be transparent, in our case we want this
// to be bright pink
dbSetImageColorKey ( 255, 0, 255 );
// in this loop we're going to create some animated sprites, the image
// we load contains frames of animation for an asteroid
// create an animated sprite and give it the ID number from the
// variable i, next is the filename, now we come to how many frames
// across and down, in our case this is 4, finally we come to the image
// ID that the sprite will use, again we use i
dbLoadImage("sprite.bmp",2);
int start=0, finish=0, length=200, count=0, nextsprite=5;
float bullets[200][3];//[int][0] object index//[int][1] x vel//[int][2] y vel...
while ( LoopGDK ( ) )
{
//press the space key to fire a bullet
if(dbSpaceKey()){
dbSprite(nextsprite,200,500,2);
bullets[finish][0]=nextsprite;
bullets[finish][1]=-2;
bullets[finish][2]=-6;
nextsprite++;
finish++;
if(finish>199){
finish=0;
}
}
//update bullets
count=start;
while(count!=finish){
if(bullets[count][0]!=0){//
//update bullet position collision.
dbSprite(bullets[count][0],dbSpriteX(bullets[count][0])+bullets[count][1],dbSpriteY(bullets[count][0])+bullets[count][2],2);
if(dbSpriteY(bullets[count][0])<0){///
//delete bullet
dbDeleteSprite(bullets[count][0]);
bullets[count][0]=0;
if(count==start){
start++;
if(start>199){
start=0;
}
}
}///
}//
count++;
if(count>199){
count=0;
}
}
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 < nextsprite; i++ )
dbDeleteSprite ( i );
// delete the backdrop image
dbDeleteImage ( 1 );
dbDeleteImage ( 2 );
// and now everything is ready to return back to Windows
return;
}
So, you will need a background image( I used the default for 2d projects) and a bullet sprite.
what this does is generates a new sprite every refresh you hold sown the space bar. they have a velocity of -2 in the x and -6 in the y. it stores the sprite number in the [int][0] index of the array bullets. It stores the velocity in the [int][1] and [int][2] indexes of the array.
It then reassigns the finish index of the loop that updates the bullets. I the index exceeds the max of the array 199 then it will be set back to the start. ( note, an array with length 9 has indexes 0,1,2,3,4,5,6,7,8 there are nine numbers but the indexes go from 0-8)
In the update loop if the the bullet with the index of the starting index is deleted the start will step up one, thus shortening the number of loops the program must do. This way the processor does up to 200 loops but only when necessary.
I'll get a new signature someday.