-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Guide
- Core GAME1 JS files
- Main HTML File Including these files
- Game JS File
- Game statedefinitions.js file
In most cases you also want you game resources to be included. The directory structure is not fixed, but strongly recommended is to follow the example standard.
The following example shows how this can be done, from the main index.html file.
<script src="../../../core/boot.js"></script>
<script src="../../../core/blockfont.js"></script>
<script src="../../../core/spritemover.js"></script>
Only boot.js is mandatory.
- blockfont.js is used to write color-full text on the screen
- spritemover.js is an implementation of software sprites
In this case the core files, are located under ../../../core You may put them in any place you like.
This file handles the moving between different states in the game. For example the title sequence is a different state then the ingame action.
Below is an example:
class StateDefinitions {
constructor ( demo ) {
this.startPlaybook = "demo";
/* -----------------------------------------------------
Playbooks
----------------------------------------------------- */
this.playbooks = {
demo: { object: demo, enter: 'load', definition: this },
};
/* -----------------------------------------------------
Global state setup
----------------------------------------------------- */
this.stateTypes = {
LOADSILENT: ['LOAD'],
PLAY: ['INIT','CLEANUP','RENDER','PROCESS','HANDLEINPUT'],
WATCH: ['INIT','CLEANUP','RENDER','PROCESS'],
INIT: ['INIT'],
BRANCH: ['BRANCH']
};
this.stateMethodSuffix = {
LSRENDER: undefined,
LSPROCESS: undefined,
RENDER: 'Render',
PROCESS: 'Run',
HANDLEINPUT: 'Handle'
};
/* -----------------------------------------------------
Demo playbook
----------------------------------------------------- */
/* no branch functions */
/* demo playbook */
var demoPlaybook = this.playbooks.demo;
demoPlaybook.states = {
/* Only load, play and repeat since this is a demo, not a game */
'load': { _type: "LOADSILENT", next: 'play'},
'play': { _type: "PLAY", next: 'play' },
} ;
}
}
A State is a like a single Moment in the game. A Playbook is a collection of such moments. For example:
A Playbook called "title" could contain:
- State title.load
- State title.play
A Playbook called "game" could contain:
- State: game.load
- State: game.playing
- State: game.bonuslevel
There are different types of states. But in general states have method groups. A method group, is a number of methods in JS that are executing code for that state.
This is defined in the following way.
First let's look again at the example definition file, this section below:
demoPlaybook.states = {
/* Only load, play and repeat since this is a demo, not a game */
'load': { _type: "LOADSILENT", next: 'play'},
'play': { _type: "PLAY", next: 'play' },
} ;
Here you see that there is two states (for one playbook only).
Each state, has a type. The definition of the type is done a bit earlier like this.
this.stateTypes = {
LOADSILENT: ['LOAD'],
PLAY: ['INIT','CLEANUP','RENDER','PROCESS','HANDLEINPUT'],
WATCH: ['INIT','CLEANUP','RENDER','PROCESS'],
INIT: ['INIT'],
BRANCH: ['BRANCH']
};
this.stateMethodSuffix = {
LSRENDER: undefined,
LSPROCESS: undefined,
RENDER: 'Render',
PROCESS: 'Run',
HANDLEINPUT: 'Handle'
};
Each type has a few (pre defined) types. For example, the PLAY state has 5 types. This means it has a method for each of these 5 types.
Each type has 1 or more methods attached to it. Simple states just one. The stateMethodSuffix record overrides standard suffixes.
The name of the method is <statename_lc>
So we have the following methods for example:
playRender playRun playHandle etc...