33 lines
929 B
Plaintext
33 lines
929 B
Plaintext
package demo
|
|
|
|
import (
|
|
"aego/debug"
|
|
"aego/input"
|
|
)
|
|
|
|
// Player respawns after a fall or when R is pressed.
|
|
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()
|
|
}
|
|
if input.KeyPressed(input.KeyR) {
|
|
node.Get<Respawn>().Trigger()
|
|
}
|
|
p := node.WorldPosition()
|
|
debug.Text(Vec2{p.X - 1, p.Y - 1}, "R: respawn", Color{0.8, 0.8, 0.8, 1})
|
|
}
|
|
}
|