Documentation ¶
Index ¶
- Variables
- func LoadSounds()
- func LoopSound(sound Sound) int
- func PlaySound(sound Sound)
- func StopSound(ref int)
- func ViewControls(win *pixelgl.Window, grid *Grid, done chan GoToCmd)
- func ViewGame(win *pixelgl.Window, grid *Grid, done chan GoToCmd)
- func ViewMenu(win *pixelgl.Window, grid *Grid, done chan GoToCmd)
- type Block
- type BlockState
- type FallingBlocks
- func (blocks *FallingBlocks) Add(row int, col int, value int)
- func (blocks FallingBlocks) Blocks() []Block
- func (blocks *FallingBlocks) Clear()
- func (blocks FallingBlocks) DescribeLanding(block Block, game *GameState) (LandingType, int, int)
- func (blocks FallingBlocks) Length() int
- func (blocks *FallingBlocks) Random(count int)
- func (blocks *FallingBlocks) Remove(row int, col int)
- func (blocks *FallingBlocks) ShiftLeft(game *GameState)
- func (blocks *FallingBlocks) ShiftRight(game *GameState)
- func (blocks *FallingBlocks) Slam(game *GameState)
- func (blocks *FallingBlocks) Speedup()
- func (blocks *FallingBlocks) Update(ticks float64, game *GameState)
- type GameState
- func (gs *GameState) AddBlock(block Block) error
- func (gs GameState) ColCount() int
- func (gs *GameState) IsDead(row int, col int) bool
- func (gs *GameState) IsEmpty(row int, col int) bool
- func (gs *GameState) IsOver() bool
- func (gs GameState) RowCount() int
- func (gs *GameState) ValueAt(row int, col int) int
- type GoToCmd
- type Grid
- type ImageBuffer
- type ImageRenderer
- type LandingType
- type MultiRenderer
- type Renderer
- type ScoreRenderer
- type Sound
- type TextRenderer
- type ViewFunc
Constants ¶
This section is empty.
Variables ¶
var ( ColorBg color.RGBA = colornames.Aliceblue ColorFallingBlock = colornames.Cornflowerblue ColorDeadBlock = colornames.Tomato ColorLiveBlock = colornames.Aquamarine ColorSlamTrail = colornames.Cadetblue ColorMenuOption = colornames.Crimson )
Functions ¶
func LoopSound ¶
LoopSound loops a sound.
A number that can be used to stop the sound via StopSound() is returned.
func StopSound ¶
func StopSound(ref int)
StopSound stops a looping sound.
If the given ref does not identify a looping sound, an error is logged.
func ViewControls ¶
ViewControls displays user controls.
Types ¶
type BlockState ¶
type BlockState bool
BlockState determines whether a block is dead or live.
const ( // DeadBlock describes a block that cannot be modified. DeadBlock BlockState = true // LiveBlock describes a block that can be modified. LiveBlock BlockState = false )
type FallingBlocks ¶
type FallingBlocks struct {
// contains filtered or unexported fields
}
FallingBlocks manages the cells that currently under player-control.
func NewFallingBlocks ¶
func NewFallingBlocks(ticksPerStep float64) *FallingBlocks
NewFallingBlocks returns a pointer to a new FallingBlocks.
func (*FallingBlocks) Add ¶
func (blocks *FallingBlocks) Add(row int, col int, value int)
Add adds an ActiveCell to this collection.
func (FallingBlocks) Blocks ¶
func (blocks FallingBlocks) Blocks() []Block
Blocks returns a copy of the cells in these FallingBlocks.
func (*FallingBlocks) Clear ¶
func (blocks *FallingBlocks) Clear()
Clear clears all cells from this collection.
func (FallingBlocks) DescribeLanding ¶
func (blocks FallingBlocks) DescribeLanding(block Block, game *GameState) (LandingType, int, int)
DescribeLanding returns information about a block's landing.
A block has landed iff: 1. It overlaps an inactive block. 2. It overlaps a dead block. 3. It is in the final row of the grid.
If the block has not landed, the returned landing type is Unlanded and the position values should be ignored.
func (*FallingBlocks) Random ¶
func (blocks *FallingBlocks) Random(count int)
Random generates a new set of cells in the first row.
func (*FallingBlocks) ShiftLeft ¶
func (blocks *FallingBlocks) ShiftLeft(game *GameState)
ShiftLeft shifts these FallingBlocks to the left.
A block can move to its left iff: 1. There is no dead block to its left. 2. There is no other falling block to its left. 3. It is not in the leftmost column.
func (*FallingBlocks) ShiftRight ¶
func (blocks *FallingBlocks) ShiftRight(game *GameState)
ShiftRight shifts these FallingBlocks to the right.
A block can move to its right iff: 1. There is no dead block to its right. 2. There is no other falling block to its right. 3. It is not in the rightmost column.
func (*FallingBlocks) Slam ¶
func (blocks *FallingBlocks) Slam(game *GameState)
func (*FallingBlocks) Speedup ¶
func (blocks *FallingBlocks) Speedup()
func (*FallingBlocks) Update ¶
func (blocks *FallingBlocks) Update(ticks float64, game *GameState)
Update updates this FallingBlocks given the current ticks and gameState.
type GameState ¶
type GameState struct {
// contains filtered or unexported fields
}
GameState represents the state
func NewGameState ¶
NewGameState returns a GameState with the given number of rows and columns. All blocks are initially alive and empty.
func (*GameState) AddBlock ¶
AddBlock adds the given block to this GameState.
If the block overlaps a dead block, it is added to the row above its current row. If that row is above the top of the grid, nothing is done and IsDead() will return true.
If the block overlaps a live block, its value is added to the live block's value. If the new value is outside the allowed bounds, the block becomes dead.
type GoToCmd ¶
type GoToCmd int
GoToCmd instructs the numino application to navigate to another view. These values are emitted when a Viewer is done controlling the application.
type Grid ¶
Grid is a model for computing the boundaries and locations of game entities.
func (Grid) ColumnToCell ¶
func (Grid) ColumnToPixel ¶
func (Grid) PixelHeight ¶
func (Grid) PixelWidth ¶
func (Grid) RowToPixel ¶
type ImageBuffer ¶
type ImageBuffer struct {
// contains filtered or unexported fields
}
func NewImageBuffer ¶
func NewImageBuffer() *ImageBuffer
func (*ImageBuffer) Color ¶
func (buf *ImageBuffer) Color(c color.RGBA)
func (*ImageBuffer) Polygon ¶
func (buf *ImageBuffer) Polygon()
func (ImageBuffer) Renderer ¶
func (buf ImageBuffer) Renderer() Renderer
func (*ImageBuffer) Vertex ¶
func (buf *ImageBuffer) Vertex(x float64, y float64)
type ImageRenderer ¶
type ImageRenderer struct {
// contains filtered or unexported fields
}
ImageRenderer draws images to a window.
func NewImageRenderer ¶
func NewImageRenderer(img *imdraw.IMDraw) *ImageRenderer
func (ImageRenderer) Render ¶
func (r ImageRenderer) Render(win *pixelgl.Window)
Render implements the Renderer interface
type LandingType ¶
type LandingType int
LandingType describes a LandedEvent
const ( LandedOnDeadBlock LandingType = iota LandedOnLiveBlock LandedOnSpace Unlanded )
type MultiRenderer ¶
type MultiRenderer []Renderer
MultiRenderer executes multiple Renderers at once.
func (MultiRenderer) Render ¶
func (drawer MultiRenderer) Render(win *pixelgl.Window)
Render implements the Renderer interface
type ScoreRenderer ¶
type ScoreRenderer struct {
// contains filtered or unexported fields
}
func NewScoreRenderer ¶
func NewScoreRenderer(x float64, y float64) *ScoreRenderer
func (*ScoreRenderer) Render ¶
func (s *ScoreRenderer) Render(win *pixelgl.Window)
func (*ScoreRenderer) SetScore ¶
func (s *ScoreRenderer) SetScore(score float64)
type TextRenderer ¶
type TextRenderer struct {
// contains filtered or unexported fields
}
TextRenderer draws text to a window.
func NewTextRenderer ¶
func NewTextRenderer(text *text.Text) *TextRenderer
func (TextRenderer) Render ¶
func (r TextRenderer) Render(win *pixelgl.Window)
Render implements the Renderer interface