common

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2020 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UP            byte = 1 << 0
	DOWN          byte = 1 << 1
	LEFT          byte = 1 << 2
	RIGHT         byte = 1 << 3
	UPLEFT        byte = UP | LEFT
	UPRIGHT       byte = UP | RIGHT
	DOWNLEFT      byte = DOWN | LEFT
	DOWNRIGHT     byte = DOWN | RIGHT
	ALLDIR        byte = UP | DOWN | LEFT | RIGHT
	UPDOWN        byte = UP | DOWN
	LEFTRIGHT     byte = LEFT | RIGHT
	UPDOWNLEFT    byte = UP | DOWN | LEFT
	UPDOWNRIGHT   byte = UP | DOWN | RIGHT
	LEFTDOWNRIGHT byte = LEFT | DOWN | RIGHT
	LEFTUPRIGHT   byte = LEFT | UP | RIGHT
)
View Source
const MaxPacketSize = 1024

MaxPacketSize anything bigger gets booted, or if server sends over 1024 in one packet there will be a read error on the clients For multipart binary transfers we use http to make things easier

Variables

View Source
var Debug = false
View Source
var ErrLength = errors.New("type length is wrong")
View Source
var ErrZero = errors.New("id is zero")

Functions

func Connect

func Connect(userid uint64, server string, options *ConnectOptions) (*net.TCPConn, error)

func DPAD

func DPAD(b byte) string

func Endian

func Endian() binary.ByteOrder

func GenUUID

func GenUUID() uint64

func MSG

func MSG(b byte) string

func Sprint64

func Sprint64(i uint64) string

Sprint64 returns a binary representation of 64 bit unsigned integer, but in 8 chunks of 8 bits

func SprintByte

func SprintByte(c byte) string

SprintByte returns a binary representation of 8 bits

func TYPE

func TYPE(t types.Type) string

func Vec2Dir

func Vec2Dir(v pixel.Vec) byte

Types

type ClientUpdate

type ClientUpdate struct {
	T          string
	UpdateTick time.Duration
}

func (ClientUpdate) Type

func (s ClientUpdate) Type() types.Type

type Component

type Component interface {
	Type() types.Type
	Value() interface{}
	String() string // return short human readable form, Include "Component" or "Component " prefix
}

Component type. Such as... Health Mana StatusEffects ArmorClass WeaponDamage

type ConnectOptions

type ConnectOptions struct {
}

type DIR

type DIR byte

func (DIR) Vec

func (dd DIR) Vec() pixel.Vec

1000 0101

type ExpBar

type ExpBar struct {
	StatBar64
}

type HealthBar

type HealthBar struct {
	StatBar
}

type HealthReport

type HealthReport struct {
	M map[uint64]HealthStatus // current/max health
}

type HealthStatus

type HealthStatus struct {
	ID   uint64
	From uint64
	Cur  float64
	Max  float64
	Dam  float64
}

type Login

type Login struct {
	ID       uint64
	Password [32]byte `gob:",omitempty"`
}

func (*Login) Decode

func (l *Login) Decode(b []byte) (err error)

func (Login) Encode

func (l Login) Encode(b []byte) (n int, err error)

func (Login) EncodeTo

func (l Login) EncodeTo(w io.Writer) (n int, err error)

func (Login) Type

func (l Login) Type() types.Type

type ManaBar

type ManaBar struct {
	StatBar
}

type Message

type Message struct {
	Dpad      byte
	UnusedPad byte
	Key       int16
	Keymod    int16
	Action    uint16
	Count     uint16
}

func (Message) String

func (p Message) String() string

func (Message) Type

func (p Message) Type() types.Type

type Ping

type Ping struct {
	ID   uint64
	Time time.Time
}

func (Ping) Encode

func (l Ping) Encode(b []byte) (n int, err error)

func (Ping) String

func (p Ping) String() string

func (Ping) Type

func (l Ping) Type() types.Type

type Player

type Player struct {
	PID        uint64
	EntityType uint16
	PosX       float64
	PosY       float64
	// StatBars   []StatBar
	// StatBar64  []StatBar64
	HP float64
	MP float64
}

Player is a Typer, Positioner, Pos(), and a world.Being (MoveTo, ID, X, Y)

Weird entity names because methods should instead be used by users of this struct. Positions/Components arent guarded, and instead should be guarded by the World or Game

func (*Player) DealDamage

func (e *Player) DealDamage(from uint64, amount float64) float64

func (Player) Health

func (e Player) Health() float64

func (Player) ID

func (p Player) ID() uint64

func (*Player) MoveTo

func (p *Player) MoveTo(xy [2]float64)

func (Player) Pos

func (p Player) Pos() pixel.Vec

func (*Player) SetHealth

func (e *Player) SetHealth(hp float64)

func (Player) Type

func (p Player) Type() types.Type

func (Player) X

func (p Player) X() float64

func (Player) Y

func (p Player) Y() float64

type PlayerAction

type PlayerAction struct {
	ID     uint64
	At     [2]int64
	DPad   byte
	Action uint16
	HP     float64
}

func (PlayerAction) Pos

func (p PlayerAction) Pos() [2]float64

func (PlayerAction) Type

func (p PlayerAction) Type() types.Type

type PlayerLogoff

type PlayerLogoff struct {
	UID uint64
}

func (PlayerLogoff) Type

func (p PlayerLogoff) Type() types.Type
func (p PlayerLogoff) Encode(b []byte) (n int, err error) {
	buf := new(bytes.Buffer)
	err = gob.NewEncoder(buf).Encode(p)
	if err != nil {
		log.Println("Encoding Ping:", err)
		return 0, err
	}
	n += copy(b[:], buf.Bytes())
	return n, nil
}
func (p *PlayerLogoff) Decode(b []byte) (err error) {
	if len(b) < 10 {
		return ErrLength
	}
	err = gob.NewDecoder(bytes.NewReader(b)).Decode(p)
	if err != nil && err != io.EOF {
		log.Println("Decoding:", err)
		return err
	}
	return nil
}

type PlayerMessage

type PlayerMessage struct {
	From    uint64
	To      uint64
	Message string
}

func (PlayerMessage) Type

func (p PlayerMessage) Type() types.Type

type Pong

type Pong Ping

func (Pong) Type

func (p Pong) Type() types.Type

type ServerUpdate

type ServerUpdate struct {
	T          string
	UpdateTick time.Duration
	Restart    bool
}

func (ServerUpdate) Type

func (s ServerUpdate) Type() types.Type

type StatBar

type StatBar struct {
	StatType types.Type
	Current  uint16
	Max      uint16
}

func (StatBar) CurrentMax

func (s StatBar) CurrentMax() float64

func (StatBar) Type

func (s StatBar) Type() types.Type

type StatBar64

type StatBar64 struct {
	StatType types.Type
	Current  uint64
	Max      uint64
}

func (StatBar64) CurrentMax

func (s StatBar64) CurrentMax() float64

func (StatBar64) Type

func (s StatBar64) Type() types.Type

type StatusEffect

type StatusEffect struct {
	StatusType types.Type
}

func (StatusEffect) Type

func (s StatusEffect) Type() types.Type

Directories

Path Synopsis
codec package for encoding/decoding messages over the wire this exists so that we use networking through easy-to-use interfaces, and that when this file changes
codec package for encoding/decoding messages over the wire this exists so that we use networking through easy-to-use interfaces, and that when this file changes

Jump to

Keyboard shortcuts

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