doodle/dev-assets/doodads/azulian/azulian.js
Noah Petherbridge d28745f89e Mobile Enemy Doodad Test
* Add a Red Azulian as a test for mobile enemies.
  * Its A.I. has it walk back and forth, changing directions when it
    comes up against an obstacle for a few moments.
  * It plays walking animations and can trigger collision events with
    other Doodads, such as the Electric Door and Trapdoor.
* Move Gravity responsibility to the doodad scripts themselves.
  * Call `Self.SetGravity(true)` to opt the Doodad in to gravity.
  * The canvas.Loop() adds gravity to any doodad that has it enabled.
2019-05-06 16:30:45 -07:00

38 lines
827 B
JavaScript

function main() {
log.Info("Azulian '%s' initialized!", Self.Doodad.Title);
var playerSpeed = 12;
var gravity = 4;
var Vx = Vy = 0;
var animating = false;
var animStart = animEnd = 0;
var animFrame = animStart;
Self.SetGravity(true);
Self.AddAnimation("walk-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]);
Self.AddAnimation("walk-right", 100, ["blu-wr1", "blu-wr2", "blu-wr3", "blu-wr4"]);
Events.OnKeypress(function(ev) {
Vx = 0;
Vy = 0;
if (ev.Right.Now) {
if (!Self.IsAnimating()) {
Self.PlayAnimation("walk-right", null);
}
Vx = playerSpeed;
} else if (ev.Left.Now) {
if (!Self.IsAnimating()) {
Self.PlayAnimation("walk-left", null);
}
Vx = -playerSpeed;
} else {
Self.StopAnimation();
animating = false;
}
// Self.SetVelocity(Point(Vx, Vy));
})
}