I trying to make some kind of Tank game. I managed to program movement and bullet sprite creation. If bullet after certain time does not hit anything it should disappear. dbDeleteSprite should do that. But that function somehow modifies my bullet variable which is sprite ID. On First run that variable has value of 2. After pressing W key Sprite is created and it moves. After Deleting Sprite bullet variable has value of 302 instead of 3. If I delete "dbDeleteSprite" from code everything works normally.
This Happens:
Uploaded with
ImageShack.com
If i delete dbDeleteSprite function:
Uploaded with
ImageShack.com
which is normal
Is this bug in library or what?
Here is Full Code:
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetImageColorKey(0,128,128);
dbLoadImage("Media\\Tank.bmp",1);
dbLoadImage("Media\\bullet.bmp",2);
dbLoadImage("Media\\test1.bmp",3);
dbLoadImage("Media\\test2.bmp",4);
dbSprite(1,320,240,1);
dbSizeSprite(1,34,34);
dbOffsetSprite(1,17,17);
int bullet=2,KeyBoardTimerNum=0,TimerBullet[5]={0,0,0,0,0},angle=0,angle2;
bool KeyBoardTimer=false,Timer2=false;
while ( LoopGDK ( ) )
{
if(KeyBoardTimer==true)
{
KeyBoardTimerNum++;
if(KeyBoardTimerNum==30)
{
KeyBoardTimer=false;
KeyBoardTimerNum=0;
}
}
dbText(320,280,dbStr(bullet)); //Used for Debugging
if(dbUpKey()==1)
dbMoveSprite(1,1);
if(dbLeftKey()==1){
angle--;
dbRotateSprite(1,angle);
if(angle==-360)
angle=0;
}
if(dbRightKey()==1){
angle++;
dbRotateSprite(1,angle);
if(angle==360)
angle=0;
}
if(dbDownKey()==1)
{
for(int i=1;i<361;i++)
{
if((dbSIN(angle)+dbSIN(i)>-0.01)&&(dbSIN(angle)+dbSIN(i)<0.01)&&(dbCOS(angle)+dbCOS(i)>-0.01)&&(dbCOS(angle)+dbCOS(i)<0.01))
angle2=i;
}
dbRotateSprite(1,angle2);
dbMoveSprite(1,1);
dbRotateSprite(1,angle);
}
if((dbKeyState(17)==1)&&(KeyBoardTimer==false))
{
if(dbSpriteExist(bullet)==0)
{
dbSprite(bullet,dbSpriteX(1),dbSpriteY(1),2);
dbRotateSprite(bullet,angle);
bullet++; //here bullet variable increments
if(bullet==7)
{
bullet=2;
}
KeyBoardTimer=true;
}
}
for (int i=2;i<7;i++)
{
if(dbSpriteExist(i)==1)
{
if(TimerBullet[i-2]==20)
{
dbDeleteSprite(i); //If i delete this function bullet variable increments as it should
TimerBullet[i-2]=0; //Reseting Timer
}
dbMoveSprite(i,3);
TimerBullet[i-2]++; //Timer
}
}
if (dbEscapeKey()==1)
break;
dbSync ();
}
return;
}