Documentation ¶
Overview ¶
OUTPUT STANDARD 'ST_1'
1. Dots
1.1. Output pattern of dot is `X&Y` where 'X' and 'Y' are dot coordinates:
1&2 2&1 31&10
1.2. Dot set is printing as `dot1;dot2;dot3` where dotN is packed dot:
12&12;12&13;12&14;14&15
2. Directions
2.1. Direction packs as exclamation mark and letter of a direction:
!n !s !e !w
2.2 Used directions
n - north s - sounth e - east w - west
3. Objects
3.1 Output pattern of objects is `'TYPE'ID[OBJECT_DATA]` where 'TYPE' is a type of object (in single quotes), 'ID' is object identifier on playground, 'OBJECT_DATA' is a dataset which object contains (string returned Pack method of object). For example:
'apple'2[22&22] 'apple'3[1&7] 'corpse'5[1&7;6&6;5&7;9&8] 'snake'10[key%3%1&2;21&2;21&3]
'OBJECT_DATA' cannot contain chars '[', ']', ','
3.3 In a objectsets objects are separated by comma:
'apple'3[1&7],'snake'10[3%1&2;21&2;21&3]
Objects of different types cannot have equal type name markers.
4. Cached objects
4.1. If object state was not updated it are created in cache list. In cache list objects are represented like numbers according with it's identifiers on playground separated by comma:
1,2,3,4,5,6,7
4.2. Identifiers of cached objects are printed in objectset:
1,2,'apple'3[1&7],4,5,6,7,8,9,'snake'10[3%1&2;21&2;21&3]
4.3 Objects cannot be created in object set twice: as identifier (like cached object) and as updated packed object
This package provides simple small engine for flat games. It contains minimum set of functions, objects and interfaces to develop online 2d arcade games such as tanks or snake etc.
Author: Pushkin Ivan <pushkin13@bk.ru>
Index ¶
- Variables
- func CalculatePath(from, to *Dot) uint16
- func ValidDirection(dir Direction) bool
- type Direction
- type Dot
- type DotList
- 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) GetEmptyDot() (*Dot, error)
- func (pg *Playground) GetEmptyField(w, h uint8) (DotList, error)
- func (pg *Playground) GetObjectByDot(dot *Dot) Object
- func (pg *Playground) GetSize() (uint8, uint8)
- func (pg *Playground) Locate(object Object) error
- func (pg *Playground) Located(object Object) bool
- func (pg *Playground) Navigate(dot *Dot, dir Direction, dis int16) (*Dot, error)
- func (pg *Playground) Occupied(dot *Dot) bool
- func (pg *Playground) Pack() (output string)
- func (pg *Playground) PackObjects(ids []int) (output string)
- func (pg *Playground) RandomDot() *Dot
- func (pg *Playground) Updated() bool
- type Shifting
Constants ¶
This section is empty.
Variables ¶
var ( ErrPGNotContainsDot = errors.New("Playground doesn't contain dot") ErrNilPlayground = errors.New("Playground is nil") ErrInvalid_W_or_H = errors.New("Invalid width or height") ErrPassedNilObject = errors.New("Passed nil object") )
var ErrEmptyDotList = errors.New("Empty dot list")
var ErrInvalidDirection = errors.New("Invalid direction")
Functions ¶
func CalculatePath ¶
CalculatePath calculates path between two dots
func ValidDirection ¶
ValidDirection returns true if passed direction is valid
Types ¶
type Direction ¶
type Direction uint8
Direction indicates movement direction of a object
func CalculateDirection ¶
CalculateDirection calculates direction by two passed dots
func ReverseDirection ¶
ReverseDirection reverses passed direction dir
type Dot ¶
type Dot struct {
// contains filtered or unexported fields
}
Dot are used to understand object position
func NewDefaultDot ¶
func NewDefaultDot() *Dot
func NewRandomDotOnSquare ¶
NewRandomDotOnSquare generates random dot on square with coordinates x and y and width w and height h
type DotList ¶
type DotList []*Dot
DotList represents list of dots and provides list packing
type Object ¶
type Object interface { DotCount() uint16 // DotCount must return dot count Dot(i uint16) *Dot // Dot returns dot by index Pack() string // Pack converts object data to string }
Each object must implements Object interface
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) GetEmptyDot ¶
func (pg *Playground) GetEmptyDot() (*Dot, error)
GetEmptyDot finds empty random dot
func (*Playground) GetEmptyField ¶
func (pg *Playground) GetEmptyField(w, h uint8) (DotList, error)
GetEmptyField finds empty field with passed width and height
func (*Playground) GetObjectByDot ¶
func (pg *Playground) GetObjectByDot(dot *Dot) Object
GetObjectByDot returns object which contains passed dot
func (*Playground) GetSize ¶
func (pg *Playground) GetSize() (uint8, uint8)
GetSize returns width and height of playground
func (*Playground) Locate ¶
func (pg *Playground) Locate(object Object) error
Locate tries to create object to playground
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) Pack ¶
func (pg *Playground) Pack() (output string)
Pack packs playground in accordance with standard ST_1
func (*Playground) PackObjects ¶
func (pg *Playground) PackObjects(ids []int) (output string)
PackObjects packs objects to string in accordance with standard ST_1 by passed object identifiers
func (*Playground) RandomDot ¶
func (pg *Playground) RandomDot() *Dot
RandomDot generates random dot located on playground
func (*Playground) Updated ¶
func (pg *Playground) Updated() bool
Updated returns true if any object on playground was updated or just added or deleted
type Shifting ¶
type Shifting interface { PackChanges() string // PackChanges packs last changes Updated() time.Time // Updated returns last updating time }
Moving and shifting objects must implement Shifting interface. For objects which implements Object and Shifting interfaces method Pack returns all object data and method PackChanges returns only last updates.