![]() |
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
||||||||
|
SpaceShooter (name pending) View Screenshots The real purpose of this project was to start applying polymorphism, inheritance and encapsulation in my class structure. If done correctly, in the end I could have an engine which has functionality portable across my future games. I’ve structured my engine as such: The Unit class represents nearly all objects which are drawn to screen. These units all share many common attributes, such as their x and y positions, the width, height and directory of the image which they are drawn from, as well as common functions like draw() and kill(). Some of the Unit subclasses, for example, are the Ship, Projectile, and Item drops. Of these subclasses, though, the only one which has any further complexity is the Ship class. Since the game will allow for the player ship to be edited part by part, the Ship class itself has to be made up of separate parts. This is where the structure begins to form some kind of a containment hierarchy. What I have is a ShipPart class whose subclasses are each of the types of parts available. ![]() Originally, the Ship was one class which did not contain ShipParts and thus had full control over all its “ship functions “, such as moving, firing, etc. Now, instead, each ShipPart that a Ship contains is given control over its own function. That is to say that the main body of the ship will control movement, while the weapon will control the firing. In order to do this, I have what I call Behaviour Modules. Taking one step further into this containment hierarchy, each ShipPart will have pointers to the type of behaviour module it controls. Each Module itself has sub-modules, if you will, which specify the sub-type of that module. So, as an example, the MovementModule defines a way that the Ship will move, and the subclasses of it are Linear, Stationary, UserInput, etc. Each ShipPart will then be constructed with the appropriate subtype of each Module. ![]() ![]() |
||||||||
|
|
||||||||
|
|
||||||||