ci-platforms / darwin amd64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 15m28s
ci / release (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
ci / checks (push) Successful in 7m47s
86 lines
1.7 KiB
Plaintext
86 lines
1.7 KiB
Plaintext
package player
|
|
|
|
import (
|
|
"aego/anim"
|
|
"aego/input"
|
|
"aego/math"
|
|
"aego/settings"
|
|
)
|
|
|
|
// Hero moves with the left stick or WASD and lunges with its Sword towards the right stick, the mouse or the way it walks.
|
|
script Hero {
|
|
@export
|
|
var Sword NodeRef
|
|
|
|
@export
|
|
var Torch NodeRef
|
|
|
|
@export
|
|
var StepDust NodeRef
|
|
|
|
@export(min=0)
|
|
var Reach float = 0.8
|
|
|
|
var facing Vec2 = Vec2{1, 0}
|
|
var mouse Vec2
|
|
var useMouse bool
|
|
var hit int
|
|
var footstep int
|
|
|
|
func Ready() {
|
|
mouse = input.MousePos()
|
|
hit = anim.EventID("Hit")
|
|
footstep = anim.EventID("Footstep")
|
|
}
|
|
|
|
func FixedUpdate(dt float) {
|
|
move := Vec2{input.Axis("MoveX"), input.Axis("MoveY")}
|
|
node.Get<Motion2D>().MoveDir(move)
|
|
a := node.Get<Animator>()
|
|
a.SetFloat("Speed", math.Length(move))
|
|
a.RootScale = facing
|
|
if input.Pressed("Attack") {
|
|
a.SetTrigger("Attack")
|
|
}
|
|
}
|
|
|
|
func OnAnimEvent(id int, payload float) {
|
|
if id == footstep && StepDust != nil && StepDust.IsAlive() {
|
|
StepDust.Get<ParticleSystem2D>().Burst(2)
|
|
}
|
|
if id == hit {
|
|
Sword.Get<Hitbox2D>().Pulse()
|
|
}
|
|
}
|
|
|
|
func Update(dt float) {
|
|
move := Vec2{input.Axis("MoveX"), input.Axis("MoveY")}
|
|
aim := Vec2{input.Axis("AimX"), input.Axis("AimY")}
|
|
p := input.MousePos()
|
|
if math.Dist(p, mouse) > 2 {
|
|
mouse = p
|
|
useMouse = true
|
|
}
|
|
if math.Length(aim) > 0.3 {
|
|
facing = math.Normalize(aim)
|
|
useMouse = false
|
|
} else if useMouse {
|
|
to := input.MouseWorld() - node.WorldPosition()
|
|
if math.Length(to) > 0.2 {
|
|
facing = math.Normalize(to)
|
|
}
|
|
} else if math.Length(move) > 0.1 {
|
|
facing = math.Normalize(move)
|
|
}
|
|
Sword.SetPosition(facing * Reach)
|
|
angle := math.Angle(facing)
|
|
Sword.SetRotation(angle)
|
|
if Torch != nil {
|
|
Torch.SetRotation(angle)
|
|
}
|
|
if input.Pressed("Pause") {
|
|
settings.OpenView()
|
|
}
|
|
}
|
|
}
|