Files
aego/modules/gameplay/res/docs/StateMachineGuideOriginal.aes
sanspie a46347e2c6
ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 12m19s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / checks (push) Failing after 23m57s
ci / release (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: failure
GitHub / darwin arm64 native GitHub-hosted native CI: failure
GitHub / darwin amd64 native GitHub-hosted native CI: failure
GitHub / linux amd64 native GitHub-hosted native CI: success
editor: add art studio and stage 12.5 workflows
2026-11-08 18:47:57 +03:00

67 lines
1.8 KiB
Plaintext

package demo
import (
"aego/debug"
"aego/input"
)
// Player keeps its states in a State Machine: Idle, Run and Air, each with its own hooks and colour.
script Player {
func Update(dt float) {
m := node.Get<Motion2D>()
x := 0.0
if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
x -= 1
}
if input.Down(input.KeyD) || input.Down(input.KeyRight) {
x += 1
}
m.Move(x)
if input.KeyPressed(input.KeySpace) || input.KeyPressed(input.KeyW) || input.KeyPressed(input.KeyUp) {
m.Jump()
}
if input.KeyReleased(input.KeySpace) || input.KeyReleased(input.KeyW) || input.KeyReleased(input.KeyUp) {
m.JumpReleased()
}
sm := node.Get<StateMachine>()
p := node.WorldPosition()
debug.Text(Vec2{p.X - 0.4, p.Y - 1}, sm.Current, Color{1, 1, 1, 1})
}
func UpdateIdle(dt float) {
m := node.Get<Motion2D>()
if !m.Grounded {
node.Get<StateMachine>().Go("Air")
} else if m.Velocity.X > 0.5 || m.Velocity.X < -0.5 {
node.Get<StateMachine>().Go("Run")
}
}
func UpdateRun(dt float) {
m := node.Get<Motion2D>()
if !m.Grounded {
node.Get<StateMachine>().Go("Air")
} else if m.Velocity.X < 0.5 && m.Velocity.X > -0.5 {
node.Get<StateMachine>().Go("Idle")
}
}
func UpdateAir(dt float) {
if node.Get<Motion2D>().Grounded {
node.Get<StateMachine>().Go("Idle")
}
}
func EnterIdle() {
node.Get<SpriteRenderer>().Tint = Color{0.96, 0.62, 0.04, 1}
}
func EnterRun() {
node.Get<SpriteRenderer>().Tint = Color{0.2, 0.8, 0.4, 1}
}
func EnterAir() {
node.Get<SpriteRenderer>().Tint = Color{0.3, 0.6, 1, 1}
}
}