surge

package module
v0.0.0-...-9aa04a4 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2019 License: MIT Imports: 18 Imported by: 0

README

surge

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultcharacterSounds = struct {
		Jump,
		Land assets.ID
	}{
		Jump: assets.SoundAdventurerJump,
		Land: assets.SoundAdventurerLand,
	}
)

Functions

func BridgemanCharacterModel

func BridgemanCharacterModel() *characterModel

func HeraldCharacterModel

func HeraldCharacterModel() *characterModel

func SprenCharacterModel

func SprenCharacterModel() *characterModel

func SurgebinderCharacterModel

func SurgebinderCharacterModel() *characterModel

Types

type BaseAirborneState

type BaseAirborneState struct {
	BaseState
	Animation       *graphics.SpriteAnimation
	MoveLeftButton  pixelgl.Button
	MoveRightButton pixelgl.Button
}

func (*BaseAirborneState) Enter

func (s *BaseAirborneState) Enter(c Character)

func (*BaseAirborneState) HandleCollision

func (s *BaseAirborneState) HandleCollision(c Character, event physics.CollisionEvent)

func (*BaseAirborneState) HandleInput

func (s *BaseAirborneState) HandleInput(gtx GameContext, c Character)

type BaseCharacter

type BaseCharacter struct {
	Graphics GraphicsComponent
	// contains filtered or unexported fields
}

func (BaseCharacter) Body

func (c BaseCharacter) Body() *physics.Body

func (BaseCharacter) Direction

func (c BaseCharacter) Direction() physics.Direction

func (*BaseCharacter) Jump

func (c *BaseCharacter) Jump()

NOTE: this pattern is actually error prone: concrete character types should have to implement Character methods directly so as to avoid the programmer forgetting to do so, which might lead to e.g. double-jumping because the concrete character does not have a Jump method to put them into the airborne state.

func (*BaseCharacter) KeepMovingLeft

func (c *BaseCharacter) KeepMovingLeft()

func (*BaseCharacter) KeepMovingRight

func (c *BaseCharacter) KeepMovingRight()

func (*BaseCharacter) Land

func (c *BaseCharacter) Land()

func (*BaseCharacter) OnAttacked

func (c *BaseCharacter) OnAttacked(gtx GameContext)

func (*BaseCharacter) SetAnimation

func (c *BaseCharacter) SetAnimation(a *graphics.SpriteAnimation)

func (*BaseCharacter) SetState

func (c *BaseCharacter) SetState(state State)

func (*BaseCharacter) Slow

func (c *BaseCharacter) Slow()

func (BaseCharacter) State

func (c BaseCharacter) State() State

func (*BaseCharacter) Team

func (c *BaseCharacter) Team() string

func (*BaseCharacter) Update

func (c *BaseCharacter) Update(_ GameContext)

func (*BaseCharacter) WalkLeft

func (c *BaseCharacter) WalkLeft()

func (*BaseCharacter) WalkRight

func (c *BaseCharacter) WalkRight()

type BaseIdleState

type BaseIdleState struct {
	BaseState
	Animation       *graphics.SpriteAnimation
	JumpButton      pixelgl.Button
	MoveLeftButton  pixelgl.Button
	MoveRightButton pixelgl.Button
}

func (*BaseIdleState) Enter

func (s *BaseIdleState) Enter(c Character)

func (*BaseIdleState) HandleInput

func (s *BaseIdleState) HandleInput(gtx GameContext, c Character)

type BaseState

type BaseState struct{}

BaseState implements all state methods so derived state classes don't have to.

func (BaseState) Enter

func (s BaseState) Enter(_ Character)

func (BaseState) Exit

func (s BaseState) Exit(_ Character)

func (BaseState) HandleAirborne

func (s BaseState) HandleAirborne(_ Character)

func (BaseState) HandleCollision

func (s BaseState) HandleCollision(_ Character, __ physics.CollisionEvent)

func (BaseState) HandleInput

func (s BaseState) HandleInput(_ GameContext, __ Character)

func (BaseState) Update

func (s BaseState) Update(_ GameContext, __ Character)

type BaseWalkingState

type BaseWalkingState struct {
	BaseState
	Animation       *graphics.SpriteAnimation
	JumpButton      pixelgl.Button
	MoveLeftButton  pixelgl.Button
	MoveRightButton pixelgl.Button
}

func (*BaseWalkingState) Enter

func (s *BaseWalkingState) Enter(c Character)

