Change this:
for (int i=3;i<1000;i++)
{
Box[i].x-=1;//fixed
dbPasteSprite(3,Box[i].x,Box[i].y);
}
to:
for (int i=0;i<1000;i++)
{
Box[i].x-=1;//fixed
if (Box[i].active) dbPasteSprite(3,Box[i].x,Box[i].y);
}
You have no "destroy box" functionallity. It will only generate a max of 1000 and they will go to the left side of the screen. Once the 1000th box has been generated, there will be no more. Add something like this to your update code:
if (Box[i].x<0) Box[i].active=false;
Here is the entire updated code:
#include "DarkGDK.h"
#include "Dinput.h"
#include <stdio.h>
void DarkGDK ( void )
{
struct BOX
{
bool active;
float x,y;
}Box[1000];
int Score = 0;
char str[200];
bool PlayerFalling = false;
int Timer=0;
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetWindowTitle("RunningMan");
dbSetWindowSize(800,600);
dbSetImageColorKey(255,0,255);
dbLoadImage("Player.bmp",1);
dbLoadImage("Box_down.bmp",3);
dbSprite(1,400,400,1);
dbSprite(3,400,400,3);
dbHideSprite(3);
while ( LoopGDK ( ) )
{
int PlayerY = dbSpriteY(1);
int PlayerX = dbSpriteX(1);
dbSync ( );
Score++;
sprintf_s ( str, 200, "Score: %d",Score );
dbText(10,10,str);
for (int i=0;i<1000;i++)
{
Box[i].x--;
if (Box[i].active) dbPasteSprite(3,Box[i].x,Box[i].y);
if (Box[i].x<0) Box[i].active=false;
}
if (Timer<0)
{
int g;
for(g=0;g<1000;g++) if (!Box[g].active) break;
if (g<1000)
{
Box[g].active=true;
Box[g].x=400;
Box[g].y=dbRnd(400);
Timer=2000;
}
}else Timer--;
if (dbKeyState(DIK_SPACE) == 1 && PlayerFalling != true)
{
dbMoveSprite(1,70);
PlayerFalling = true;
}
if (PlayerFalling == true && PlayerY <= 400)
{
dbMoveSprite(1,-2.5);
}else if (PlayerFalling == true && PlayerY >= 400)
{
PlayerFalling = false;
}
}
return;
}
The fastest code is the code never written.