Tuesday, July 26, 2011

Sensible Structure

Having finished the the basics of the player, I decided to start a new project and start using classes. Since the player ship wasn't going to be the only type of ship in the game, it made sense to create a 'Ship' super class with some basic properties common to enemies and the player. This was a fairly simple class that contained fields like texture, position, velocity and anything else common to all ships. I just had to copy in the player properties and functions from the previous project into the 'PlayerShip' class, so it was finished with for the time being. Next I decided to start on the enemy ship class. Again, I got the sprites from the same website!


The 'EnemyShip' class was designed to look after the rotation of the enemy in relation to the player and its position. I didn't want to make this class too specific as there will be many different types, each with their own properties and functions. So the 'EnemyShip' class will be sub-classes later on. So after finishing theses two classes and adding a bit of code to the main game class, I had a limited number of enemies spawning and following the player wherever he went!

No comments:

Post a Comment