func (*BaseWalkingState) HandleInput

func (s *BaseWalkingState) HandleInput(gtx GameContext, c Character)

type Bridgeman

type Bridgeman struct {
	*BaseCharacter
	// contains filtered or unexported fields
}

func NewBridgeman

func NewBridgeman(_ context.Context, c *BaseCharacter) *Bridgeman

func (*Bridgeman) DropoffSphere

func (b *Bridgeman) DropoffSphere(gtx GameContext, sphere *Sphere, stockpile *SphereStockpile)

func (*Bridgeman) Jump

func (b *Bridgeman) Jump()

func (*Bridgeman) Land

func (b *Bridgeman) Land()

func (*Bridgeman) OnAttacked

func (b *Bridgeman) OnAttacked(gtx GameContext)

func (*Bridgeman) PickupSphere

func (b *Bridgeman) PickupSphere(gtx GameContext, sphere *Sphere)

func (*Bridgeman) Slow

func (b *Bridgeman) Slow()

func (*Bridgeman) Update

func (b *Bridgeman) Update(gtx GameContext)

Overrides BaseCharacter.Update.

func (*Bridgeman) WalkLeft

func (b *Bridgeman) WalkLeft()

func (*Bridgeman) WalkRight

func (b *Bridgeman) WalkRight()

type BridgemanDropoffSphereState

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

func (BridgemanDropoffSphereState) Update

type BridgemanPickupSphereState

type BridgemanPickupSphereState struct{}

func (BridgemanPickupSphereState) Update

type BridgemanSphereState

type BridgemanSphereState interface {
	Update(GameContext, *Bridgeman)
}

type BridgemanState

type BridgemanState struct{ State }

func (*BridgemanState) HandleAirborne

func (s *BridgemanState) HandleAirborne(c Character)

type Character

type Character interface {
	Updater
	Body() *physics.Body
	SetAnimation(*graphics.SpriteAnimation)
	Team() string

	Jump()
	KeepMovingLeft()
	KeepMovingRight()
	Land()
	OnAttacked(GameContext)
	SetState(State)
	State() State
	Slow()
	WalkLeft()
	WalkRight()
}

type CharacterSpawnTimer

type CharacterSpawnTimer struct {
	C         Character
	Now       func() time.Time
	SpawnX    float64
	SpawnY    float64
	SpawnTime time.Time
}

func (*CharacterSpawnTimer) Update

func (t *CharacterSpawnTimer) Update(gtx GameContext) (done bool)

type CharacterSystem

type CharacterSystem struct {
	Now          func() time.Time
	RespawnDelay time.Duration
	// contains filtered or unexported fields
}

func (*CharacterSystem) AddCharacter

func (s *CharacterSystem) AddCharacter(c Character)

func (CharacterSystem) Characters

func (s CharacterSystem) Characters() []Character

func (*CharacterSystem) RemoveCharacter

func (s *CharacterSystem) RemoveCharacter(c Character)

func (*CharacterSystem) ScheduleSpawn

func (s *CharacterSystem) ScheduleSpawn(gtx GameContext, c Character)

func (*CharacterSystem) Update

func (s *CharacterSystem) Update(gtx GameContext)

type CharacterType

type CharacterType = string
const (
	SurgebinderCharacterType CharacterType = "surgebinder"
	BridgemanCharacterType   CharacterType = "bridgeman"
	SprenCharacterType       CharacterType = "spren"
)

type Controller

type Controller interface {
	JustPressed(pixelgl.Button) bool
	Pressed(pixelgl.Button) bool
}

type Game

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

func NewGame

func NewGame(o GameOptions) *Game

func (*Game) CharacterSystem

func (g *Game) CharacterSystem() *CharacterSystem

func (*Game) Controller

func (g *Game) Controller() Controller

func (*Game) LashingSystem

func (g *Game) LashingSystem() *LashingSystem

func (*Game) Map

func (g *Game) Map() *Map

func (*Game) ObjectSystem

func (g *Game) ObjectSystem() *ObjectSystem

func (*Game) PhysicsContext

func (g *Game) PhysicsContext() *physics.PhysicsContext

func (*Game) Run

func (g *Game) Run(ctx context.Context) error

func (*Game) SphereStockpiles

func (g *Game) SphereStockpiles() []*SphereStockpile

type GameContext

type GameContext interface {
	Controller() Controller
	PhysicsContext() *physics.PhysicsContext
	CharacterSystem() *CharacterSystem
	LashingSystem() *LashingSystem
	ObjectSystem() *ObjectSystem
	SphereStockpiles() []*SphereStockpile
	Map() *Map
}

