game

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionDispatcher

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

ActionDispatcher is in charge of dispatching actions to the application dispatcher

func NewActionDispatcher

func NewActionDispatcher(d *flux.Dispatcher, s *store.Store, wsSendFn func(a *action.Action), l *slog.Logger) *ActionDispatcher

NewActionDispatcher initializes the action dispatcher with the give dispatcher

func (*ActionDispatcher) CameraZoom

func (ac *ActionDispatcher) CameraZoom(d int)

CameraZoom zooms the camera the direction 'd'

func (*ActionDispatcher) CloseTowerMenu

func (ac *ActionDispatcher) CloseTowerMenu()

CloseTowerMenu when a tower menu needs to be closed

func (*ActionDispatcher) CursorMove

func (ac *ActionDispatcher) CursorMove(x, y int)

CursorMove dispatches an action of moving the Cursor to the new x,y coordinates

func (*ActionDispatcher) DeselectTower

func (ac *ActionDispatcher) DeselectTower(t string)

DeselectTower cleans the current selected tower

func (*ActionDispatcher) Dispatch

func (ac *ActionDispatcher) Dispatch(a *action.Action)

Dispatch is a helper to access to the internal dispatch directly with an action. This should only be used from the WS Handler to forward server actions directly

func (*ActionDispatcher) GoHome

func (ac *ActionDispatcher) GoHome()

GoHome will move the camera to the current player home line

func (*ActionDispatcher) IncomeTick

func (ac *ActionDispatcher) IncomeTick()

IncomeTick a new tick for the income

func (*ActionDispatcher) OpenTowerMenu

func (ac *ActionDispatcher) OpenTowerMenu(tid string)

OpenTowerMenu when a tower is clicked and the menu of the tower is displayed

func (*ActionDispatcher) PlaceTower

func (ac *ActionDispatcher) PlaceTower(t, pid string, x, y int)

PlaceTower places the tower 't' on the position X and Y of the player pid

func (*ActionDispatcher) RemovePlayer

func (ac *ActionDispatcher) RemovePlayer(pid string)

func (*ActionDispatcher) RemoveTower

func (ac *ActionDispatcher) RemoveTower(pid, tid string)

RemoveTower removes the tower tid

func (*ActionDispatcher) SelectTower

func (ac *ActionDispatcher) SelectTower(t string, x, y int)

SelectTower selects the tower 't' on the position x, y

func (*ActionDispatcher) SelectedTowerInvalid

func (ac *ActionDispatcher) SelectedTowerInvalid(i bool)

SelectTower selects the tower 't' on the position x, y

func (*ActionDispatcher) SummonUnit

func (ac *ActionDispatcher) SummonUnit(unit, pid string, plid, clid int)

SummonUnit summons the 'unit' from the player id 'pid' to the line 'plid' and with the current line id 'clid'

func (*ActionDispatcher) TPS

func (ac *ActionDispatcher) TPS()

TPS is the call for every TPS event

func (*ActionDispatcher) ToggleStats

func (ac *ActionDispatcher) ToggleStats()

func (*ActionDispatcher) UpdateTower added in v1.1.0

func (ac *ActionDispatcher) UpdateTower(pid, tid, tt string)

GoHome will move the camera to the current player home line

func (*ActionDispatcher) UpdateUnit added in v1.1.0

func (ac *ActionDispatcher) UpdateUnit(pid, ut string)

type CameraState

type CameraState struct {
	utils.Object
	Zoom               float64
	LastCursorPosition utils.Object
}

CameraState is the store data on the Camera

type CameraStore

type CameraStore struct {
	*flux.ReduceStore

	Store *store.Store
	// contains filtered or unexported fields
}

CameraStore is in charge of what it's seen on the screen, it also tracks the position of the cursor and the wheel scroll

func NewCameraStore

func NewCameraStore(d *flux.Dispatcher, s *store.Store, l *slog.Logger, w, h int) *CameraStore

NewCameraStore creates a new CameraState linked to the Dispatcher d with the Game g and with width w and height h which is the size of the viewport

func (*CameraStore) Draw

func (cs *CameraStore) Draw(screen *ebiten.Image)

func (*CameraStore) Reduce

func (cs *CameraStore) Reduce(state, a interface{}) interface{}

func (*CameraStore) Update

func (cs *CameraStore) Update() error

type Game

type Game struct {
	Store *store.Store

	Camera *CameraStore
	HUD    *HUDStore
	Lines  *Lines

	Map *Map

	Logger *slog.Logger
}

func New

func New(s *store.Store, ad *ActionDispatcher, l *slog.Logger) *Game

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

func (*Game) Update

func (g *Game) Update() error

type HUDState

type HUDState struct {
	SelectedTower *SelectedTower
	OpenTowerMenu *store.Tower

	LastCursorPosition utils.Object

	ShowStats bool
}

HUDState stores the HUD state

type HUDStore

type HUDStore struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

HUDStore is in charge of keeping track of all the elements on the player HUD that are static and always seen

func NewHUDStore

func NewHUDStore(d *flux.Dispatcher, g *Game) (*HUDStore, error)

NewHUDStore creates a new HUDStore with the Dispatcher d and the Game g

func (*HUDStore) Draw

func (hs *HUDStore) Draw(screen *ebiten.Image)

func (*HUDStore) Reduce

func (hs *HUDStore) Reduce(state, a interface{}) interface{}

func (*HUDStore) Update

func (hs *HUDStore) Update() error

type ImagesCache

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

ImagesCache is a simple cache for all the images, so instead of running 'ebiten.NewImageFromImage' we just ran it once and reuse it all the time

func (*ImagesCache) Get

func (i *ImagesCache) Get(key string) *ebiten.Image

Get will return the image from 'key', if it does not exists a 'nil' will be returned

type Lines

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

func NewLines

func NewLines(g *Game) (*Lines, error)

func (*Lines) Draw

func (ls *Lines) Draw(screen *ebiten.Image)

func (*Lines) DrawTower

func (ls *Lines) DrawTower(screen *ebiten.Image, c *CameraStore, t *store.Tower)

func (*Lines) DrawTowerHelath added in v1.2.0

func (ls *Lines) DrawTowerHelath(screen *ebiten.Image, c *CameraStore, t *store.Tower)

func (*Lines) DrawUnit

func (ls *Lines) DrawUnit(screen *ebiten.Image, c *CameraStore, u *store.Unit)

func (*Lines) Update

func (ls *Lines) Update() error

type Map

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

func NewMap

func NewMap(g *Game) *Map

func (*Map) Draw

func (m *Map) Draw(screen *ebiten.Image)

func (*Map) Update

func (m *Map) Update() error

type SelectedTower

type SelectedTower struct {
	store.Tower

	Invalid bool
}

Jump to

Keyboard shortcuts

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