numino

package module
v0.0.0-...-f16d6ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2018 License: MIT Imports: 17 Imported by: 0

README


numino
Numino

Numino is a tetris-clone that uses numbers instead of shapes.

Quickstart

go install github.com/kharland/numino/cmd/numino
numino

Concepts

Cells

A cell is a space on the screen. Numinos that fall from the top of the screen occupy one cell each.

Numino

Numino are blocks that the player must place at the bottom of the game window. A numino is either live or dead. A live numino's value is between -10 and 10 and a dead numino's value is outside this range. A numino with a value of zero is removed from the game.

Objective

Numinoes will continuously fall from the top of the screen. Your goal is to place as many numinos as possible without letting them reach the top of the screen. The game ends as soon as a cell in the top row contains a dead numino. A numino's value changes when you place another numino on top of it. For example, landing a numino with a value of 3 on a numino with a value of 5 will change that numino's value to 8.

Controls

Shifting

You can shift the falling numinos left or right using the a and d keys, respectively.

Slamming

You can slam the numinoes to the bottom of the screen using the s key. This immediately places the numino at the lowest cell that it can occupy, merging it with another numino if possible.

Scoring

Your score is equal to the number of numinos that you successfuly land on the game board. Even if a numino dies as a result of landing, your score increases by one.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorBg           color.RGBA = colornames.Aliceblue
	ColorFallingBlock            = colornames.Cornflowerblue
	ColorDeadBlock               = colornames.Tomato
	ColorLiveBlock               = colornames.Aquamarine
	ColorSlamTrail               = colornames.Cadetblue
	ColorMenuOption              = colornames.Crimson
)

Functions

func LoadSounds

func LoadSounds()

LoadSounds loads all sounds.

func LoopSound

func LoopSound(sound Sound) int

LoopSound loops a sound.

A number that can be used to stop the sound via StopSound() is returned.

func PlaySound

func PlaySound(sound Sound)

PlaySound plays the specified sound.

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

func ViewControls(win *pixelgl.Window, grid *Grid, done chan GoToCmd)

ViewControls displays user controls.

func ViewGame

func ViewGame(win *pixelgl.Window, grid *Grid, done chan GoToCmd)

ViewGame runs the numino game.

func ViewMenu

func ViewMenu(win *pixelgl.Window, grid *Grid, done chan GoToCmd)

ViewMenu runs the main menu.

Types

type Block

type Block struct {
	Col   int
	Row   int
	Value int
}

Block represents an object that occupies a space on the game grid.

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) Length

func (blocks FallingBlocks) Length() int

Length ...

func (*FallingBlocks) Random

func (blocks *FallingBlocks) Random(count int)

Random generates a new set of cells in the first row.

func (*FallingBlocks) Remove

func (blocks *FallingBlocks) Remove(row int, col int)

Remove ...

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

func NewGameState(rows int, cols int) *GameState

NewGameState returns a GameState with the given number of rows and columns. All blocks are initially alive and empty.

func (*GameState) AddBlock

func (gs *GameState) AddBlock(block Block) error

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.

func (GameState) ColCount

func (gs GameState) ColCount() int

func (*GameState) IsDead

func (gs *GameState) IsDead(row int, col int) bool

func (*GameState) IsEmpty

func (gs *GameState) IsEmpty(row int, col int) bool

func (*GameState) IsOver

func (gs *GameState) IsOver() bool

IsOver returns true iff this game is over.

This game is over when the top-most row of any column contains a dead block.

func (GameState) RowCount

func (gs GameState) RowCount() int

func (*GameState) ValueAt

func (gs *GameState) ValueAt(row int, col int) int

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.

const (
	// GoToExit instructs numino to exit.
	GoToExit GoToCmd = iota
	// GoToNewGame instructs numino to start a new game.
	GoToNewGame
	// GoToMenu instructs numino to go to the main menu.
	GoToMenu
	// GoToControls instructs numino to show the controls.
	GoToControls
)

type Grid

type Grid struct {
	Cols       int
	Rows       int
	SquareSize float64
}

Grid is a model for computing the boundaries and locations of game entities.

func (Grid) ColumnToCell

func (g Grid) ColumnToCell(n int) float64

func (Grid) ColumnToPixel

func (g Grid) ColumnToPixel(n int) float64

func (Grid) PixelHeight

func (g Grid) PixelHeight() float64

func (Grid) PixelWidth

func (g Grid) PixelWidth() float64

func (Grid) RowToCell

func (g Grid) RowToCell(n int) float64

func (Grid) RowToPixel

func (g Grid) RowToPixel(n int) float64

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) Text

func (buf *ImageBuffer) Text(row float64, col float64, msg string)

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 Renderer

type Renderer interface {
	Render(*pixelgl.Window)
}

Renderer is an interface for objects that draw to a window.

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 Sound

type Sound int
const (
	ShiftSound Sound = iota
	SlamSound
	MergeSound
	DieSound
	BackgroundMusic
)

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

type ViewFunc

type ViewFunc func(win *pixelgl.Window, done chan GoToCmd)

ViewFunc runs an game view, such as the main menu or gameplay screen.

A view is expected to signal when it is done by emitting a GoToCmd on the given done channel.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL