rogue

package module
v0.0.0-...-6825928 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2017 License: MIT Imports: 25 Imported by: 0

README

About

rogue-like with go and phaser.io, using websockets

Install

go get -u github.com/martinlindhe/shrink-png
go get -u github.com/martinlindhe/tile-tools/...
go get -u github.com/martinlindhe/roguer

Start the server:

cd $GOROOT/src/github.com/martinlindhe/rouger
make run

Finally, visit http://localhost:3322

License

Under MIT

Documentation

Index

Constants

View Source
const (
	Minute = 1
	Hour   = Minute * 60
	Day    = Hour * 24
	Month  = Day * 30
	Season = Month * 3
	Year   = Month * 12
)

time constants

Variables

This section is empty.

Functions

func BootServer

func BootServer()

BootServer ...

func ParseSpritesetDefinition

func ParseSpritesetDefinition(defFileName string) (spritesheetSpec, error)

Types

type Action

type Action interface {
	// returns true when finished performing action
	Perform(npc *Obj) bool
}

Action ...

type Game

type Game struct {
	Island *Island
	// contains filtered or unexported fields
}

Game ...

func (*Game) ContinuePlayer

func (g *Game) ContinuePlayer(token string, socket *websocket.Conn) (*Point, string, error)

ContinuePlayer resumes a game, given a valid token

func (*Game) NewPlayer

func (g *Game) NewPlayer(name string, socket *websocket.Conn) (Point, string)

NewPlayer creates a new player

type GameTime

type GameTime struct {
	Time int64
}

GameTime is the object representing game server time

Server ticks every 3 real-world seconds. A day has 24 hours. There are 4 seasons. Each season has 3 months (90 days).

Each tick progresses the in-game time by 1 minutes, giving 60 ticks for an hour

So 1 game year = 518400 * 3 = 1555200 real seconds, or 25920 real time minutes (432 real hours, 7.2 real days).

func (*GameTime) Current

func (t *GameTime) Current() int64

Current returns the current time

func (*GameTime) DateString

func (t *GameTime) DateString() string

DateString returns "evening 19:20\nspring feb 20"

func (*GameTime) Day

func (t *GameTime) Day() int64

Day returns the day

func (*GameTime) DayOfYear

func (t *GameTime) DayOfYear() string

DayOfYear returns "19 feb in year 5"

func (*GameTime) Hour

func (t *GameTime) Hour() int64

Hour returns the hour

func (*GameTime) IsDaytime

func (t *GameTime) IsDaytime() bool

IsDaytime ...

func (*GameTime) IsNighttime

func (t *GameTime) IsNighttime() bool

IsNighttime ...

func (*GameTime) Minute

func (t *GameTime) Minute() int64

Minute returns the minute

func (*GameTime) Month

func (t *GameTime) Month() int64

Month returns the month

func (*GameTime) PartOfDay

func (t *GameTime) PartOfDay() string

PartOfDay returns "morning" or "midnight"

func (*GameTime) PassedSinceStart

func (t *GameTime) PassedSinceStart() string

PassedSinceStart describes distance of t.time to 0

func (*GameTime) Season

func (t *GameTime) Season() string

Season returns "spring" or "winter"

func (*GameTime) Set

func (t *GameTime) Set(i int64)

Set sets the current time

func (*GameTime) Tick

func (t *GameTime) Tick()

Tick progress the time

func (*GameTime) TimeOfDay

func (t *GameTime) TimeOfDay() string

TimeOfDay returns time as "19:30"

func (*GameTime) Year

func (t *GameTime) Year() int64

Year returns the year

type Island

type Island struct {
	Width     int
	Height    int
	Seed      int64 `bson:"_id"`
	Age       GameTime
	HeightMap [][]int
	Spawns    []*Obj
	Players   []*Player
	// contains filtered or unexported fields
}

Island ...

func NewIsland

func NewIsland() *Island

NewIsland inits the singelton

func (*Island) ColoredHeightMapAsImage

func (i *Island) ColoredHeightMapAsImage() image.Image

ColoredHeightMapAsImage ...

func (*Island) DescribeLocalArea

func (i *Island) DescribeLocalArea(pos Point) []LocalSpawn

DescribeLocalArea returns all spawns near pos

func (*Island) HeightsAsFlatTilemap

func (i *Island) HeightsAsFlatTilemap() []int

HeightsAsFlatTilemap ...

func (*Island) LoadSpecs

func (i *Island) LoadSpecs()

LoadSpecs loads all possible world items, NPC:s and actions

func (*Island) RandomPointAboveWater

func (i *Island) RandomPointAboveWater() Point

RandomPointAboveWater ...

func (*Island) Tick

func (i *Island) Tick()

Tick executes one tick on each spawn in the zone

type LocalSpawn

type LocalSpawn struct {
	Name   string
	Class  string
	Sprite string
	X      float64
	Y      float64
}

LocalSpawn exposes public info about the spawn to the player

type Obj

type Obj struct {
	ID       int64
	Level    int
	Age      GameTime
	Name     string
	Race     string
	Type     string
	Class    string
	Sprite   string
	Position Point
	Energy   int
	Weight   int

	XP             int
	Island         *Island
	Home           *Obj
	CurrentAction  *actionSpec
	PlannedActions []actionSpec
	Inventory      []*Obj

	// the lower value, the less hungry npc is
	Hunger    int
	Thirst    int
	Tiredness int
	Coldness  int

	// for objects
	Activated bool
}

Obj is a in-game object, such as a npc or a item

func (*Obj) Activate

func (n *Obj) Activate()

Activate ...

func (*Obj) Announce

func (o *Obj) Announce(format string, a ...interface{})

Announce to nearby players that something happened

func (*Obj) String

func (o *Obj) String() string

func (*Obj) Tick

func (o *Obj) Tick() bool

Tick until it returns false

type Player

type Player struct {
	Name   string
	Token  string
	Spawn  *Obj // points to a npc in game
	Socket *websocket.Conn
}

Player ...

type Point

type Point struct {
	X float64
	Y float64
}

Point ...

func (Point) Equals

func (p Point) Equals(p2 Point) bool

Equals returns true of p and p2 has the same coordinates

func (Point) String

func (p Point) String() string

type TexturePack

type TexturePack struct {
	Frames []textureFrame `json:"frames"`
	Meta   textureMeta    `json:"meta"`
}

TexturePack ...

func GenerateTexturePacker

func GenerateTexturePacker(spec spritesheetSpec) TexturePack

type TiledMapJSON

type TiledMapJSON struct {
	Version     int             `json:"version"`
	Width       int             `json:"width"`
	Height      int             `json:"height"`
	TileWidth   int             `json:"tilewidth"`
	TileHeight  int             `json:"tileheight"`
	Orientation string          `json:"orientation"`
	Layers      []TiledMapLayer `json:"layers"`
	TileSets    []TiledTileSet  `json:"tilesets"`
}

TiledMapJSON represents the tiled json format, recognized by phaser.io

type TiledMapLayer

type TiledMapLayer struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Data    []int  `json:"data"`
	Width   int    `json:"width"`
	Height  int    `json:"height"`
	Opacity int    `json:"opacity"`
	Visible bool   `json:"visible"`
	X       int    `json:"x"`
	Y       int    `json:"y"`
}

TiledMapLayer represents a map layer

type TiledTileSet

type TiledTileSet struct {
	FirstGid    int    `json:"firstgid"`
	Image       string `json:"image"`
	Name        string `json:"name"`
	ImageHeight int    `json:"imageheight"`
	ImageWidth  int    `json:"imagewidth"`
	Margin      int    `json:"margin"`
	Spacing     int    `json:"spacing"`
	TileHeight  int    `json:"tileheight"`
	TileWidth   int    `json:"tilewidth"`
}

TiledTileSet represents a tile set in use on the map

Directories

Path Synopsis
cmd
server command

Jump to

Keyboard shortcuts

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