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
- Variables
- func CalculateDistance(from, to *Dot) (res uint16)
- func ValidDirection(dir Direction) bool
- type Direction
- type Dot
- type DotList
- type Entity
- type Object
- type Playground
- func (pg *Playground) Contains(dot *Dot) bool
- func (pg *Playground) Delete(object Object) error
- func (pg *Playground) GetArea() uint16
- func (pg *Playground) GetObjectByDot(dot *Dot) Object
- func (pg *Playground) GetRandomEmptyDot() (*Dot, error)
- func (pg *Playground) GetRandomEmptyRect(rw, rh uint8) (*Rect, error)
- func (pg *Playground) GetSize() (uint8, uint8)
- func (pg *Playground) Locate(object Object, occupy bool) error
- func (pg *Playground) Located(object Object) bool
- func (pg *Playground) Navigate(dot *Dot, dir Direction, dis uint8) (*Dot, error)
- func (pg *Playground) Occupied(dot *Dot) bool
- func (pg *Playground) RandomDot() *Dot
- func (pg *Playground) RandomRect(rw, rh uint8) (*Rect, error)
- type Rect
Constants ¶
const ( DIR_NORTH = iota DIR_EAST DIR_SOUTH DIR_WEST )
Variables ¶
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") )
var ErrInvalidDirection = errors.New("invalid direction")
Functions ¶
func CalculateDistance ¶
CalculateDistance calculates distance between two dots
func ValidDirection ¶
ValidDirection returns true if passed direction is valid
Types ¶
type Direction ¶
type Direction uint8
Direction indicates movement direction
func CalculateDirection ¶
CalculateDirection calculates direction by two passed dots
func ReverseDirection ¶
ReverseDirection reverses passed direction
func (Direction) MarshalJSON ¶
Implementing json.Marshaler interface
type Dot ¶
type Dot struct {
// contains filtered or unexported fields
}
func NewRandomDotOnSquare ¶
NewRandomDotOnSquare generates random dot on square with coordinates x and y, width w and height h
func (*Dot) MarshalJSON ¶
Implementing json.Marshaler interface
type DotList ¶
type DotList []*Dot
DotList represents list of dots
func EntityToDotList ¶
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) 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 ¶
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 (*Rect) ContainsDot ¶
func (*Rect) ContainsRect ¶
func (*Rect) MarshalJSON ¶
Implementing json.Marshaler interface
func (*Rect) RandomDotOnRect ¶
RandomDotOnRect returns random dot on rect