我正在开发一款太空射击游戏,但在我释放空格键后,我无法弄清楚如何让子弹继续射击到屏幕的尽头。到目前为止,如果我按下它发射的空格键,当我释放它时,子弹就会停留在它们离开的地方。这是我在 main() 中按顺序调用的类。
class Projectile : public Character
{
private:
float xVel;
float yVel;
float x;
float y;
public:
void init();
void keys();
void move();
void show();
}bullet;
void Projectile::init()
{
x=315;
y=305;
xVel=0;
yVel=0;
}
void Projectile::keys()
{
bool shoot = true;
Uint8 *keystates = SDL_GetKeyState( NULL );
if(keystates[SDLK_SPACE])
{
yVel-=14;
}
}
void Projectile::move()
{
x=x+xVel;
y=y+yVel;
xVel=0;
yVel=0;
if(y<0)
{
x=charx;
y=chary;
}
}
void Projectile::show()
{
apply_surface(x-5,y-2,jizz,screen);
cout << y << endl;
}