type GameOptions

type GameOptions struct {
	FPS int
	Map *Map
}

type GraphicsComponent

type GraphicsComponent struct {
	DrawBoundingBox bool
	Canvas          graphics.Canvas
	Animation       *graphics.SpriteAnimation
}

func (*GraphicsComponent) Update

func (c *GraphicsComponent) Update(char *BaseCharacter)

type Herald

type Herald struct {
	*BaseCharacter
	// contains filtered or unexported fields
}

func NewHerald

func NewHerald(ctx context.Context, c *BaseCharacter) *Herald

func (*Herald) Attack

func (h *Herald) Attack()

func (*Herald) Land

func (h *Herald) Land()

func (*Herald) OnAttacked

func (h *Herald) OnAttacked(gtx GameContext)

func (*Herald) SetState

func (h *Herald) SetState(state State)

func (*Herald) Slow

func (h *Herald) Slow()

func (*Herald) State

func (h *Herald) State() State

func (*Herald) Update

func (h *Herald) Update(gtx GameContext)

func (*Herald) WalkLeft

func (h *Herald) WalkLeft()

func (*Herald) WalkRight

func (h *Herald) WalkRight()

type HeraldAttackingState

type HeraldAttackingState struct {
	BaseState
	Animation *graphics.SpriteAnimation
}

func NewHeraldAttackingState

func NewHeraldAttackingState() *HeraldAttackingState

func (*HeraldAttackingState) Enter

func (s *HeraldAttackingState) Enter(c Character)

func (*HeraldAttackingState) HandleInput

func (s *HeraldAttackingState) HandleInput(_ GameContext, __ Character)

func (*HeraldAttackingState) Update

func (s *HeraldAttackingState) Update(gtx GameContext, c Character)

type HeraldGroundedState

type HeraldGroundedState struct{ State }

func (*HeraldGroundedState) HandleAirborne

func (s *HeraldGroundedState) HandleAirborne(c Character)

type HeraldNotAttackingState

type HeraldNotAttackingState struct{ State }

func (*HeraldNotAttackingState) HandleInput

func (s *HeraldNotAttackingState) HandleInput(gtx GameContext, c Character)

type Lashable

type Lashable interface {
	Body() *physics.Body
}

Lashable is an object that can be Lashed.

type Lasher

type Lasher interface {
	Body() *physics.Body
	Team() string
	Stormlight() int
	SetStormlight(int)
}

Lasher is an object that can use Lashings.

type Lashing

type Lashing struct {
	// The character that activated the Lash ability.
	Lasher Lasher

	// The target of this lashing.
	//
	// If null, a target will be selected automatically.
	Target Lashable

	// The direction to lash the target.
	Direction physics.Direction
}

Lashing forcibly changes the direction of a character's gravity.

type LashingSystem

type LashingSystem struct {
	StormlightCost int
	// contains filtered or unexported fields
}

func (*LashingSystem) Activate

func (s *LashingSystem) Activate(gtx GameContext, lashing Lashing)

func (*LashingSystem) Update

func (s *LashingSystem) Update(_ GameContext)

type Map

type Map struct {
	// The locations where surgespheres spawn on this map.
	SphereSpawnLocations []*SphereSpawnLocation

	// The locations where Surgespheres may be stored.
	//
	// Each team on this map should have a single SphereStockpileArea in this
	// list.
	SphereStockpileAreas []*SphereStockpileArea

	// The set of player spawn locations.
	PlayerSpawnLocations []*PlayerSpawnLocation

	// The rectangles that form the collision locations with map terrain.
	CollisionBoxes []*physics.Rect

	// A sprite to render as the background image for this map.
	BackgroundSprite *pixel.Sprite

	WidthInPixels  int
	HeightInPixels int
}

Map represents a Surge game world.

func LoadMap

func LoadMap(ctx context.Context, mapID assets.ID, decoder MapDecoder) *Map

func (*Map) AddPlayerSpawnLocation

func (m *Map) AddPlayerSpawnLocation(l *PlayerSpawnLocation)

func (*Map) AddSphereSlotLocation

func (m *Map) AddSphereSlotLocation(s *SphereSlotLocation)

func (*Map) AddSphereSpawnLocation

func (m *Map) AddSphereSpawnLocation(s *SphereSpawnLocation)

func (*Map) AddSphereStockpileArea

func (m *Map) AddSphereStockpileArea(a *SphereStockpileArea)

func (Map) Draw

func (m Map) Draw(canvas graphics.Canvas)

type MapDecoder

type MapDecoder func(path string) *Map

type Object

type Object interface {
	Updater
	Bounds() *physics.Rect
}

type ObjectSystem

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

func (*ObjectSystem) AddObject

func (s *ObjectSystem) AddObject(object Object)

func (*ObjectSystem) Objects

func (s *ObjectSystem) Objects() []Object

func (*ObjectSystem) RemoveObject

func (s *ObjectSystem) RemoveObject(object Object)

func (*ObjectSystem) Update

func (s *ObjectSystem) Update(gtx GameContext)

type PlayerSpawnLocation

type PlayerSpawnLocation struct {
	CharacterType CharacterType
	Team          string
	PlayerID      string
	X, Y          float64
}

type Sounds

type Sounds struct {
	Jump,
	Land assets.ID
}

type Sphere

type Sphere struct {
	Graphics SphereGraphicsComponent
	Body     *physics.Body
	IsFrozen bool
	// contains filtered or unexported fields
}

func (*Sphere) AddPickupSubscriber

func (c *Sphere) AddPickupSubscriber(subscriber SpherePickupSubscriber)

AddPickupSubscriber registers subscriber to run the first time this sphere is picked up.

func (Sphere) Bounds

func (c Sphere) Bounds() *physics.Rect

func (*Sphere) HandlePickup

func (c *Sphere) HandlePickup(gtx GameContext)

func (*Sphere) Update

func (c *Sphere) Update(gtx GameContext)

type SphereFactory

type SphereFactory struct {
	Canvas graphics.Canvas
}

func (SphereFactory) Create

func (f SphereFactory) Create(x, y float64) *Sphere

type SphereGraphicsComponent

type SphereGraphicsComponent struct {
	Animation *graphics.SpriteAnimation
	Canvas    graphics.Canvas
}

func (*SphereGraphicsComponent) Update

func (c *SphereGraphicsComponent) Update(sphere *Sphere)

type SpherePickupSubscriber

type SpherePickupSubscriber func()

type SphereSlot

type SphereSlot struct {
	X, Y float64
	// contains filtered or unexported fields
}

func (*SphereSlot) Insert

func (s *SphereSlot) Insert(gtx GameContext, sphere *Sphere)

func (SphereSlot) IsOpen

func (s SphereSlot) IsOpen() bool

type SphereSlotLocation

type SphereSlotLocation struct {
	Stockpile string
	X, Y      float64
}

type SphereSpawn

type SphereSpawn struct {
	X, Y          float64
	Now           func() time.Time
	SphereFactory *SphereFactory
	SpawnDelay    time.Duration
	// contains filtered or unexported fields
}

SphereSpawn is a location on the map where spheres repeatedly spawn.

func (*SphereSpawn) ScheduleSpawn

func (s *SphereSpawn) ScheduleSpawn()

func (*SphereSpawn) Update

func (s *SphereSpawn) Update(gtx GameContext)

type SphereSpawnLocation

type SphereSpawnLocation struct {
	X, Y float64
}

type SphereStockpile

type SphereStockpile struct {
	Team string
	// contains filtered or unexported fields
}

SphereStockpile is a where a team's spheres are stored.

func NewSphereStockpile

func NewSphereStockpile(team string, bounds *physics.Rect, slots []*SphereSlot) *SphereStockpile

func (*SphereStockpile) AddSphere

func (s *SphereStockpile) AddSphere(gtx GameContext, sphere *Sphere) bool

func (*SphereStockpile) Bounds

func (s *SphereStockpile) Bounds() *physics.Rect

type SphereStockpileArea

type SphereStockpileArea struct {
	Team                string
	X, Y, Width, Height float64
	Slots               []*SphereSlotLocation
}

func (*SphereStockpileArea) Bounds

func (s *SphereStockpileArea) Bounds() *physics.Rect

type Spren

type Spren struct{ *BaseCharacter }

func NewSpren

func NewSpren(ctx context.Context, c *BaseCharacter) *Spren

func (*Spren) Land

func (s *Spren) Land()

func (*Spren) OnAttacked

func (s *Spren) OnAttacked(gtx GameContext)

func (*Spren) Slow

func (s *Spren) Slow()

func (*Spren) Update

func (s *Spren) Update(gtx GameContext)

func (*Spren) WalkLeft

