Tuto Gideros Game Template1 Part 7 Game
The Game Scene
This is going to be the last scene for our Gideros Game Template1 tutorial.
This is going to be a quick and simple one because you may decide to organize your game differently.
Usually, when I make games, prototypes, I put all my levels in one scene. When I change level I reload the game scene with a variable indicating the current level, eg.: currlevel = 1, 2, ...
For the reason cited above and for how long I have been using this kind of architecture, I decided to call the game Class: LevelX (please feel free to change it).
Our Game scene (LevelX) will mainly consist of:
- moving the mouse cursor out of the way :-)
- dividing our scene into layers (Sprite): background layer, fx layer, actors layer, foreground layer, ...
- the game loop
The Options scene code
It makes sense to create the file in the scenes folder. You can call the file "options.lua". Here is the code:
Code comments
Sometimes a key doesn't have a KeyCode visual, eg.: the arrow keys. The local keyNames variable will translate the KeyCode of a key to a more user friendly name.
init
In the init function we add:
- a title for the scene
- the sliders to set the game sound volume and difficulty
- the keys to control the player which can be remapped
We listen for any key that can be remapped and activate the remap key system when "clicked".
The keys are added to the btns table which serves the keyboard navigation system.
We add the sliders listeners and will save any modified value to the user preference file.
The mouse listener will cancel any key remapping when clicked outside of a remappable key.
Finally we update our buttons visuals and we are ready to process any change to a slider value or a key remapping event.
key remapping
When we click on a remappable key (most of the buttons in this scene), the new value (KeyCode) will be assigned to that key. A friendly name will be displayed to show the change.
When the remapping is validated we save it to the user preference file.
buttons actions
The buttons will trigger different actions according to the button id. If it is a remappable key we activate the remap system, if it is the MENU button we go back to the Menu scene.
Next?
We hopefully have a good base for an Options scene. The final scene for this tutorial will be the Game scene.
Prev.: Tuto Gideros Game Template1 Part 6 Options
END
Tutorial - Gideros Game Template1