Hey all, so I have a pretty basic code and I've hit this problem that is driving me crazy.
Basically, a spaceship (sprite 2) is supposed to fire a bullet (sprite 3) when the user presses the Shift key. Here's the code so far:
#include "DarkGDK.h"
int y=600; //set initial y-position of bullet later on
void shipmove(void);
void DarkGDK ( void )
{
dbSetDisplayMode(1024,768,32);
dbMaximizeWindow();
dbSyncOn ( );
dbSyncRate ( 60 );
dbLoadImage("asssmash.png",1);
dbLoadImage("ship.png",2);
dbLoadImage("bullet.png",3);
dbSprite(1,0,0,1);
dbSprite(2,519,600,2);
while ( LoopGDK ( ) )
{
shipmove();
dbSync ( );
}
return;
}
void shipmove(void)
{
if (dbLeftKey())
{
dbSprite(2,dbSpriteX(2)-7,600,2);
if (dbSpriteX(2)<=0)
dbSprite(2,0,600,2);
}
if (dbRightKey())
{
dbSprite(2,dbSpriteX(2)+7,600,2);
if (dbSpriteX(2)>=980)
dbSprite(2,980,600,2);
}
if (dbShiftKey())
{
dbSprite(3,dbSpriteX(2),600,3);
while(dbSpriteY(3)>0)
{
dbSprite(3,dbSpriteX(2),y,3);
y=dbSpriteY(3)-10;
}
}
}
The problem is, the bullet will always appear at the top of my screen around the (y=30) position or so, not at the y=600 position.
Does anyone know why this would be the case. My guess is that this code here is the culprit:
if (dbShiftKey())
{
dbSprite(3,dbSpriteX(2),600,3);
while(dbSpriteY(3)>0)
{
dbSprite(3,dbSpriteX(2),y,3);
y=dbSpriteY(3)-10;
}
}
Thanks