func (s *Spren) WalkLeft()

func (*Spren) WalkRight

func (s *Spren) WalkRight()

type SprenAirborneState

type SprenAirborneState struct{ *BaseAirborneState }

func (*SprenAirborneState) HandleInput

func (s *SprenAirborneState) HandleInput(gtx GameContext, c Character)

type SprenState

type SprenState struct{ State }

func (*SprenState) HandleAirborne

func (s *SprenState) HandleAirborne(c Character)

type State

type State interface {
	Enter(Character)
	Exit(Character)
	HandleAirborne(Character)
	HandleInput(GameContext, Character)
	HandleCollision(Character, physics.CollisionEvent)
	Update(GameContext, Character)
}

func NewBridgemanAirborneState

func NewBridgemanAirborneState() State

func NewBridgemanIdleState

func NewBridgemanIdleState() State

func NewBridgemanWalkingState

func NewBridgemanWalkingState() State

func NewHeraldAirborneState

func NewHeraldAirborneState() State

func NewHeraldIdleState

func NewHeraldIdleState() State

func NewHeraldWalkingState

func NewHeraldWalkingState() State

func NewSprenAirborneState

func NewSprenAirborneState() State

func NewSprenIdleState

func NewSprenIdleState() State

func NewSprenWalkingState

func NewSprenWalkingState() State

func NewSurgebinderAirborneState

func NewSurgebinderAirborneState() State

func NewSurgebinderIdleState

func NewSurgebinderIdleState() State

func NewSurgebinderWalkingState

func NewSurgebinderWalkingState() State

type StateStack

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

func (StateStack) At

func (s StateStack) At(i int) State

func (StateStack) Dump

func (s StateStack) Dump(format func(State) string)

func (StateStack) IsEmpty

func (s StateStack) IsEmpty() bool

func (*StateStack) Pop

func (s *StateStack) Pop() (State, bool)

func (*StateStack) Push

func (s *StateStack) Push(state State)

func (StateStack) Size

func (s StateStack) Size() int

func (StateStack) Top

func (s StateStack) Top() State

type Surgebinder

type Surgebinder struct {
	*BaseCharacter
	// contains filtered or unexported fields
}

Surgebinder is a BaseCharacter that can use stormlight to affect themselves and other players.

The surgebinder, can 'lash' themselves in any cardinal direction, as well as other players. They have finite amount of stormlight, and convert back into Bridgemen when their stormlight runs out.

func NewSurgebinder

func NewSurgebinder(ctx context.Context, c *BaseCharacter) *Surgebinder

func (*Surgebinder) Jump

func (s *Surgebinder) Jump()

func (*Surgebinder) Land

func (s *Surgebinder) Land()

func (*Surgebinder) OnAttacked

func (s *Surgebinder) OnAttacked(gtx GameContext)

func (*Surgebinder) SetStormlight

func (s *Surgebinder) SetStormlight(value int)

func (*Surgebinder) Slow

func (s *Surgebinder) Slow()

func (*Surgebinder) Stormlight

func (s *Surgebinder) Stormlight() int

func (*Surgebinder) Update

func (s *Surgebinder) Update(gtx GameContext)

Overrides BaseCharacter.Updater

func (*Surgebinder) WalkLeft

func (s *Surgebinder) WalkLeft()

func (*Surgebinder) WalkRight

func (s *Surgebinder) WalkRight()

type SurgebinderState

type SurgebinderState struct{ State }

SurgebinderState allows the surgebinder to lash objects and other players. They may do this while in any state.

func (*SurgebinderState) HandleInput

func (s *SurgebinderState) HandleInput(gtx GameContext, c Character)

type Updater

type Updater interface {
	Update(GameContext)
}

type WindowCanvas

type WindowCanvas struct {
	*pixelgl.Window
}

func (WindowCanvas) Center

func (w WindowCanvas) Center() pixel.Vec

func (WindowCanvas) DrawRect

func (w WindowCanvas) DrawRect(rect *physics.Rect)

func (WindowCanvas) DrawSprite

func (w WindowCanvas) DrawSprite(sprite *pixel.Sprite, pos pixel.Matrix)

func (WindowCanvas) DrawVertex

func (w WindowCanvas) DrawVertex(vec pixel.Vec, rgb pixel.RGBA)

Directories

Path Synopsis
cmd
run
Package physics defines physical components and transformations.
Package physics defines physical components and transformations.

Jump to

Keyboard shortcuts

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