Original Post
Hi everyone, I have a bit of a problem.
I'm working on a C++ SDL game. I just recently inputed the ability to scroll through the level with a camera. However, there is a problem. My game is turn based, and the character can fire his bullet past the limits of the camera screen. I want the player to know where the bullet lands, so I decided I would make the camera follow the bullet, keeping the bullet in the middle of the screen until it hits something.
However, for some reason, when I input the code for following the bullet with the camera, the bullet starts off to the side of the character, instead of from his gun. Without the camera following, the bullet starts from his gun as planned. I'm not completely sure why this is happening, but it seems that the bullet doesn't want to travel separately from the camera, and all the changes made with the position of the camera applies to the bullet as well.
Here is some code I have:
When the "Fire" button is clicked:
//Make the bullet position the same as the player position
Bulletx = ((Player1x) - camera.x);
Bullety = ((Player1y) - camera.y);
In function Bullet::move() :
//Move the Bullet
Bulletx += Velx;
Bullety += Vely;
//Make the camera follow the bullet
camera.x = ( Bulletx + bullet->w/2 );camera.y = ( Bullety + bullet->h/2 );
In function Bullet::show() :
//Show the bullet
apply_surface( Bulletx - bullet->w/2, Bullety - bullet->h/2, bullet, screen );
Any ideas as to what I'm doing wrong, or what I can do to fix this problem? Thanks.
I'm working on a C++ SDL game. I just recently inputed the ability to scroll through the level with a camera. However, there is a problem. My game is turn based, and the character can fire his bullet past the limits of the camera screen. I want the player to know where the bullet lands, so I decided I would make the camera follow the bullet, keeping the bullet in the middle of the screen until it hits something.
However, for some reason, when I input the code for following the bullet with the camera, the bullet starts off to the side of the character, instead of from his gun. Without the camera following, the bullet starts from his gun as planned. I'm not completely sure why this is happening, but it seems that the bullet doesn't want to travel separately from the camera, and all the changes made with the position of the camera applies to the bullet as well.
Here is some code I have:
When the "Fire" button is clicked:
//Make the bullet position the same as the player position
Bulletx = ((Player1x) - camera.x);
Bullety = ((Player1y) - camera.y);
In function Bullet::move() :
//Move the Bullet
Bulletx += Velx;
Bullety += Vely;
//Make the camera follow the bullet
camera.x = ( Bulletx + bullet->w/2 );camera.y = ( Bullety + bullet->h/2 );
In function Bullet::show() :
//Show the bullet
apply_surface( Bulletx - bullet->w/2, Bullety - bullet->h/2, bullet, screen );
Any ideas as to what I'm doing wrong, or what I can do to fix this problem? Thanks.