4D-Game SDK
The 4D-Game SDK allows you to create a physical Game which can be controlled with a Gamepad over a Raspberry Pi. To create a game, every Player (Gamepad) gets it's own Raspberry Pi (Controller). The control of the Game is done by one Raspberry Pi called the Gamecontrol.
Gameloop
The course of every game can be described by a state machine called the gameloop. It is consisting of the idle-, start-, run- and _end-_States which are controlled by the Gamecontrol.
States
Idle
The gameloop starts in the idle-State, waiting until every controller send a ready message. When this happens the state is changed to start.
Start
The start state is used to initialize different devices needed for the game and get everything into starting position. The state is changed to run when every controller sent a ready message.
Run
This is the state where the actual game is played. Player can gain or loose points or a timer is running to end the game after a certain time. When the condition for the end of a game/round is met, the state is changed to end.
End
In this state devices needed for the game can be deinitialized so they are not running in idle state. When every controller is ready, the gamecontrol switches back to idle.
Communication
All communication between different Devices is done with MQTT. The following structure is used:
Note
The setup of a MQTT Broker is needed to use the SDK
MQTT Structure
Class Structure
The 4D-Game SDK is based on the classes shown below. The structure is extended by the classes specifically used for controller, gamecontrol or passive devices. Those classes are explained in the coresponding section.
GameTemplate
The GameTemplate
class is the base for the different Game
classes for controller, gamecontrol and passive elements.
GameIO
The GameIO
gives access to the gameloop and communication between devices. It is instanciated in the Game
class and can be used with self.game_io
.
Players
The Players
class is used by the gamecontrol and passive devices. It provides an easy interface to save the score and the ready flag of all connected controllers.
Create a game
A simple game consists at least of:
- 1x Controller
- 1x Gamecontrol
The number of Controller can be increased up to 8.1
You can also have an element in your game that get's all information but doesn't interact with the game loop (e.g. A display to show the score of a player). For this the passive sdk can be used. The number of passive devices is not restricted.2
To learn how to get started with the different parts of the sdk see the following sections: