Documentation ¶
Index ¶
- Constants
- Variables
- func I(x int, y int, w int) int
- type Bag
- type Block
- type LockedMatrix
- type LockedPiece
- type Matrix
- func (m *Matrix) Add(mn *Piece, b Block, loc Point, overlay bool) error
- func (m *Matrix) AddPendingGarbage(lines int)
- func (m *Matrix) AddTestBlocks()
- func (m *Matrix) AttachBag(bag *Bag) bool
- func (m *Matrix) Block(x int, y int) Block
- func (m *Matrix) CalculateBonusGarbage() int
- func (m *Matrix) CanAdd(mn *Piece) bool
- func (m *Matrix) CanAddAt(mn *Piece, loc Point) bool
- func (m *Matrix) Clear()
- func (m *Matrix) ClearFilled() int
- func (m *Matrix) ClearOverlay()
- func (m *Matrix) ClearOverlayL()
- func (m *Matrix) Draw()
- func (m *Matrix) DrawActivePieceL()
- func (m *Matrix) DrawGhostPieceL()
- func (m *Matrix) Empty(loc Point) bool
- func (m *Matrix) HandleReceiveGarbage()
- func (m *Matrix) HardDropPiece()
- func (m *Matrix) LineFilled(y int) bool
- func (m *Matrix) LowerPiece()
- func (m *Matrix) MarshalJSON() ([]byte, error)
- func (m *Matrix) MovePiece(x int, y int) bool
- func (m *Matrix) Moved()
- func (m *Matrix) ReceiveGarbage()
- func (m *Matrix) Render() string
- func (m *Matrix) Replace(newmtx *Matrix)
- func (m *Matrix) Reset()
- func (m *Matrix) RotatePiece(rotations int, direction int) bool
- func (m *Matrix) SetBlock(x int, y int, block Block, overlay bool) bool
- func (m *Matrix) SetGameOver()
- func (m *Matrix) SpawnLocation(p *Piece) Point
- func (m *Matrix) TakePiece() bool
- func (m *Matrix) ValidPoint(x int, y int) bool
- type MatrixType
- type Mino
- func (m Mino) Canonical() Mino
- func (m Mino) Flatten() Mino
- func (m Mino) HasPoint(p Point) bool
- func (m Mino) Len() int
- func (m Mino) Less(i, j int) bool
- func (m Mino) Origin() Mino
- func (m Mino) Render() string
- func (m Mino) Size() (int, int)
- func (m Mino) String() string
- func (m Mino) Swap(i, j int)
- func (m Mino) Variations() []Mino
- type Piece
- type PieceType
- type Point
- type RotationOffsets
Constants ¶
View Source
const ( GarbageDelay = 1500 * time.Millisecond // 1.5 seconds ComboBaseTime = 2.4 // Seconds )
View Source
const ( Monomino = "(0,0)" Domino = "(0,0),(1,0)" TrominoI = "(0,0),(1,0),(2,0)" TrominoL = "(0,0),(1,0),(0,1)" TetrominoI = "(0,0),(1,0),(2,0),(3,0)" TetrominoO = "(0,0),(1,0),(0,1),(1,1)" TetrominoT = "(0,0),(1,0),(2,0),(1,1)" TetrominoS = "(0,0),(1,0),(1,1),(2,1)" TetrominoZ = "(1,0),(2,0),(0,1),(1,1)" TetrominoJ = "(0,0),(1,0),(2,0),(0,1)" TetrominoL = "(0,0),(1,0),(2,0),(2,1)" PentominoF = "(0,0),(1,0),(1,1),(2,1),(1,2)" PentominoE = "(1,0),(2,0),(0,1),(1,1),(1,2)" PentominoJ = "(0,0),(1,0),(2,0),(3,0),(0,1)" PentominoL = "(0,0),(1,0),(2,0),(3,0),(3,1)" PentominoP = "(0,0),(1,0),(2,0),(0,1),(1,1)" PentominoZ = "(1,0),(2,0),(1,1),(0,2),(1,2)" PentominoI = "(0,0),(1,0),(2,0),(3,0),(4,0)" PentominoX = "(1,0),(0,1),(1,1),(2,1),(1,2)" PentominoV = "(0,0),(1,0),(2,0),(0,1),(0,2)" PentominoB = "(0,0),(1,0),(2,0),(1,1),(2,1)" PentominoN = "(1,0),(2,0),(3,0),(0,1),(1,1)" PentominoG = "(0,0),(1,0),(2,0),(2,1),(3,1)" PentominoS = "(0,0),(1,0),(1,1),(1,2),(2,2)" PentominoT = "(0,0),(1,0),(2,0),(1,1),(1,2)" PentominoU = "(0,0),(1,0),(2,0),(0,1),(2,1)" PentominoW = "(1,0),(2,0),(0,1),(1,1),(0,2)" PentominoY = "(0,0),(1,0),(2,0),(3,0),(2,1)" PentominoR = "(0,0),(1,0),(2,0),(3,0),(1,1)" )
View Source
const ( Rotation0 = 0 RotationR = 1 Rotation2 = 2 RotationL = 3 RotationStates = 4 )
Variables ¶
View Source
var AllOffsets = []Point{{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {-1, -1}, {1, -1}, {-2, 0}, {2, 0}}
Rotation offsets
View Source
var AllRotationPivotsCCW = [][]Point{ PieceUnknown: {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, PieceI: {{2, 1}, {-1, 00}, {2, 2}, {1, 3}}, PieceO: {{0, 1}, {0, 1}, {0, 1}, {0, 1}}, PieceJ: {{1, 1}, {0, 0}, {1, 2}, {1, 2}}, PieceL: {{1, 1}, {0, 0}, {1, 2}, {1, 2}}, PieceS: {{1, 1}, {0, 0}, {1, 2}, {1, 2}}, PieceT: {{1, 1}, {0, 2}, {1, 2}, {1, 2}}, PieceZ: {{1, 1}, {0, 0}, {1, 2}, {1, 2}}, }
View Source
var AllRotationPivotsCW = [][]Point{ PieceUnknown: {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, PieceI: {{1, -2}, {-1, 0}, {1, -1}, {0, 0}}, PieceO: {{1, 0}, {1, 0}, {1, 0}, {1, 0}}, PieceJ: {{1, -1}, {0, 0}, {1, 0}, {1, 0}}, PieceL: {{1, -1}, {0, 0}, {1, 0}, {1, 0}}, PieceS: {{1, -1}, {0, 0}, {1, 0}, {1, 0}}, PieceT: {{1, -1}, {0, 0}, {1, 0}, {1, 0}}, PieceZ: {{1, -1}, {0, 0}, {1, 0}, {1, 0}}, }
View Source
var Colors = [][]byte{ BlockNone: []byte("#000000"), BlockGarbage: []byte("#999999"), BlockGhostBlue: []byte("#6e7bc3"), BlockGhostCyan: []byte("#6bbaba"), BlockGhostRed: []byte("#ba6b6b"), BlockGhostYellow: []byte("#b1b16b"), BlockGhostMagenta: []byte("#a16ba8"), BlockGhostGreen: []byte("#6bb76b"), BlockGhostOrange: []byte("#c3806c"), BlockSolidBlue: []byte("#2864ff"), BlockSolidCyan: []byte("#00eeee"), BlockSolidRed: []byte("#ee0000"), BlockSolidYellow: []byte("#dddd00"), BlockSolidMagenta: []byte("#c000cc"), BlockSolidGreen: []byte("#00e900"), BlockSolidOrange: []byte("#ff7308"), }
Dark color ghosts are 60% original overlaid #777777 Light color ghosts are 40% original overlaid #888888
Functions ¶
Types ¶
type Bag ¶
type Bag struct { Minos []Mino Original []Mino *sync.Mutex // contains filtered or unexported fields }
func (*Bag) GarbageHole ¶
type LockedPiece ¶
type LockedPiece *Piece
type Matrix ¶
type Matrix struct { W int `json:"-"` // Width H int `json:"-"` // Height B int `json:"-"` // Buffer height M []Block // Matrix O []Block `json:"-"` // Overlay Bag *Bag `json:"-"` P *Piece PlayerName string `json:"pn,omitempty"` Type MatrixType `json:"ty,omitempty"` Event chan<- interface{} `json:"-"` Move chan int `json:"-"` Combo int `json:"mc,omitempty"` ComboStart time.Time `json:"-"` ComboEnd time.Time `json:"-"` PendingGarbage int `json:"-"` PendingGarbageTime time.Time `json:"-"` LinesCleared int `json:"lc,omitempty"` GarbageSent int `json:"gs,omitempty"` GarbageReceived int `json:"gr,omitempty"` Speed int `json:"sp,omitempty"` GameOver bool `json:"go,omitempty"` sync.Mutex `json:"-"` // contains filtered or unexported fields }
func NewMatrix ¶
func NewMatrix(w int, h int, b int, players int, event chan<- interface{}, draw chan event.DrawObject, t MatrixType) *Matrix
func NewTestMatrix ¶
func (*Matrix) AddPendingGarbage ¶
func (*Matrix) AddTestBlocks ¶
func (m *Matrix) AddTestBlocks()
func (*Matrix) CalculateBonusGarbage ¶
func (*Matrix) ClearFilled ¶
func (*Matrix) ClearOverlay ¶
func (m *Matrix) ClearOverlay()
func (*Matrix) ClearOverlayL ¶
func (m *Matrix) ClearOverlayL()
func (*Matrix) DrawActivePieceL ¶
func (m *Matrix) DrawActivePieceL()
func (*Matrix) DrawGhostPieceL ¶
func (m *Matrix) DrawGhostPieceL()
func (*Matrix) HandleReceiveGarbage ¶
func (m *Matrix) HandleReceiveGarbage()
func (*Matrix) HardDropPiece ¶
func (m *Matrix) HardDropPiece()
func (*Matrix) LineFilled ¶
func (*Matrix) LowerPiece ¶
func (m *Matrix) LowerPiece()
LowerPiece lowers the active piece by one line when possible, otherwise the piece is landed
func (*Matrix) MarshalJSON ¶
func (*Matrix) ReceiveGarbage ¶
func (m *Matrix) ReceiveGarbage()
func (*Matrix) SetGameOver ¶
func (m *Matrix) SetGameOver()
func (*Matrix) SpawnLocation ¶
type MatrixType ¶
type MatrixType int
const ( MatrixStandard MatrixType = iota MatrixPreview MatrixCustom )
type Piece ¶
type Piece struct { Point `json:"pp,omitempty"` Mino `json:"pm,omitempty"` Ghost Block `json:"pg,omitempty"` Solid Block `json:"ps,omitempty"` Rotation int `json:"pr,omitempty"` sync.Mutex `json:"-"` // contains filtered or unexported fields }
func (*Piece) ApplyReset ¶
func (p *Piece) ApplyReset()
func (*Piece) ApplyRotation ¶
func (*Piece) SetLocation ¶
type Point ¶
type Point struct {
X, Y int
}
func (Point) Neighborhood ¶
Neighborhood returns the Von Neumann neighborhood of a point
type RotationOffsets ¶
type RotationOffsets []Point
Source Files ¶
Click to show internal directories.
Click to hide internal directories.