vbge

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DirNorth is the exported direction north
	DirNorth = "north"
	// DirEast is the exported direction north
	DirEast = "east"
	// DirSouth is the exported direction north
	DirSouth = "south"
	// DirWest is the exported direction north
	DirWest = "west"
)

Variables

View Source
var (
	// ErrNoEnemy is an error if there's no enemy
	ErrNoEnemy = errors.New("No Enemy")

	// ErrOutOfMap is an error when a position is out of the map
	ErrOutOfMap = errors.New("Position is out of Map")

	// ErrNoMoveOutOfMap comes when the player wants to move out of the map
	ErrNoMoveOutOfMap = errors.New("Cannot move outside the map")

	// ErrHasResident appears when a block already has a resident and an action
	// should happen
	ErrHasResident = errors.New("Block already has a resident")

	// ErrAlreadyDef describes that the player already is defending
	ErrAlreadyDef = errors.New("Player is already defending")

	// ErrAlreadyUndef describes that the player is already undefending
	ErrAlreadyUndef = errors.New("Player is already undefending")

	// ErrCantMoveOFDefending means thath the player cant move because of defending
	ErrCantMoveOFDefending = errors.New("Player is not able to move, because of defending")
)
View Source
var (

	// MapWidth is the length in x-direction
	MapWidth = 11
	// MapHeight is the length in y-direction
	MapHeight = 11
	// HalfmapWidth is the half value of 'MapWidth'
	HalfmapWidth = MapWidth / 2

	// HalfmapHeight is the half value of 'MapHeight'
	HalfmapHeight = MapHeight / 2

	// RenderWidth is the visible area for a player in x-direction
	RenderWidth = 11
	// RenderHeight is the visible area for a player in y-direction
	RenderHeight = 11
	// HrWidth is the half value of 'RenderWidth'
	HrWidth = (RenderWidth - 1) / 2
	// HrHeight is the half value of 'RenderHeight'
	HrHeight = (RenderHeight - 1) / 2

	// MaxHealth is the default value of a player's character when he has
	// full health points
	MaxHealth = 100
)

Functions

func IsAngle

func IsAngle(angleCandidate string) bool

IsAngle determines whether the `angleCandidate` is actually a valid angle

func IsBlocktype

func IsBlocktype(blocktypeCandidate string) bool

IsBlocktype determines whether the `blocktypeCandidate` is actually a valid blocktype

func IsDir

func IsDir(dirCandidate string) bool

IsDir determines whether the `dirCandidate` is actually a valid direction

func IsDistance

func IsDistance(distanceCandidate int) bool

IsDistance determines wether the `distanceCanidate` is actually a valid distance

func SetMapDimensions

func SetMapDimensions(width, height int)

SetMapDimensions sets the default map dimensions (e.g. width and health)

Types

type Battle

type Battle struct {
	Map     *MapEntity
	Players map[int]*Player
}

Battle represents a logical game instance without runtime or network infos

func (*Battle) GetGRIDFromPlayerID

func (b *Battle) GetGRIDFromPlayerID(id int) (GRID string, err error)

GetGRIDFromPlayerID returns the GRID

type BlockEntity

type BlockEntity struct {
	Resident  *Player
	Blocktype string
}

BlockEntity represents a single point (block) in the map. It holds infos about it's environment and possible residents.

func (*BlockEntity) HasResident

func (be *BlockEntity) HasResident() bool

HasResident reports if a player is currently in this block or not.

func (*BlockEntity) JoinArea

func (be *BlockEntity) JoinArea(p *Player)

JoinArea marks the passed player as the current resident of this block.

func (*BlockEntity) LeaveArea

func (be *BlockEntity) LeaveArea()

LeaveArea dismarks the player which is currently the resident of this block to be a resident.

type EntityResp

type EntityResp struct {
	Blocktype string      `json:"bt"`
	Player    *PlayerResp `json:"p"`
}

EntityResp is the response value of a specific location with the values 'Blocktype' and 'Player'

type Health

type Health struct {
	sync.Mutex
	Value int
}

Health is a struct that describes the Health of a player

func NewDefaultHealth

func NewDefaultHealth() *Health

NewDefaultHealth returns the default health

func NewHealth

func NewHealth(health int) *Health

