Documentation ¶
Overview ¶
Package engine is the game engien: it contains the game model and game logic.
The engine's Loop() method should be launched as a goroutine, and it can be controlled with opaque commands safely from other goroutines.
Index ¶
Constants ¶
const ( // BlockEmpty is the empty, free-to-walk block BlockEmpty = iota // BlockWall designates an unpassable wall. BlockWall // BlockCount is not a valid block: just to tell how many blocks there are BlockCount )
const ( // DirRight . DirRight = iota // DirLeft . DirLeft // DirUp . DirUp // DirDown . DirDown // DirCount is not a valid direction: just to tell how many directions there are DirCount )
const (
// BlockSize is the size of the labyrinth unit in pixels.
BlockSize = 40
)
Variables ¶
var Difficulties = []*Difficulty{ &Difficulty{Name: "Baby", bulldogDensity: 0}, &Difficulty{Name: "Easy", bulldogDensity: 5}, &Difficulty{Name: "Normal", bulldogDensity: 10, Default: true}, &Difficulty{Name: "Hard", bulldogDensity: 20}, &Difficulty{Name: "Brutal", bulldogDensity: 40}, }
Difficulties is a slice of all, ordered difficulties.
var DifficultyDefaultIdx int
DifficultyDefaultIdx is the index of the default difficulty in Difficulties.
var LabSizeDefaultIdx int
LabSizeDefaultIdx is the index of the default lab size in LabSizes.
var LabSizes = []*LabSize{ &LabSize{Name: "XS", rows: 9, cols: 9}, &LabSize{Name: "S", rows: 15, cols: 15}, &LabSize{Name: "M", rows: 33, cols: 33, Default: true}, &LabSize{Name: "L", rows: 51, cols: 51}, &LabSize{Name: "XL", rows: 99, cols: 99}, }
LabSizes is a slice of all, ordered lab sizes.
var SpeedDefaultIdx int
SpeedDefaultIdx is the index of the default speed in Speeds.
var Speeds = []*Speed{ &Speed{Name: "Slow", loopDelay: 67 * time.Millisecond}, &Speed{Name: "Normal", loopDelay: 50 * time.Millisecond, Default: true}, &Speed{Name: "Fast", loopDelay: 37 * time.Millisecond}, }
Speeds is a slice of all, ordered speeds.
Functions ¶
This section is empty.
Types ¶
type Click ¶
type Click struct {
X, Y int // Click coordinates in the lab
Left bool // Tells if left button was pressed
Right bool // Tells if right button was pressed
}
Click describes a click event.
type Difficulty ¶
Difficulty of the game.
func (*Difficulty) String ¶
func (d *Difficulty) String() string
type Engine ¶
type Engine struct { Model *Model // contains filtered or unexported fields }
Engine calculates and controls the game.
func NewEngine ¶
func NewEngine(invalidate func()) *Engine
NewEngine returns a new Engine. invalidate is a func which will be called by the engine to request a new view frame.
func (*Engine) Loop ¶
func (e *Engine) Loop()
Loop starts calculating the game. This function returns only if the user closes the app.
func (*Engine) NewGame ¶
func (e *Engine) NewGame(cfg GameConfig)
NewGame enqueues a new game command with the given config.
type GameConfig ¶
type GameConfig struct { Difficulty *Difficulty LabSize *LabSize Speed *Speed }
GameConfig holds config to start a new game.
type Model ¶
type Model struct { // Mutex to protect the model from concurrent access. sync.RWMutex // Game counter. Must be increased by one when a new game is initialized. // Can be used to invalidate caches when its value changes. Counter int // Size of the labyrinth in blocks. Rows, Cols int // Blocks of the lab. First indexed by row, then by column. Lab [][]Block // ExitPos: the position Gopher has to reach to win the game. ExitPos image.Point // Our well-beloved hero Gopher Gopher *MovingObj // The ancient enemies of Gopher: the bloodthirsty Bulldogs. Bulldogs []*MovingObj // Dead tells if Gopher is dead. Dead bool // Won tells if we won Won bool // For Gopher we maintain multiple target positions which specify a path on which Gopher will move along TargetPoss []image.Point }
Model is the model of the game.