Hello, I am trying to make a simple shooter. However whenever I try to make it, so that you shoot a bullet, the bullet does not appear correctly, or it does not move. I'm using C++ and SDL2. I can post more code if it is needed.
//Init values, X and Y and X_Vel and Y_Vel are declared as floats.
gBullet.Img = IMG_Load("bullet.png");
gBullet.Tex = SDL_CreateTextureFromSurface(GameRen, gBullet.Img);
//gBullet.X = 0.0f;
gBullet.Y = gPlayer.Y;
//gBullet.X_Vel = 0.0f;
gBullet.Y_Vel = 0.0f;
gBullet.Width = 32;
gBullet.Height = 32;
gBullet.isAlive = false;
//gBullet.Rect.x = (int)gBullet.X;
gBullet.Rect.y = (int)gBullet.Y;
gBullet.Rect.w = gBullet.Width;
gBullet.Rect.h = gBullet.Height;
gBullet.Timer = 0.05f;
//Supposed to fire bullet when space is pressed
if (event.key.keysym.sym == SDLK_SPACE)
{
gBullet.isAlive = true;
gBullet.Y_Vel = 0.05f;
gBullet.Y -= gBullet.Y_Vel;
gBullet.Rect.y = (int)gBullet.Y;
}
//Draw bullet
if (gBullet.isAlive)
{
SDL_RenderCopy(GameRen, gBullet.Tex, NULL, &gBullet.Rect);
}