playground

package
v2.0.0-rc-2016+incompa... Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2016 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

This package provides simple small engine for flat games. It contains minimum set of functions, objects and interfaces to develop 2d arcade games such as tanks or snake etc.

Index

Constants

View Source
const (
	DIR_NORTH = iota
	DIR_EAST
	DIR_SOUTH
	DIR_WEST
)

Variables

View Source
var (
	ErrPGNotContainsDot = errors.New("playground doesn't contain dot")
	ErrInvalid_W_or_H   = errors.New("invalid width or height")
	ErrObjectNotLocated = errors.New("passed object is not located")
)
View Source
var ErrInvalidDirection = errors.New("invalid direction")

Functions

func CalculateDistance

func CalculateDistance(from, to *Dot) (res uint16)

CalculateDistance calculates distance between two dots

func ValidDirection

func ValidDirection(dir Direction) bool

ValidDirection returns true if passed direction is valid

Types

type Direction

type Direction uint8

Direction indicates movement direction

func CalculateDirection

func CalculateDirection(from, to *Dot) Direction

CalculateDirection calculates direction by two passed dots

func RandomDirection

func RandomDirection() Direction

RandomDirection returns random direction

func ReverseDirection

func ReverseDirection(dir Direction) (Direction, error)

ReverseDirection reverses passed direction

func (Direction) MarshalJSON

func (dir Direction) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

type Dot

type Dot struct {
	// contains filtered or unexported fields
}

func NewDot

func NewDot(x, y uint8) *Dot

NewDot creates dot object

func NewRandomDotOnSquare

func NewRandomDotOnSquare(x, y, w, h uint8) *Dot

NewRandomDotOnSquare generates random dot on square with coordinates x and y, width w and height h

func (*Dot) Equals

func (d1 *Dot) Equals(d2 *Dot) bool

Equals compares two dots

func (*Dot) MarshalJSON

func (d *Dot) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

type DotList

type DotList []*Dot

DotList represents list of dots

func EntityToDotList

func EntityToDotList(e Entity) DotList

func (DotList) Contains

func (dl DotList) Contains(dot *Dot) bool

Contains returns true if dot list contains passed dot

func (DotList) Delete

func (dl DotList) Delete(dot *Dot)

Delete deletes dot from dot list

func (DotList) Dot

func (dl DotList) Dot(i uint16) *Dot

Implementing Entity interface

func (DotList) DotCount

func (dl DotList) DotCount() uint16

Implementing Entity interface

func (DotList) Reverse

func (dl DotList) Reverse() DotList

Reverse reverses dot list

type Entity

type Entity interface {
	Dot(i uint16) *Dot // Dot returns dot by index
	DotCount() uint16  // DotCount must return dot count
}

type Object

type Object interface {
	Entity
}

type Playground

type Playground struct {
	// contains filtered or unexported fields
}

Playground object contains all objects on map

func NewPlayground

func NewPlayground(width, height uint8) (*Playground, error)

NewPlayground returns new empty playground

func (*Playground) Contains

func (pg *Playground) Contains(dot *Dot) bool

Contains return true if playground contains passed dot

func (*Playground) Delete

func (pg *Playground) Delete(object Object) error

Delete deletes passed object from playground and returns error if there is a problem

func (*Playground) GetArea

func (pg *Playground) GetArea() uint16

GetArea returns playground area

func (*Playground) GetObjectByDot

func (pg *Playground) GetObjectByDot(dot *Dot) Object

GetObjectByDot returns object which contains passed dot

func (*Playground) GetRandomEmptyDot

func (pg *Playground) GetRandomEmptyDot() (*Dot, error)

GetRandomEmptyDot returns random empty dot

func (*Playground) GetRandomEmptyRect

func (pg *Playground) GetRandomEmptyRect(rw, rh uint8,
) (*Rect, error)

GetEmptyField finds empty field with passed width and height

func (*Playground) GetSize

func (pg *Playground) GetSize() (uint8, uint8)

func (*Playground) Locate

func (pg *Playground) Locate(object Object, occupy bool) error

Locate tries to create object on playground. If occupy=true object may be located only if each object dot is not occupied

func (*Playground) Located

func (pg *Playground) Located(object Object) bool

Located returns true if passed object is located on playground

func (*Playground) Navigate

func (pg *Playground) Navigate(dot *Dot, dir Direction, dis uint8,
) (*Dot, error)

Navigate calculates and returns dot placed on distance dis dots from passed dot in direction dir

func (*Playground) Occupied

func (pg *Playground) Occupied(dot *Dot) bool

Occupied returns true if passed dot already used by any object located on playground

func (*Playground) RandomDot

func (pg *Playground) RandomDot() *Dot

RandomDot generates random dot located on playground

func (*Playground) RandomRect

func (pg *Playground) RandomRect(rw, rh uint8) (*Rect, error)

type Rect

type Rect struct {
	// contains filtered or unexported fields
}

func NewRandomRectOnSquare

func NewRandomRectOnSquare(rw, rh, sx, sy, sw, sh uint8,
) (*Rect, error)

func NewRect

func NewRect(x, y, w, h uint8) *Rect

NewRect creates rect

func (*Rect) ContainsDot

func (r *Rect) ContainsDot(d *Dot) bool

func (*Rect) ContainsRect

func (r1 *Rect) ContainsRect(r2 *Rect) bool

func (*Rect) Dot

func (r *Rect) Dot(i uint16) *Dot

Implementing Entity interface

func (*Rect) DotCount

func (r *Rect) DotCount() uint16

Implementing Entity interface

func (*Rect) Equals

func (r1 *Rect) Equals(r2 *Rect) bool

func (*Rect) MarshalJSON

func (r *Rect) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

func (*Rect) RandomDotOnRect

func (r *Rect) RandomDotOnRect() *Dot

RandomDotOnRect returns random dot on rect

Jump to

Keyboard shortcuts

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