Hello
I was trying to make some simple demo to learn basics of the physics. I want the cannon to shoot single bullet whenever I press left mouse button.
I have the bullet class, that stores variables such as veolocities, position etc. Here is my problem:
//bullet myBullet(90, 530, 20, -20, 1);
while(!quit)
{
fps.start();
while(SDL_PollEvent(&event))
{
if(event.type==SDL_QUIT) quit=true;
if(event.type==SDL_MOUSEBUTTONDOWN)
{
// creating the object
if(event.button.button==SDL_BUTTON_LEFT) bullet myBullet(90, 530, 20, -20, 1);
}
}
myBullet.update(); //calculating position etc
// RENDERING
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
myBullet.show();
my_AttachImage(10, 520, cannon, screen);
SDL_Flip(screen);
if(fps.getTicks()<1000/FPS) SDL_Delay(1000/FPS-fps.getTicks());
}
I keep getting error on the myBullet.update() line. It says: |error: 'myBullet' was not declared in this scope|. Everything works when I create the object before the main loop ( the commented line that you can see ). But I need the bullet to be created when i press LMB. How can I have it working?