Archived

This topic is now archived and is closed to further replies.

SDL Space Invaders - storing shots

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I have now successfully completed some basic Pong and Tetris clones. I have now moved onto Space Invaders. I have the sprites sorted (so the enemies animate as they move) but I have a question. How should I represent / store shots, fired by the player. At the moment I have a CGame class, holding an array of CEnemys and other members, with core methods for drawing and updating the game. And I have a CPlayer class. I could have an array of structs in the CGame class. But this would be static and I could either be using all teh array or sometimes none of it. Dynamically allocating memory for each shot? How should I go about this. Is the struct a good idea? store the x/y screen coordinate of the shot and then have a CGame method for looping through each enemy and checking its bounding box? As a side question: after this I guess I''m moving onto Breakout, 2d (eventually scrolling) space ship shooter kinda game, and also a platformer similar to old mario (in a few months). Could I continue to do this with SDL? I''ve learnt a tiny bit of OpenGL (first 6 nehe tutorials) but have been relatively comfortable with SDL, so should I just stick with SDL for the rest of my 2d games. Afterall, its mainly just the logic, and experience of how I would be making games.

Share this post


Link to post
Share on other sites
quote:
Dynamically allocating memory for each shot? How should I go about this.


Check out the Standard Template Library and specifically the list class. The linked list automatically allocates and deallocates objects that are created/destroyed. Plus using a linked list you get a constant time insertion/deletion.

Share this post


Link to post
Share on other sites