Files
aego/modules/animation/res/docs/try/Animator.aes
sanspie c8d45b6ff5
ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m59s
ci / release (push) Successful in 9m16s
ci-platforms / windows amd64 smoke (push) Skipped
ci / checks (push) Successful in 8m18s
ci-platforms / darwin amd64 smoke (push) Skipped
docs: the Animator demo jumps and hits; the web demo caption names J to attack
The built-in platformer controller plays engine/anim/jump in Jump and engine/anim/hit in Hit; before, both states had no clip and nothing showed.
The Animator try scene jumps with Space (Grounded false in the air) instead of toggling the parameter.
2026-10-27 23:09:31 +03:00

61 lines
1.3 KiB
Plaintext

package demo
import (
"aego/debug"
"aego/input"
)
// Runner walks with A/D on the built-in platformer controller; Space jumps (Grounded is false in the air), J triggers Hit.
script Runner {
var vy float
var floor float
var air bool
func Update(dt float) {
a := node.Get<Animator>()
dir := 0.0
if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
dir -= 1
}
if input.Down(input.KeyD) || input.Down(input.KeyRight) {
dir += 1
}
speed := dir
if speed < 0 {
speed = -speed
node.Get<SpriteRenderer>().FlipX = true
} else if speed > 0 {
node.Get<SpriteRenderer>().FlipX = false
}
a.SetFloat("Speed", speed * 3)
p := node.Position()
if !air {
floor = p.Y
if input.KeyPressed(input.KeySpace) {
air = true
vy = -7
a.SetBool("Grounded", false)
}
}
if air {
vy += 20 * dt
p.Y += vy * dt
if p.Y >= floor {
p.Y = floor
air = false
a.SetBool("Grounded", true)
}
}
if input.KeyPressed(input.KeyJ) {
a.SetTrigger("Attack")
}
node.SetPosition(Vec2{p.X + dir * 3 * dt, p.Y})
label := a.State
if a.Blending {
label = label + " (blending)"
}
debug.Text(Vec2{p.X - 2, p.Y - 1.4}, label + " " + string(a.Progress), Color{0.85, 0.85, 0.85, 1})
debug.Text(Vec2{-4.5, 2}, "A/D walk Space jump J hit", Color{0.6, 0.6, 0.6, 1})
}
}