types

package
v0.0.0-...-219ab8e Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollisionSpaceTagPlayer   string = "player"
	CollisionSpaceTagNPC      string = "npc"
	CollisionSpaceTagLevel    string = "level"
	CollisionSpaceTagPlatform string = "platform"
	CollisionSpaceTagLadder   string = "ladder"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectPlayerEvent

type ConnectPlayerEvent struct {
	ClientID           uint32
	CharacterID        int32
	CharacterName      string
	CharacterPosition  kinematic.Vector
	CharacterFlipH     bool
	CharacterHitpoints int16
}

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 NewGameState(collisionSpace *resolv.Space) *GameState

func (*GameState) AddNPC

func (g *GameState) AddNPC(id uint32, state *NPCState)

func (*GameState) AddPlayer

func (g *GameState) AddPlayer(id uint32, state *PlayerState)

func (*GameState) Copy

func (g *GameState) Copy() *GameState

func (*GameState) RemoveNPC

func (g *GameState) RemoveNPC(id uint32)

func (*GameState) RemovePlayer

func (g *GameState) RemovePlayer(id uint32)

func (*GameState) SetTimestamp

func (g *GameState) SetTimestamp(timestamp int64)

type NPCAnimation

type NPCAnimation uint8
const (
	NPCAnimationIdle NPCAnimation = iota
	NPCAnimationWalk
	NPCAnimationDead
	NPCAnimationAttack1
	NPCAnimationAttack2
	NPCAnimationAttack3
)

type NPCAttack

type NPCAttack uint8
const (
	NPCAttack1 NPCAttack = iota
	NPCAttack2
	NPCAttack3
)

type NPCMode

type NPCMode uint8
const (
	NPCModeIdle NPCMode = iota
	NPCModeWander
	NPCModeFollow
)

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 NewNPCState(id uint32, spawnPosition kinematic.Vector, wanderRangeMinX, wanderRangeMaxX float64, flip bool) *NPCState

func (*NPCState) Copy

func (n *NPCState) Copy() *NPCState

func (*NPCState) DecrementRespawnTime

func (n *NPCState) DecrementRespawnTime(deltaTime float64)

func (*NPCState) Despawn

func (n *NPCState) Despawn()

func (*NPCState) Equals

func (n *NPCState) Equals(other *NPCState) bool

func (*NPCState) IsDead

func (n *NPCState) IsDead() bool

func (*NPCState) IsFollowing

func (n *NPCState) IsFollowing() bool

func (*NPCState) IsWandering

func (n *NPCState) IsWandering() bool

func (*NPCState) RespawnTime

func (n *NPCState) RespawnTime() float64

func (*NPCState) Spawn

func (n *NPCState) Spawn()

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 (n *NPCState) TakeDamage(damage int16)

func (*NPCState) Update

func (n *NPCState) Update(deltaTime float64) (changed bool)

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 (n *NPCState) UpdateAttack(deltaTime float64)

func (*NPCState) UpdateFlipH

func (n *NPCState) UpdateFlipH()

func (*NPCState) UpdateFollowing

func (n *NPCState) UpdateFollowing()

func (*NPCState) UpdateRespawn

func (n *NPCState) UpdateRespawn(deltaTime float64)

func (*NPCState) UpdateWandering

func (n *NPCState) UpdateWandering(deltaTime float64)

func (*NPCState) UpdateXPosition

func (n *NPCState) UpdateXPosition(deltaTime float64)

func (*NPCState) UpdateYPosition

func (n *NPCState) UpdateYPosition(deltaTime float64)

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 NewPlayerState(characterID int32, name string, position kinematic.Vector, flipH bool, hitpoints int16) *PlayerState

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

Jump to

Keyboard shortcuts

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