Documentation
¶
Overview ¶
Package model defines the basic types and data structures of the game. This can be thought of as the Model part of an MVC architecture.
It is "shared", used by the view and ctrl packages.
Index ¶
Constants ¶
const (
// BlockSize is the size of the labyrinth unit in pixels.
BlockSize = 40
)
const MouseBtnRight = 2
Constant for the right Mouse button value in the Click struct. Button value for left and middle may not be the same for older browsers, but right button always has this value.
Variables ¶
var ( // Rows is the number of rows in the Labyrinth Rows int // Cols is the number of columns in the Labyrinth Cols int // LabWidth is the width of the labyrinth's image in pixels. LabWidth int // LabHeight is the height of the labyrinth's image in pixels. LabHeight int )
var BulldogDensity float64
"Bulldog density", it tells how many Bulldogs to generate for average of 1,000 blocks. For example if this is 10.0 and rows*cols = 21*21 = 441, 10.0*441/1000 = 4.41 => 4 Bulldogs will be generated.
Bulldog images for each direction, each has zero Min point
var Bulldogs []*MovingObj
Slice of Bulldogs, the ancient enemy of Gophers.
var ClickCh = make(chan Click, 10)
Channel to receive mouse clicks on (view package sends, ctrl package (engine) processes them)
var Dead bool
Dead tells if Gopher died
var DeadImg *image.RGBA
Dead Gopher image.
var EmptyImg = image.NewUniform(color.RGBA{A: 0xff})
Image of the empty block
var ExitImg *image.RGBA
Image of a door, this is the exit sign
var ExitPos = image.Point{}
Exit position
var Gopher = new(MovingObj)
Gopher is our hero, the moving object the user can control.
Gopher images for each direction, each has zero Min point
var Lab [][]Block
The model/data of the labyrinth
var LabImg *image.RGBA
Image of the labyrinth
var Mutex sync.Mutex
Mutex to be used to synchronize model modifications
var NewGameCh = make(chan int, 1)
Channel to signal new game
var TargetImg *image.RGBA
Image of the empty block
var TargetPoss = make([]image.Point, 0, 20)
For Gopher we maintain multiple target positions which define a path on which Gopher will move along
var V float64
V is the moving speed of Gopher and the Buddlogs in pixel/sec.
var WallImg *image.RGBA
Image of the wall block var WallImg = image.NewUniform(WallCol)
var Won bool
Tells if we won
var WonImg *image.RGBA
Image of a congratulation
Functions ¶
Types ¶
type Click ¶
type Click struct {
// X, Y are the mouse coordinates in pixel, in the coordinate system of the Labyrinth
X, Y int
// Btn is the mouse button
Btn int
}
Click describes a mouse click.
type Dir ¶
type Dir int
type MovingObj ¶
type MovingObj struct { // The position in the labyrinth in pixel coordinates Pos struct { X, Y float64 } // Direction where the object is facing toward Direction Dir // Target position the object is moving to TargetPos image.Point // Images for each direction, each has zero Min point Imgs []*image.RGBA }
MovingObj is a struct describing a moving object.
func (*MovingObj) DrawImg ¶
func (m *MovingObj) DrawImg()
DrawImg draws the image of the MovingObj to the LabImg.
func (*MovingObj) DrawWithImg ¶
DrawWithImage draws the specified image at the position of the moving object onto the LabImg.