Documentation ¶
Overview ¶
Package demo contains support for playing scripted demos.
There is an entity Demo which can be added to the screen and it will play demo Script. Demo Script consist of ordered commands. Each command can perform some in game action.
There is support for parsing demo script from string representation. Script string should contain one command per line. It can contain empty lines and commented lines starting with `#`. Alternatively there can be multiple commands per line separated by `;` (semicolon).
Supported commands:
- `wait s` - will wait for `s` seconds
- `hideMessageBox` - hides any visible message box
- `setAngle a` - continuosly change cannon angle to `a` for active player
- `shoot p` - load power to `p` and shoot with active player
- `waitForFinishTurn` - will wait for all explosions and bullets are gone and turn is shifted to next player
- `nextRound` - switches game to the next round
- `moveFocus` - move focus to next ui component
- `pressButton` - send action event to ui component with focus
- `exit` - exits game
Index ¶
- type Command
- type Demo
- type Exit
- type GameContext
- type HideMessageBox
- type Memory
- func (m *Memory) AddFloat(id string, add float64) float64
- func (m *Memory) Clear(id string)
- func (m *Memory) ClearAll()
- func (m *Memory) Read(id string) interface{}
- func (m *Memory) ReadFloat(id string) float64
- func (m *Memory) UpdateFloat(id string, f func(f float64) float64) float64
- func (m *Memory) Write(id string, v interface{})
- func (m *Memory) WriteFloat(id string, f float64)
- type MoveFocus
- type NextRound
- type Parser
- type PressButton
- type Script
- type SetAngle
- type Shoot
- type Wait
- type WaitForFinishTurn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command interface {
Eval(c *GameContext) bool
}
Command represents some activity which can be done during game play. Each command can be executed multiple times. How many times will be command executed depends on its return value. If command returns true it is considered as finished. Otherwise it will be called again.
type Demo ¶
type Demo struct {
// contains filtered or unexported fields
}
Demo is entity which when added to the game will play given Script. Use NewDemo to create new demo with some script. Use LoadFromFile to create new demo with script loaded from file.
func LoadFromFile ¶
LoadFromFile loads demo from file with demo script commands
type GameContext ¶
type GameContext struct { // Controls refers to the game controls which can be used to do some action Controls *gorched.Controls // Round refers to current game round which can be used to getting the state information Round *gorched.Round // Dt is delta time between two executions (game screen redraws) Dt float64 // Memory is local memory which "lives" during execution of single command Memory *Memory }
GameContext holds access to the game controls and state.
type HideMessageBox ¶
type HideMessageBox struct{}
HideMessageBox will hide any messagebox if visible
func (*HideMessageBox) Eval ¶
func (t *HideMessageBox) Eval(c *GameContext) bool
Eval evaluates command
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is simple memory which can be used by commands to store some values under string identifiers
func (*Memory) AddFloat ¶
AddFloat adds given add float to the float value stored in memory on given id.
func (*Memory) ReadFloat ¶
ReadFloat reads float64 value stored on given id from memory. If there is no float64 value stored on id 0 is returned.
func (*Memory) UpdateFloat ¶
UpdateFloat reads value from memory stored on given id, applies function f to this value and writes result back on id. Result of function apply is returned too.
func (*Memory) WriteFloat ¶
WriteFloat stores float64 value to memory on given id. If there was already some value stored on id it will be overwritten.
type PressButton ¶
type PressButton struct{}
PressButton sends action event to currently focused ui component
type SetAngle ¶
type SetAngle struct {
Angle int
}
SetAngle will change tank's angle to specified Angle. Changing is not done immediately but it tries to simulate continuos change like when done via kayboard.
type Shoot ¶
type Shoot struct {
Power int
}
Shoot will make tank to load and shoot with given Power
type Wait ¶
type Wait struct {
Seconds float64
}
Wait will wait for given Seconds to be finished. It is not blocking all other entities during wait only next commands.
type WaitForFinishTurn ¶
type WaitForFinishTurn struct{}
WaitForFinishTurn will wait until there are no bullets and explisions in the game world. Use it after Shoot if you want to invoke next actions for next player. It is not blocking all other entities during wait only next commands.
func (*WaitForFinishTurn) Eval ¶
func (w *WaitForFinishTurn) Eval(c *GameContext) bool
Eval evaluates command