Documentation
¶
Overview ¶
Package game defines ECS components and game logic.
Index ¶
- Constants
- func DemoLevel() *collision.TileMap
- func DemoLevelForViewport(width, height int) *collision.TileMap
- func RenderTileMap(tm *collision.TileMap) [][]rune
- func StatesMatch(a, b *WorldState, tolerance float64) bool
- type AttackState
- type Collider
- type Controller
- type Damage
- type EntityState
- type Fist
- type Gravity
- type Grounded
- type Health
- type Player
- type Position
- type Renderable
- type Sprite
- type Velocity
- type World
- func (w *World) GetPlayerPosition() (float64, float64, bool)
- func (w *World) GetRenderables() []Renderable
- func (w *World) Restore(state WorldState)
- func (w *World) SetPlayerIntent(playerID int, intents protocol.Intent)
- func (w *World) SetTileMap(tm *collision.TileMap)
- func (w *World) Snapshot() WorldState
- func (w *World) SpawnEnemy(enemyType string, x, y float64) ecs.Entity
- func (w *World) SpawnFist(x, y float64, facingRight bool, maxDistance float64, ownerID int) ecs.Entity
- func (w *World) SpawnPlayer(id int, name string, x, y float64) ecs.Entity
- func (w *World) Update()
- type WorldState
Constants ¶
const ( MaxChargeTicks = 180 // 3 seconds at 60 TPS = maximum charge MinFistDistance = 1.0 // Minimum distance (no charge) MaxFistDistance = 20.0 // Maximum distance (full charge) - 20x character width FistSpeed = 0.8 // Speed of the flying fist per tick )
Charge constants
const AttackCooldown = 15 // ~250ms at 60 TPS
AttackCooldown is how many ticks must pass before another attack can be initiated
const AttackDuration = 8
AttackDuration is how many ticks the punch animation lasts
Variables ¶
This section is empty.
Functions ¶
func DemoLevelForViewport ¶
DemoLevelForViewport creates a test level sized to fit the given viewport
func RenderTileMap ¶
RenderTileMap returns ASCII representation of the tilemap
func StatesMatch ¶
func StatesMatch(a, b *WorldState, tolerance float64) bool
StatesMatch compares two world states for equivalence within tolerance
Types ¶
type AttackState ¶
type AttackState struct {
Attacking bool // Currently in attack animation (post-release)
TicksLeft int // Animation ticks remaining
FacingRight bool // Direction of attack
// Charging state
Charging bool // Currently charging (key held)
ChargeTicks int // How long the key has been held
// Attack key tracking for edge detection
AttackWasPressed bool // Was attack key pressed last frame (for edge detection)
}
AttackState tracks attack animation state
type Controller ¶
Controller tracks which intents are active for an entity
type EntityState ¶
type EntityState struct {
Entity ecs.Entity
Position Position
Velocity Velocity
Grounded Grounded
HasPlayer bool
Player Player
HasAttack bool
Attack AttackState
}
EntityState captures the full state of an entity for snapshot/restore
type Fist ¶
type Fist struct {
StartX float64 // Starting X position
MaxDistance float64 // Maximum distance to travel
FacingRight bool // Direction of travel
OwnerID int // Player who threw the fist
}
Fist component marks a flying fist projectile
type Gravity ¶
type Gravity struct {
Scale float64 // Multiplier (1.0 = normal, 0 = no gravity)
}
Gravity component (affected by gravity)
type Renderable ¶
type Renderable struct {
X, Y float64
SpriteID string
Color uint32 // Color hint (renderers may use their atlas colors instead)
FlipX bool // Flip sprite horizontally (facing left)
}
Renderable represents an entity that can be drawn
type Sprite ¶
type Sprite struct {
ID string // Sprite identifier (e.g., "player", "slime", "platform")
Color uint32 // RGB color hint (renderers may use or ignore)
}
Sprite component (for rendering) Uses abstract sprite IDs - renderers map these to their native format
type World ¶
type World struct {
Tick uint64
ECS *ecs.World
TileMap *collision.TileMap
TileSize float64 // Size of each tile in world units
// contains filtered or unexported fields
}
World holds all game state using ark ECS
func (*World) GetPlayerPosition ¶
GetPlayerPosition returns the first player's position
func (*World) GetRenderables ¶
func (w *World) GetRenderables() []Renderable
GetRenderables returns all entities with position and sprite for rendering
func (*World) Restore ¶
func (w *World) Restore(state WorldState)
Restore applies a saved world state, rolling back to that point in time
func (*World) SetPlayerIntent ¶
SetPlayerIntent sets the input intent for all players
func (*World) SetTileMap ¶
SetTileMap sets the collision tile map
func (*World) Snapshot ¶
func (w *World) Snapshot() WorldState
Snapshot creates a complete snapshot of the current world state This captures all entity states needed for rollback and replay
func (*World) SpawnEnemy ¶
SpawnEnemy creates an enemy entity
func (*World) SpawnFist ¶
func (w *World) SpawnFist(x, y float64, facingRight bool, maxDistance float64, ownerID int) ecs.Entity
SpawnFist creates a flying fist projectile The fist spawns at chest height (0.5 units above the character's foot position)
func (*World) SpawnPlayer ¶
SpawnPlayer creates a player entity
type WorldState ¶
type WorldState struct {
Tick uint64
Entities []EntityState
Checksum uint32
}
WorldState is a complete snapshot of the game world for rollback
func (*WorldState) ToProtocolSnapshot ¶
func (state *WorldState) ToProtocolSnapshot() protocol.StateSnapshot
ToProtocolSnapshot converts a WorldState to a protocol.StateSnapshot for network transmission