NewHealth accepts an integer value that is returned as new health

func (*Health) TakeDamage

func (h *Health) TakeDamage(p *Player)

TakeDamage returns the health of the player after taking dmg

type Location

type Location struct {
	X int `json:"x"`
	Y int `json:"y"`
}

Location represents a two-dimensional point in a matrix. It's values are zero-based. Therfore (0, 0) is the first point in the upper left.

func (*Location) AddDirection

func (l *Location) AddDirection(dir string)

AddDirection manipulates the current location by a factor of one into the cardinal direction specified by the `dir` parameter. `dir` must be a valid direction representation. Check with `vbge.IsDir`. This function doesn't validate the resulting location. Therefore it's maybe out-of-map. Check with `(*Location).IsInMap`

func (*Location) DeepCopy

func (l *Location) DeepCopy() *Location

DeepCopy allocates new memory and copies all the contents of the current location into the newly allocated one. Afterwards the pointer of the new struct is returned.

func (*Location) IsInMap

func (l *Location) IsInMap() bool

IsInMap checks whether the location is in the map or not. Determined with `(X && Y > 0) && (X < MapWidth) && (Y < MapHeight)`

func (*Location) RelativeFrom

func (l *Location) RelativeFrom(pl *Location) *Location

RelativeFrom returns the relative position from the center of the Rendermapsize

type MapEntity

type MapEntity struct {
	Height   int
	Width    int
	Matrix   [][]*BlockEntity
	SyncRoot sync.Mutex
}

MapEntity describes a single map instance.

func NewMapEntity

func NewMapEntity(width, height int) *MapEntity

NewMapEntity allocates memory for a new map with the size specified by the `width` and `height` parameter.

func (*MapEntity) GetMatrixSectionFromMapentity

func (me *MapEntity) GetMatrixSectionFromMapentity(width, height int, p *Player, sync bool) (gameMatrix [][]*BlockEntity)

GetMatrixSectionFromMapentity returns the 'viewable' matrix of a given player

func (*MapEntity) GetNewLineFromMapEntity

func (me *MapEntity) GetNewLineFromMapEntity(width int, p *Player, direction string) (gameLine [][]*BlockEntity)

GetNewLineFromMapEntity is returning a 11x1 dim (RenderWidth), usually called when a player is moving

func (*MapEntity) LeaveArea

func (me *MapEntity) LeaveArea(p *Player, l Location)

LeaveArea is calling (*BlockEntity).LeaveArea() to set a location after moving to nil, so the location isn't blocked anymore.

func (*MapEntity) PInMatrix

func (me *MapEntity) PInMatrix() bool

PInMatrix returns true if any player is in the matrix of the given MapEntity. If a player occurs, true is returned

func (*MapEntity) PInRenderArea

func (me *MapEntity) PInRenderArea(l Location) NotifyGroup

PInRenderArea returns all the players that are inside the render area around the passend location. Result is returned as a `NotifyGroup`. This function isn't safe for concurrent use.

func (*MapEntity) TryJoinAreaSynced

func (me *MapEntity) TryJoinAreaSynced(p *Player, l Location) (joined bool, ng NotifyGroup)

TryJoinAreaSynced checks whether the area passed is empty and hence joinable. If so it joins `(*BlockEntity).JoinArea` and calculates the `NotifyGroup` for this operation. This function is safe for concurrent use.

type NotifyGroup

type NotifyGroup []*Player

NotifyGroup specifies a set of `*Player` that should be informed about a specific event.

type OpLimitations

type OpLimitations struct {
	Rotate      ratelimit.Limiter
	Move        ratelimit.Limiter
	Radar       ratelimit.Limiter
	Scout       ratelimit.Limiter
	Environment ratelimit.Limiter
	Watch       ratelimit.Limiter
	Attack      ratelimit.Limiter
	Defend      ratelimit.Limiter
	Health      ratelimit.Limiter
}

OpLimitations stores ratelimit datastructures for each callable player operation

func NewOpLimitations

func NewOpLimitations() *OpLimitations

NewOpLimitations returns a new pointer to a new OpLimitation container with default time-limitations already set.

type Player

type Player struct {
	UserID        int
	GRenderID     string
	PicLink       string
	Map           *MapEntity
	Location      *Location
	WatchDir      string
	Health        *Health
	IsDefending   bool
	Kills         int
	Deaths        int
	Rl            *OpLimitations
	CharacterType string
}

