Phoenix

Level Design

For level design was an important part of the game in that the levels and possible bosses need to continually get more difficult. In the past I have used a file to determine a finite number of levels. But let’s be honest here, what fun is that really? Ignoring the fact that it is tedious to hard code values like that, having a finite amount of levels really takes the ‘arcade’ feel out of the game. Thus I went with an algorithmic approach. Every 3 levels is a boss level, there are multiple ship types and health limits, as well as slightly different behaviors.

Problem: Resource Class

I came to a problem pretty quickly with resource management.  In the Phoenix source there is a bullet class.  Each time a ship (Player or Enemy) fires a bullet, a new bullet is created and added to the ‘global scene’.  From there its update function is called and it updates its own position etc.  It also contains a reference to an SDL_image which is actually a pointer.  There is only one of these images in memory, and it is redrawn to a specific location based on the coordinates of any given bullet.  The problem comes into play when the bullet is deleted (when it hits a ship or moves off screen).  In the destructor of a bullet, I can not just delete the pointer because at some point there has to still be a reference to the image to delete when the game end.  I also cannot delete the actual object the pointer is pointing to because that would delete the image for all of the other valid bullets that still need it.  There are two possible solutions to this problem.

The first would be a sort of ‘Image factory’.  This would hold how many references there are currently for a particular image.  When there are no more, it would safely delete the image.  Any request for an image that is already loaded in memory would only result in a reference to the existing image being returned.  This sounds really close to the functionality of a smart pointer, but the main difference is that the method above is using the factory design pattern.

The second method would be to have one large singleton class that holds a single reference to images, sound files, etc.  When objects, like bullets or even ships are created, a reference to this object is passed in their constructors and the objects get references to the resources they needs.  I will be choosing this method because I think it will be better suited for a small game like this.

Leave a Reply

Your email address will not be published. Required fields are marked *