Assignment 09: Game! First Pass!
Time Spent: 8 hrsGit Tag: Assignment_08
Download Executable Archive here
Controls:
Sphere Movement:
- Up Arrow: Fwd
- Down Arrow: Back
- Left Arrow: Left
- Right Arrow: Right
- Shift: Down
- Enter: Up
- Space: FIRE!
- W: Fwd
- A: Left
- S: Back
- D: Right
- Q: Down
- E: Up
Start making a game of my own! The goal here is to step out on my own and start adding projects and files to the solution without the instructors direction in a way that make cogent sense given the project and engine structure we are trying to achieve.
How I completed it:
For this assignment I built up a very simple shooting gallery type game. The player attempts to align a projectile with a moving target using the arrow keys, then fires by pressing the space bar. The projectile flies forward at a fixed velocity and resets after traveling a certain distance.
To make all this happen, I began by adding several new projects to the solution. I added a messaging system for delivering messages between objects throughout the game, a HashedString class for supporting the messaging system in an efficient manner, and a new class I'm calling an ObjectScript that can be given a pointer to any gameobject and allowed to control it at run time (though I'm thinking of changing the name to be simply "Controller"... we'll see...).
The ObjectScript class is connected to the MessagingSystem via an ObjectMessageHandler, a class derived from a basic MessageHandler. These ObjectMessageHandlers can be passed member-function-pointers on instantiation which they will use as call-backs when they receive a message from the messaging system. To start with, the base ObjectScript class has a built in "Update" message handler that is called once per frame when the engine sends an "Update" message. This allows me to define scripts like "TargetMotion" and "ProjectileMotion" and attach them to their respective GameObjects at instantiation, resulting in lovely behaviors without any additional update calls from the game to the objects.
Additional ObjectMessageHandlers are easily added to classes derived from ObjectScript, and are simply given string messages such as "FIRE" and member-function-pointers to appropriate handler functions within the ObjectScript derived class. This is how I made the projectile responsive to a space-bar press: space bar calls MessagingSystem::SendMessage("FIRE") which results in the calling of ProjectileMotion::OnFire, changing the state of the projectile to "launched" which then results in forward motion on each Update call.
Where to next?
My eventual goal for this game is to add controls which allow the player to aim a vector pointing out of the projectile up, down, left, or right, and then add some UI elements such that the player can set the "launch strength" by holding the spacebar for varying lengths of time, launching upon release. I also want to add basic ballistic physics to the game, collision detection for determining whether the projectile hits targets and bouncing off of them when it does, and a scoring system for aggregating points. Then I will add obstacle objects the player will have to avoid hitting while shooting for the highest value targets they can see.
Right now, the ObjectScripts I use are instantiated and destroyed directly by the MyGame class, which is undesirable. In the future I will add an ObjectScriptFactory type object for lifecycle management that pulls the ObjectScript declarations out of MyGame.h & MyGame.cpp and cleans them up as appropriate.
No comments:
Post a Comment