Template Linked List Class
A linked list is a type of memory construct that holds a variable amount of data. The major advantage of a linked list is that any amount of data can be pushed into the collection and taken out of the collection. In a linked list, each piece of data is represented by a node. The node contains the data for that part of the list as well as a pointer to the next piece of data. A program can traverse the entire list by getting the pointer to the next data from each node until a particular piece of data is found or the end of the list is reached.
I chose to use a linked list for Penguin because I knew that a user should be able to create as many particles on screen as he/she wants to. If I used a basic array, only so many particles could be on the screen; as many as I programmed into the array. I'm also really anal and like to take care of all the data management myself, so I chose to write my own linked list class rather than use a stack or queue that was already premade.
Programming linked lists for every kind of data is extremely tedious. To prevent time wasted on programming these data structures, I decided that my time would be better spent on programming a general linked list that could be used to store any kind of data. I used a C++ template class.
Each particle in the engine is defined by these properties:
- x, y : the position on screen
- xvel, yvel : the velocity vector componenets of the particle's motion
- xaccel, yaccel : the acceleration vector componenets
- bouncing : if set to true, the particle rebounds off of the edges of the screen
- life : a "timer" for how long the particle stays on screen before disappearing
- fade_rate : the "timer step"; how fast the timer runs down
The particles need to track themselves on screen, so I gave the class an Update() function that I can call for each particle every loop of the main game logic. The particles move themselves, fade themselves, and mark themselves for deletion when they are dead. The linked list can then make sure to release the memory held by the particle.
The main power behind a particle engine is not in creating individual particles but in being able to set up an obect that spits out particles automatically. This is what I call a generator. A generator holds many of the same properties as a particle, but it has a range of values for many of the properties instead. This allows the particles to have a certain sense of random-ness, and therefore they appear to flow more naturally from the generator.
The explosion is a subclass of generator. It has all the same properties as the generator, but it has a different emission algorithm than a standard generator. Instead of creating particles indefinitely, it creates a certain number of particles all at once and then terminates. This creates a somewhat explosive effect almost like a firework.
I didn't want to just create a very specific particle engine; I wanted to design something that other people would be able to use in their own games. The intention is to do all the work of creating particle effects so other game designers don't have to worry about it themselves, but also allow room for alteration so they can expand the engine to use the particles in any way they want. In order to demonstrate with code how to implement the engine into a program, I'm writing a program that uses the engine and has a simple user interface that shows off Penguin. This will be used in conjunction with the documentation that comes with Penguin to explain fully how to utilize the engine and expand it as needed.
Once I have the basic engine and environment done, I would like to improve it further (time allowing) by creating a 16bit color version as well as allowing the particles to be drawn with images instead of colored pixels.
Another key part of the project is the informational document that comes with Penguin. The documentation is going to have three major sections: a description of the algorithm and logic behind the engine, an explanation of the example environment and how to use it, and instructions on how to implement Penguin into another program as well as how to expand it with new types of emitters.