Player represents a single character in the game. It collects all infos needed.

func NewDebugPlayer

func NewDebugPlayer(m *MapEntity) *Player

NewDebugPlayer returns a player that can be used for DEMO-purposes

func NewPlayerWithSpawn

func NewPlayerWithSpawn(userID int, m *MapEntity) (p *Player, err error)

NewPlayerWithSpawn creates a new player and spawn the player on the map

func (*Player) Attack

func (p *Player) Attack(beforeRespawn func(*Player, NotifyGroup), afterRespawn func(*Player, NotifyGroup)) (enemyHealth int, ng NotifyGroup, err error)

Attack implements https://sdk-wiki.vikebot.com/#attack

func (*Player) Defend

func (p *Player) Defend() (ng NotifyGroup, err error)

Defend implements https://sdk-wiki.vikebot.com/#defend-and-undefend

func (*Player) Environment

func (p *Player) Environment() (blocktypeMatrix [][]string, ng NotifyGroup, err error)

Environment implements https://sdk-wiki.vikebot.com/#environment

func (*Player) GetHealth

func (p *Player) GetHealth() (health int, ng NotifyGroup)

GetHealth returns the health as an int value of a player

func (*Player) Move

func (p *Player) Move(dir string) (ng NotifyGroup, err error)

Move implements https://sdk-wiki.vikebot.com/#move

func (*Player) Radar

func (p *Player) Radar() (playerCount int, ng NotifyGroup, err error)

Radar implements https://sdk-wiki.vikebot.com/#radar

func (*Player) Respawn

func (p *Player) Respawn() error

Respawn removes the player from it's current position and add calls `Spawn` to place it again.

func (*Player) RespawnSynced

func (p *Player) RespawnSynced() error

RespawnSynced is like `Respawn` but locks the Map

func (*Player) Rotate

func (p *Player) Rotate(angle string) NotifyGroup

Rotate implements https://sdk-wiki.vikebot.com/#rotate

func (*Player) SafeHealthSynced

func (p *Player) SafeHealthSynced() int

SafeHealthSynced returns a definite state of player health

func (*Player) Scout

func (p *Player) Scout(distance int) (playerCount int, ng NotifyGroup, err error)

Scout implements https://sdk-wiki.vikebot.com/#scout

func (*Player) Spawn

func (p *Player) Spawn() error

Spawn places the player randomly on the map as long as the location doesn't already have a resident. If so Spawn will retry 20 times. If no suitable location is found an error is returned.

func (*Player) SpawnSynced

func (p *Player) SpawnSynced() error

SpawnSynced is like `Spawn` but locks the Map

func (*Player) Undefend

func (p *Player) Undefend() (ng NotifyGroup, err error)

Undefend implements https://sdk-wiki.vikebot.com/#defend-and-undefend

func (*Player) Watch

func (p *Player) Watch() (playerhealthMatrix [][]int, ng NotifyGroup, err error)

Watch implements https://sdk-wiki.vikebot.com/#watch

type PlayerResp

type PlayerResp struct {
	GRID          string   `json:"grid"`
	Health        int      `json:"health"`
	CharacterType string   `json:"ct"`
	WatchDir      string   `json:"watchdir"`
	Location      Location `json:"location"`
}

PlayerResp is the response value of player for vbwatch

type ViewableMapentity

type ViewableMapentity struct {
	Height int             `json:"height"`
	Witdh  int             `json:"width"`
	Matrix [][]*EntityResp `json:"matrix"`
}

ViewableMapentity is nearly the same like 'MapEntity' but only the for a specific player visible matrix including other players and blocktypes

func GetNewLineMapentity

func GetNewLineMapentity(width, userID int, game *Battle, direction string) (newLineMeViewable *ViewableMapentity, err error)

GetNewLineMapentity returns a new mapentity with a size of 1x11 or 11x1 depends on moving direction

func GetViewableMapentity

func GetViewableMapentity(width, height, userID int, game *Battle, sync bool) (viewableMapentity *ViewableMapentity, err error)

GetViewableMapentity returns a Mapentity for a specific player

Jump to

Keyboard shortcuts

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