Documentation
¶
Index ¶
- Constants
- type ConnectPlayerEvent
- type DisconnectPlayerEvent
- type GameState
- type NPCAnimation
- type NPCAttack
- type NPCMode
- type NPCState
- func (n *NPCState) Copy() *NPCState
- func (n *NPCState) DecrementRespawnTime(deltaTime float64)
- func (n *NPCState) Despawn()
- func (n *NPCState) Equals(other *NPCState) bool
- func (n *NPCState) IsDead() bool
- func (n *NPCState) IsFollowing() bool
- func (n *NPCState) IsWandering() bool
- func (n *NPCState) RespawnTime() float64
- func (n *NPCState) Spawn()
- func (n *NPCState) StartFollowing(target *PlayerState)
- func (n *NPCState) StartWandering()
- func (n *NPCState) StopFollowing()
- func (n *NPCState) StopWandering()
- func (n *NPCState) TakeDamage(damage int16)
- func (n *NPCState) Update(deltaTime float64) (changed bool)
- func (n *NPCState) UpdateAnimation()
- func (n *NPCState) UpdateAttack(deltaTime float64)
- func (n *NPCState) UpdateFlipH()
- func (n *NPCState) UpdateFollowing()
- func (n *NPCState) UpdateRespawn(deltaTime float64)
- func (n *NPCState) UpdateWandering(deltaTime float64)
- func (n *NPCState) UpdateXPosition(deltaTime float64)
- func (n *NPCState) UpdateYPosition(deltaTime float64)
- type PlayerAnimation
- type PlayerAttack
- type PlayerState
- func (p *PlayerState) ApplyInput(clientPlayerUpdate *messages.ClientPlayerUpdate) (changed bool)
- func (p *PlayerState) Copy() *PlayerState
- func (p *PlayerState) Equals(other *PlayerState) bool
- func (p *PlayerState) IsDead() bool
- func (p *PlayerState) Respawn(position kinematic.Vector)
- func (p *PlayerState) TakeDamage(damage int16)
- func (p *PlayerState) UpdateAnimation()
- func (p *PlayerState) UpdateAttack(clientPlayerUpdate *messages.ClientPlayerUpdate)
- func (p *PlayerState) UpdateFlipH(clientPlayerUpdate *messages.ClientPlayerUpdate)
- func (p *PlayerState) UpdateLadderState(clientPlayerUpdate *messages.ClientPlayerUpdate)
- func (p *PlayerState) UpdateRespawn(clientPlayerUpdate *messages.ClientPlayerUpdate)
- func (p *PlayerState) UpdateXPosition(clientPlayerUpdate *messages.ClientPlayerUpdate)
- func (p *PlayerState) UpdateYPosition(clientPlayerUpdate *messages.ClientPlayerUpdate)
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectPlayerEvent ¶
type DisconnectPlayerEvent ¶
type DisconnectPlayerEvent struct {
ClientID uint32
}
type GameState ¶
type GameState struct { // Timestamp is the time at which the game state was generated Timestamp int64 // Players maps client IDs to player states Players map[uint32]*PlayerState // NPCs maps enemy IDs to NPC states NPCs map[uint32]*NPCState // CollisionSpace is a resolv.Space used for collision detection CollisionSpace *resolv.Space }
func NewGameState ¶
func (*GameState) AddPlayer ¶
func (g *GameState) AddPlayer(id uint32, state *PlayerState)
func (*GameState) RemovePlayer ¶
func (*GameState) SetTimestamp ¶
type NPCAnimation ¶
type NPCAnimation uint8
const ( NPCAnimationIdle NPCAnimation = iota NPCAnimationWalk NPCAnimationDead NPCAnimationAttack1 NPCAnimationAttack2 NPCAnimationAttack3 )
type NPCState ¶
type NPCState struct { ID uint32 SpawnPosition kinematic.Vector SpawnFlip bool WanderRangeMin kinematic.Vector WanderRangeMax kinematic.Vector Position kinematic.Vector Velocity kinematic.Vector Object *resolv.Object FlipH bool IsOnGround bool Animation NPCAnimation AnimationSequence uint8 ResetAnimation bool Hitpoints int16 IdleTimeLeft float64 WanderTarget *kinematic.Vector FollowTarget *PlayerState IsInAttackRange bool IsAttacking bool CurrentAttack NPCAttack AttackTimeLeft float64 IsAttackHitting bool DidAttackHit bool // contains filtered or unexported fields }
func NewNPCState ¶
func (*NPCState) DecrementRespawnTime ¶
func (*NPCState) IsFollowing ¶
func (*NPCState) IsWandering ¶
func (*NPCState) RespawnTime ¶
func (*NPCState) StartFollowing ¶
func (n *NPCState) StartFollowing(target *PlayerState)
func (*NPCState) StartWandering ¶
func (n *NPCState) StartWandering()
func (*NPCState) StopFollowing ¶
func (n *NPCState) StopFollowing()
func (*NPCState) StopWandering ¶
func (n *NPCState) StopWandering()
func (*NPCState) TakeDamage ¶
func (*NPCState) Update ¶
Update updates the NPC state based on the current state and the time passed and returns whether the state has changed
func (*NPCState) UpdateAnimation ¶
func (n *NPCState) UpdateAnimation()
func (*NPCState) UpdateAttack ¶
func (*NPCState) UpdateFlipH ¶
func (n *NPCState) UpdateFlipH()
func (*NPCState) UpdateFollowing ¶
func (n *NPCState) UpdateFollowing()
func (*NPCState) UpdateRespawn ¶
func (*NPCState) UpdateWandering ¶
func (*NPCState) UpdateXPosition ¶
func (*NPCState) UpdateYPosition ¶
type PlayerAnimation ¶
type PlayerAnimation uint8
const ( PlayerAnimationIdle PlayerAnimation = iota PlayerAnimationRun PlayerAnimationJump PlayerAnimationLadderIdle PlayerAnimationLadderClimb PlayerAnimationFall PlayerAnimationAttack1 PlayerAnimationAttack2 PlayerAnimationAttack3 PlayerAnimationDead )
type PlayerAttack ¶
type PlayerAttack uint8
const ( PlayerAttack1 PlayerAttack = iota PlayerAttack2 PlayerAttack3 )
type PlayerState ¶
type PlayerState struct { LastProcessedTimestamp int64 CharacterID int32 Name string Position kinematic.Vector Velocity kinematic.Vector Object *resolv.Object FlipH bool IsOnGround bool IsOnLadder bool LadderPosition *kinematic.Vector DismountedLadderPosition *kinematic.Vector IsAttacking bool CurrentAttack PlayerAttack AttackTimeLeft float64 IsAttackHitting bool DidAttackHit bool Animation PlayerAnimation AnimationSequence uint8 ResetAnimation bool Hitpoints int16 }
func NewPlayerState ¶
func (*PlayerState) ApplyInput ¶
func (p *PlayerState) ApplyInput(clientPlayerUpdate *messages.ClientPlayerUpdate) (changed bool)
ApplyInput updates the player's state based on the client's input and returns whether the state has changed
func (*PlayerState) Copy ¶
func (p *PlayerState) Copy() *PlayerState
Copy returns a copy of the player state with an empty object reference
func (*PlayerState) Equals ¶
func (p *PlayerState) Equals(other *PlayerState) bool
Equals returns true if the player state is equal to another player state. It only compares the fields that are serialized to the client.
func (*PlayerState) IsDead ¶
func (p *PlayerState) IsDead() bool
IsDead returns true if the player's hitpoints are less than or equal to zero
func (*PlayerState) Respawn ¶
func (p *PlayerState) Respawn(position kinematic.Vector)
Respawns the player at the given position
func (*PlayerState) TakeDamage ¶
func (p *PlayerState) TakeDamage(damage int16)
TakeDamage reduces the player's hitpoints by the given amount
func (*PlayerState) UpdateAnimation ¶
func (p *PlayerState) UpdateAnimation()
UpdateAnimation updates the player's animation state
func (*PlayerState) UpdateAttack ¶
func (p *PlayerState) UpdateAttack(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateAttack updates the player's attack state
func (*PlayerState) UpdateFlipH ¶
func (p *PlayerState) UpdateFlipH(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateFlipH updates the player's flip state based on the client's input
func (*PlayerState) UpdateLadderState ¶
func (p *PlayerState) UpdateLadderState(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateLadderState updates the player's ladder state based on the client's input
func (*PlayerState) UpdateRespawn ¶
func (p *PlayerState) UpdateRespawn(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateRespawn updates the player's respawn state
func (*PlayerState) UpdateXPosition ¶
func (p *PlayerState) UpdateXPosition(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateXPosition updates the player's X position based on the client's input
func (*PlayerState) UpdateYPosition ¶
func (p *PlayerState) UpdateYPosition(clientPlayerUpdate *messages.ClientPlayerUpdate)
UpdateYPosition updates the player's Y position based on the client's input