• Advertisement
Sign in to follow this  

RType style game

This topic is 4404 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

Im attempting to code a 2D style RType game in C++. This is my first real venture into programming a full game. I am trying to design a class structure in UML using Visio, but am unsure as to how this would look. I would appreciate a class diagram from someone who has completed a similar project, also any advice would be appreciated. I am sure i could probubaly code this game in a messy way, but i wanted to focus my efforts on creating an elegant structred object oriented framework. Thanks, Steve

Share this post


Link to post
Share on other sites
Advertisement
My advice is to Do The Simplest Thing That Works. Don't over-abstract, don't over-engineer, don't write something only because it might be useful later on.

Now, on to the actual 'personal experience' part you were asking for. I have no class diagram ready, but I can describe the overall ideas.

My project is a series of layers.

  • The bottom layer is what I would call the 'core engine'. It provides a Timer and EventScheduler that measure time and allow the other layers to schedule things at given times. It also provides a World : a set of all Avatar objects that can be drawn (video) or played (audio) on a given Trajectory, which describes position as a function of time. It provides a function to load Image or Animation video and Sound audio resources, and to create avatars from a trajectory and an image. It finally provides Input data (key and mouse status).


  • The next layer is the 'game engine', in that it provides basic facilities useful for a video game. All are presented as independent one-file modules without cyclical dependencies. This includes, for collision detection, CollisionGroup (a group of objects which share who they can collide with: this object would be used to represent 'player bullets', 'enemy bullets', 'player', 'pickups'), Hull (the shape of an object, used for collision detection) and CollisionDetector (used to detect collisions between two groups; calls a predefined callback function whenever a collision occurs, with the objects as arguments). It describes special trajectory types, such as WavePath to describe the movement of enemies, HomingTrajectory for homing missiles or ControlledTrajectory for binding a trajectory to a set of keys. It also implements the standard 'game' procedure, which involves a StateStack for going from menu to game to pause menu.


  • The layer above comprises 'game logic'.
    • It provides PlayerStatus, which details the player score, health and firepower, and the graphical/auditive incarnation of this status through HeadsUpDisplay.

    • As part of level loading, it provides EnemyTemplate, GunTemplate and BulletTemplate classes which serve as blueprints (or, if you prefer, factories) that are easy to save and load. Equally easy to serialize is the EnemyWave class which describes a set of enemy templates to be used to launch, at given times, enemies along given trajectories.

    • Templates create simultaneously a visual Avatar and an Enemy or Bullet object to control that avatar's position. Special enemies might even be given a HealthBar, such as bosses. Each Enemy is given one or more Gun objects, which incorporate a BulletTemplate along with rate-of-fire and aiming properties they need to actually shoot bullets. Finally, both enemies and bullets are associated (by their templates) with a hull and placed in the appropriate CollisionGroup, with callbacks that will make them react by making the target lose health (for bullets) or lose health because of collisions (for enemies).

    • The death of an Enemy or Bullet triggers the death of the associated avatar. A ScoreReward object is associated to an Enemy every time a player bullet hits it (and can be merged with each other). When the enemy dies, score is added to the PlayerStatus object that corresponds to the ScoreReward Finally, this layer provides with the easy means to create, fill, save and load Level objects with the appropriate templates and enemy waves, as well as some additional information on level backgrounds and music.

    • All of this is kept independent by providing all the necessary data through the constructors: level creation requires references to the correct CollisionGroup objects for each category, which it then passes on to all templates, as well as the PlayerStatus information (position, invulnerability) which is then passed on to all guns and enemies.




  • The 'game world' layer provides a simple Game object that is pushed onto the state stack. This object has a player (Status, HUD and avatar), a current Level (and a list of filenames corresponding to the various levels), and the collision detection groups required. It also has a Timer and EventScheduler. It allows such simple things as saving or loading the game when commanded to do so by a menu, starting a new game with a specified player and using a specific level list, or shutting down an entire game and returning to the main menu.
    Finally, the Game world can be registered to perform certain actions when certain events happen: end of level, loss of last life, end of game, pause button pressed.


  • The 'interface' layer uses the high configurability of the Game object to register
    When a pause button is hit, it creates a PauseMenuState which may manipulate it. When a level is over, it creates LevelEndState or a GameEndState which sums up the player's results for that level or game. Finally, a GameOverState is created when the player loses his last life. The two last states can in turn create a HighScoreState by checking the player state against the saved high scores. Finally, a MainMenuState is able to respond to player input by creating a new game with a selected player ship (or continuing a saved one), by displaying high scores, by configuring input, or by quitting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement