Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Implemented player sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
eth0net committed Feb 17, 2021
1 parent 50f1252 commit 9ead0aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 5 additions & 4 deletions systems/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
)

var (
upButton string = "up"
downButton string = "down"
leftButton string = "left"
rightButton string = "right"
upButton string = "up"
downButton string = "down"
leftButton string = "left"
rightButton string = "right"
sprintButton string = "sprint"
)

// ControlComponent stores control input for player entity.
Expand Down
13 changes: 10 additions & 3 deletions systems/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
const (
AxisVertical string = "vertical"
AxisHorizontal string = "horiztonal"
speedScale float32 = 6400
speedScale float32 = 7200
)

// SpeedMessageType is the unique type identifier for SpeedMessage.
Expand Down Expand Up @@ -55,6 +55,7 @@ func (ss *SpeedSystem) New(*ecs.World) {
engo.Input.RegisterButton(downButton, engo.KeyS, engo.KeyArrowDown)
engo.Input.RegisterButton(leftButton, engo.KeyA, engo.KeyArrowLeft)
engo.Input.RegisterButton(rightButton, engo.KeyD, engo.KeyArrowRight)
engo.Input.RegisterButton(sprintButton, engo.KeyLeftShift)

engo.Input.RegisterAxis(
AxisVertical,
Expand Down Expand Up @@ -121,8 +122,14 @@ func (ss *SpeedSystem) Remove(b ecs.BasicEntity) {

// Update the SpeedSystem this frame.
func (ss *SpeedSystem) Update(dt float32) {
speedX := speedScale * dt * engo.GetGlobalScale().X
speedY := speedScale * dt * engo.GetGlobalScale().Y
speedX := speedScale * dt
speedY := speedScale * dt

if engo.Input.Button(sprintButton).Down() {
speedX *= 2
speedY *= 2
}

for _, e := range ss.entities {
e.Position.X = e.Position.X + speedX*e.SpeedComponent.X
e.Position.Y = e.Position.Y + speedY*e.SpeedComponent.Y
Expand Down

0 comments on commit 9ead0aa

Please sign in to comment.