Design Thought
I'm taking design a step further and implementing a Chain of Command pattern on top of this pluggability. There are discrete steps in these sorts of games, and all of them operate directly on the units in the playing field -- essentially a Blackboard model, except in order to prevent chaos I'll sequence the blackboard elements into a Chain of Command. So the game loop is managed by GameStep objects, which operate independently of each other:
- Gravity Model
- Input Model
- Position Tracker
- Impact Model
The interface may simply be:
public function accept(state:GameState):void {...}
public function name():String {...} // for game settings chooser...
The control loop therefore becomes very lightweight.
I could implement these as Template Methods, but I like the "pluggable" modularity of Chain of Command. It's one of the side-effects of Object-Oriented programming that I enjoy (OO tends to still be a bit overrated at times).
It's also easily extensible: if my game becomes cool and I want to play my friend Dan Terrill over the internet, I can later code up a NetworkInputModel that lets us play. If I want to create a Lunar Lander variant, I code up a SurfaceGravityModel that exerts a "downward" pull on all objects in the game, and a variant ImpactModel that detects a safe vs. unsafe landing. Plus it could retain the combat elements... combat lunar lander... cool.
Implementation Thought
One of the few things I know about Flex is that the Canvas (and Panel) objects are positionable graphics objects which "own" things which are displayed. That's all fine and well, but I found a side effect that I hope I can exploit: point rotations of objects on a Canvas are rotated relative to the origin of the Canvas.
Here's why that's important: If I create a separate Canvas for each object in play, centered on its origin, then I can move and rotate the Canvas very easily.
Normally, when you rotate an object, you translate its points relative to the origin, then apply the transformation (rotation), then re-translate back to their actual position, then move the object to that new position. It's lots of work, and also a solved problem... for decades. If I can simply set the rotation angle of an owning Canvas, however, all that work is done for me. Simpler application code. Less boring work. Win-win.
your friend Dan Terrill is too busy taking vitamin C to combat migraines to play networked Spacewars
ReplyDelete