example

package
v0.0.0-...-7867579 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package client handles drawing the UI, interfacing with the player, and talking to the server.

TODO: SpawnNPC() should always trigger a new goroutine to handle that NPCs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckError

func CheckError(e error)

Types

type Actors

type Actors []engine.Actor

Actors is a wrapper for an array of Actors. It is necessary to Unmarshal objects that implement Actor.

func (*Actors) Arr

func (a *Actors) Arr() []engine.Actor

func (*Actors) UnmarshalJSON

func (a *Actors) UnmarshalJSON(data []byte) error

Takes JSON data and reads it into this array.

type Client

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

func (*Client) Addr

func (c *Client) Addr() string

func (*Client) HandleAction

func (c *Client) HandleAction(a engine.Action)

func (*Client) Init

func (c *Client) Init() *engine.UI

func (*Client) Maps

func (c *Client) Maps() map[string]engine.Map

func (*Client) Move

func (c *Client) Move(a engine.Action)

Move requests that the server move actor a in direction dir.

func (*Client) Ping

func (c *Client) Ping()

Ping asks the server for all information relevant to the client.

func (*Client) SetAddr

func (c *Client) SetAddr(addr string)

func (*Client) SetRPC

func (c *Client) SetRPC(conn *rpc.Client)

func (*Client) Spawn

func (c *Client) Spawn(a ...engine.Actor)

Spawn requests that the server spawn actors. The server determines where to spawn them and returns the map where they spawned.

func (*Client) Squad

func (c *Client) Squad() []engine.Actor

type Map

type Map struct {
	Name    string // The key that identifies this map in the server.
	Height  int    // The number of vertical tiles.
	Width   int    // The number of horizontal tiles.
	Players Actors
	Tiles   [][]engine.Tile
	// contains filtered or unexported fields
}

Map is a 2 dimensional plane containing tiles, objects and Actors. Each map will continue to Tick, so long as it has at least one active connection.

func NewMap

func NewMap(w, h int, name string) *Map

NewMap creates a new, empty map with given dimensions and names.

func (*Map) Actors

func (m *Map) Actors() []engine.Actor

func (*Map) AllTiles

func (m *Map) AllTiles() [][]engine.Tile

AllTiles returns all of the map's tiles. It is congruent with calling TileSlice(0, 0, Map.Width, Map.Height)

func (*Map) Tick

func (m *Map) Tick()

Tick moves time forward one tick after it has received a valid Action from each Actor on the Map. Tick blocks all NPCs and connections.

Currently, Actions are evaluated in FIFO order, meaning that Players' actions

will almost always be evaluated last.

func (*Map) TileSlice

func (m *Map) TileSlice(Ox, Oy, w, h int) [][]engine.Tile

TileSlice returns the contents of all tiles within the bounds of [(x1, y1), (x2, y2)]

func (*Map) WaitForTurn

func (m *Map) WaitForTurn(i int) bool

WaitForTurn blocks an actor until Tick gives them priority.

type MoveAction

type MoveAction struct {
	Caller string    // The originator of the MocwAction.
	Target string    // The name of the Actor to move.
	Pos    rogue.Pos // The coordinates to move them to.
}

MoveAction is used to move Objects.

type Player

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

func NewPlayer

func NewPlayer(name string) *Player

NewPlayer creates a new Player using the standard '@' character sprite.

func (*Player) ID

func (p *Player) ID() string

func (*Player) Index

func (p *Player) Index() int

func (*Player) JSON

func (p *Player) JSON() PlayerJSON

func (*Player) MarshalJSON

func (p *Player) MarshalJSON() ([]byte, error)

MarshalJSON converts the Player into JSON bytes.

func (*Player) Move

func (p *Player) Move(pos engine.Pos) bool

func (*Player) Name

func (p *Player) Name() string

func (*Player) Pos

func (p *Player) Pos() *engine.Pos

func (*Player) SetIndex

func (p *Player) SetIndex(i int)

func (*Player) SetPos

func (p *Player) SetPos(pos engine.Pos)

func (*Player) Sprite

func (p *Player) Sprite() termbox.Cell

func (*Player) UnmarshalJSON

func (p *Player) UnmarshalJSON(data []byte) error

UnmarshalJSON reads JSON data into this Player.

type PlayerJSON

type PlayerJSON struct {
	Name   string
	Index  int
	Pos    *engine.Pos
	Sprite termbox.Cell
	Type   string
}

PlayerJSON allows Player objects to be converted into JSON and transported via JSON RPC.

type Pong

type Pong struct {
	Squad Actors
	Maps  map[string]*Map
}

type Server

type Server struct {
	engine.Server

	Maps map[string]*Map
	// contains filtered or unexported fields
}

Game logic is handled on the server.

Each world gets at least one goroutine, with each active map getting its own goroutine as well.

func (*Server) Conns

func (s *Server) Conns() map[string]*engine.Conn

func (*Server) HandleRequests

func (s *Server) HandleRequests()

func (*Server) Move

func (s *Server) Move(args *MoveAction, reply *engine.ActionResponse) error

func (*Server) Ping

func (s *Server) Ping(addr *string, reply *Pong) error

func (*Server) SetPort

func (s *Server) SetPort(port string)

func (*Server) Spawn

func (s *Server) Spawn(args *SpawnAction, reply *bool) error

Spawn spawns new actors on the first map.

type SpawnAction

type SpawnAction struct {
	Caller string
	Actors Actors // TODO: (8) Change to object rather than Actor.
}

MoveAction is used to spawn Objects.

Jump to

Keyboard shortcuts

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