This isn't exactly how you're expected to use SDL. SDL_GetTicks, for one, doesn't start a timer. It returns the amount of time that has gone by since your program started.
Example:
int main() //<-- SDL_GetTicks is set to 0 here, and starts counting up.{ SDL_Init(SDL_INIT_EVERYTHING); //Or possibly starts here, I'm honestly not too sure. =) ... Uint32 time = SDL_GetTicks(); //'time' is now equal to however many millaseconds has passed since your program started when you hit this particular line of code.}
You
can use SDL_GetTicks to time things, and create timers, but not how you have it in your code snippet.
This tutorial explains it fairly well.
A SDL_Surface is a image only, not a object that has collision detection or anything like that built into it.
When you create your SDL_Surface by loading a image, SDL gives you a image only. It doesn't manage the image for you like a game engine might, you have to do it yourself(which is good).
When you delete your SDL_Surface with SDL_FreeSurface, the image ceases to exist, and your call SDL_SetAlpha is called on a image that no longer exists.
What could be done is you'd load your image at the beggining of your game, and free it at the end. Then you'd keep a bool also, and when you set it to 'true' it draws the image, and when you set it to false, it doesn't draw it.
Also, in C/C++, you can't say:
if (reload = 300)
Because that sets 'reload' to be equal to 300. It doesn't check if reload is equal to 300. Use '==' instead of '=' when in 'if' or 'while' or 'for' statements.
if (reload == 300)
In C/C++ the '=' symbol means 'make this equal to' and the '==' symbol means 'if this is equal to'. (Basicly)
Try something like this:
//In the Player class, have a bool 'CanFire' (start it as 'true')//Have a bool named 'DrawCircle' (start it at false)//Also, have a Uint32 'FireTime' (start it as 0)void Player::shoot() //Call this when the player shoots.{ ... //<--- Whatever else you have in this function if(CanFire == true) { CanFire = false; //To stop the player from firing again, until he has reloaded. FireTime = SDL_GetTicks(); //The player fired at 'xxx' millaseconds since the program started. DrawCircle = true; //Set DrawCircle to true, so we know to draw the circle. } ...}void Player::draw() //Call this every single frame.{ //Draw the player. apply_surface(/*your x location*/, (/*your y location*/, human_ship, screen); //Draws the player on the screen. if(DrawCircle == true) { apply_surface(/*your x location*/, (/*your y location*/, circle, screen); //Draws the circle on top of the place where we draw the player. //But only if 'DrawCircle' is equal to 'true'. =) }}void Player::update() //Call this every frame also.{ if(CanFire == false) //We are currently reloading { Uint32 currentTime = SDL_GetTicks(); //Checks the current time. if(currentTime > (FireTime + 300)) //If the current time, is more than 300 millaseconds past the firing time. { CanFire = true; //We're done reloading. DrawCircle = false; //Tell ourselves to stop drawing the circle. } }}
Reading through this 'Game Loops' article might be of some help, if you used to make games with GameMaker or something simular.
In fact, the entire Lazyfoo's SDL tutorials are a very good way to learn SDL, I suggest reading through them while working on your game. [smile]
Also, Futurama rocks, if your name is a reference to the show. [grin]