player

package
v1.1.112 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PlayerWidth is the hitbox width of the player.
	// Actual width is 14 (one extra pixel to left and right).
	PlayerWidth = 14 + 2*PlayerOffsetDX
	// PlayerHeight is the hitbox height of the player.
	// Actual height is 30 (three extra pixels at the top).
	PlayerHeight = 30 + PlayerOffsetDY + PlayerFlippedOffsetDY
	// PlayerEyeDX is the X coordinate of the player's eye.
	PlayerEyeDX = 5
	// PlayerEyeDY is the Y coordinate of the player's eye.
	PlayerEyeDY = 3
	// PlayerOffsetDX is the player's render offset.
	PlayerOffsetDX = -2
	// PlayerOffsetDY is the player's render offset.
	PlayerOffsetDY = -4
	// PlayerFlippedOffsetDY is the player's render offset.
	PlayerFlippedOffsetDY = -1
	// PlayerBorderPixels is the size of the player's black border.
	PlayerBorderPixels = 1

	// LookTiles is how many tiles the player can look up/down.
	LookDistance = level.TileSize * 4

	// Nice run/jump speed.
	MaxGroundSpeed = 160 * constants.SubPixelScale / engine.GameTPS
	GroundAccel    = GroundFriction + AirAccel
	GroundFriction = 640 * constants.SubPixelScale / engine.GameTPS / engine.GameTPS

	// Air max speed is lower than ground control, but same forward accel.
	MaxAirSpeed = 120 * constants.SubPixelScale / engine.GameTPS
	AirAccel    = 480 * constants.SubPixelScale / engine.GameTPS / engine.GameTPS

	// We want 4.5 tiles high jumps, i.e. 72px high jumps (plus something).
	// Jump shall take 1 second.
	// Yields:
	// v0^2 / (2 * g) = 72
	// 2 v0 / g = 1
	// ->
	// v0 = 288
	// g = 576
	// Note: assuming 1px=6cm, this is actually 17.3m/s and 3.5x earth gravity.
	JumpVelocity = 288 * constants.SubPixelScale / engine.GameTPS
	MaxSpeed     = 2 * level.TileSize * constants.SubPixelScale

	// Scale noise by speed.
	NoiseMinSpeed = 384 * constants.SubPixelScale / engine.GameTPS
	NoiseMaxSpeed = MaxSpeed
	NoisePower    = 2.0

	// Scale hitwall sound by speed.
	HitWallMinSpeed = 40 * constants.SubPixelScale / engine.GameTPS
	HitWallMaxSpeed = 160 * constants.SubPixelScale / engine.GameTPS

	// We want at least 19px high jumps so we can be sure a jump moves at least 2 tiles up.
	JumpExtraGravity = 72*constants.Gravity/19 - constants.Gravity

	// Number of frames to allow jumping after leaving ground. This is an extra 1/30 sec.
	// 7 allows reliable walking over 2 tile gaps.
	// 1 allows reliable walking over 1 tile gaps.
	// 0 allows some walking over 1 tile gaps.
	ExtraGroundFrames = 4

	// Animation tuning.
	AnimGroundSpeed = 20 * constants.SubPixelScale / engine.GameTPS
)

Player height is 30 px. So 30 px ~ 180 cm. Gravity is 9.81 m/s^2 = 163.5 px/s^2.

Variables

This section is empty.

Functions

This section is empty.

Types

type Player

type Player struct {
	mixins.Physics
	World           *engine.World
	Entity          *engine.Entity
	PersistentState map[string]string

	AirFrames      int // Number of frames since last leaving ground.
	LastGroundPos  m.Pos
	Jumping        bool
	JumpingUp      bool
	LookUp         bool
	LookDown       bool
	Respawning     bool
	WasOnGround    bool
	PrevVelocity   m.Delta
	VVVVVV         bool
	JustSpawned    bool
	Goal           *engine.Entity
	EasterEggCount int

	Anim animation.State

	JumpSound       *sound.Sound
	VVVVVVSound     *sound.Sound
	LandSound       *sound.Sound
	HitHeadSound    *sound.Sound
	HitWallSound    *sound.Sound
	GotAbilitySound *sound.Sound
}

func (*Player) ActionPressed

func (p *Player) ActionPressed() bool

func (*Player) Despawn

func (p *Player) Despawn()

func (*Player) EyePos

func (p *Player) EyePos() m.Pos

EyePos returns the position the player eye is at.

func (*Player) GiveAbility

func (p *Player) GiveAbility(name, text string)

func (*Player) HasAbility

func (p *Player) HasAbility(name string) bool

func (*Player) LookPos

func (p *Player) LookPos() m.Pos

LookPos returns the position the player is focusing at.

func (*Player) Respawned

func (p *Player) Respawned()

Respawned informs the player that the world moved/respawned it.

func (*Player) SetGoal

func (p *Player) SetGoal(goal *engine.Entity)

func (*Player) SetVVVVVV

func (p *Player) SetVVVVVV(vvvvvv bool, up m.Delta, factor float64)

func (*Player) SetVelocityForJump

func (p *Player) SetVelocityForJump(velocity m.Delta)

func (*Player) Spawn

func (p *Player) Spawn(w *engine.World, sp *level.SpawnableProps, e *engine.Entity) error

func (*Player) Touch

func (p *Player) Touch(other *engine.Entity)

func (*Player) Update

func (p *Player) Update()

Jump to

Keyboard shortcuts

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