Porting a single player game
From Whirled
Contents |
Setting Up
To begin with, set up your development environment. We recommend you also build and test the Hello Whirled program if possible. Set up a new Game folder with the build files per those instructions.
Adding imports
We assume your game already comes with one or more ActionScript classes. Add these to your new game folder, making sure that none of them have exactly the same name as the files in the new game folder. Add the following imports to your ActionScript classes.
import com.whirled.game.CoinsAwardedEvent; import com.whirled.game.GameControl; import com.whirled.game.StateChangedEvent; import com.whirled.game.MessageReceivedEvent;
Removing Calls to Stage
Whirled games do not use the stage. If you have calls in your code that refer to the stage, please remove them. You can add your eventListeners onto the GameControl class
//create a main instance of the gameController class
_control = new GameControl(this, false);
.....
// register for GameControl events on the various subcontrols
_control.game.addEventListener(StateChangedEvent.GAME_STARTED, gameDidStart);
_control.net.addEventListener(MessageReceivedEvent.MESSAGE_RECEIVED, messageReceived);
_control.player.addEventListener(CoinsAwardedEvent.COINS_AWARDED, coinsAwarded);
_control.local.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
// tell the server you are ready to start playing - this triggers gameDidStart()
_control.game.playerReady();
}
If you want your game to work both in and out of whirled, and you are using the stage. You can do some conditional switching.
//create a main instance of the gameController class
_control = new GameControl(this, false);
var boolean isConnectedToWhirled = _control.isConnected();
.....
// register for GameControl events on the various subcontrols
if (_isConnectedToWhirled) {
_control.game.addEventListener(StateChangedEvent.GAME_STARTED, gameDidStart);
_control.net.addEventListener(MessageReceivedEvent.MESSAGE_RECEIVED, messageReceived);
_control.player.addEventListener(CoinsAwardedEvent.COINS_AWARDED, coinsAwarded);
_control.local.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
} else {
//register your events outside of whirled.
}
// tell the server you are ready to start playing - this triggers gameDidStart()
if (_isConnectedToWhirled) {
_control.game.playerReady();
}
Move Keyboard Events
Due to our security model, Keyboard Events should be registered on the localSubControl Object. All other events can be handled as usual.
_control.local.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
......
_control.local.removeEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown);
Rematch button control
For single player/multilevel games, you might find it easier to control the rematch from inside your game. You can turn off the the Rematch button using setShowButtons()
Persist Private Data
You can follow the instructions here to store player data.
Add Coin Payouts
You can follow the instructions here to add payouts to your game.
Add Trophies
You can follow the instructions here to add trophies to your game.
Add Return To Whirled
When a user finishes playing one level, or one round, it's usually nice to offer them an option to either replay or a chance to return to Whirled. You can return the user to Whirled using the backToWhirled() call on the localSubControl.
Upload and Test
You can build and test your new game using the ant build files in your new Games folder. If your game works for one round offline, then upload it. The usual settings for a single player game is Pre-matched Table with both minimum and maximum of 1 player, and Watchable? unchecked.

