Sunday, February 21, 2010

Command Utility for Rusher Game Framework

I've added a Command Utility to Rusher Game Framework. Each engine core now has a reference to a CommandManager object; this object allows you to execute commands, be it single commands or composite commands.

There are two types of composite commands: ParallelCommand and SerialCommand. The parallel command executes all its subcommands simultaneously, while the serial command executes its subcommands sequentially. Also, each command has a delay property (the time a command "waits" before execution), which you may make use of to have advanced control over the command execution timing.

Here are some code snippets for Rusher's Command Utility.

This TraceCommand class is a very simple command consisted of a delay time and a trace message. Note that the execute() method is where all your command goes, and the complete() method should be called when the command is finished.

Here's the document class. The two commands "ps" and "sp" are a parallel command with a serial subcommand and a serial command with a parallel subcommand, respectively. The first constructor parameter of the parallel and serial commands is the delay time, and the subsequent parameters are subcommands.

This shall trace out "ps0", "ps1", "ps2", "ps3", "sp0", "sp1", "sp2", and "sp3" sequentially with a time gap of one second. The complete source code for this example can be found here.

One engine core is supposed to be used for one game level, or one scene in a game. I'm aiming for creating a utility for handling the entire game, including opening, menu screen, main game, ending, credits, etc. The Command Utility is just one part of it. You can think of it as something similar to Progression Framework.

No comments: