diff --git a/dev-assets/doodads/azulian/Makefile b/dev-assets/doodads/azulian/Makefile index 20e7aa5..05dae89 100644 --- a/dev-assets/doodads/azulian/Makefile +++ b/dev-assets/doodads/azulian/Makefile @@ -4,11 +4,13 @@ ALL: build build: doodad convert -t "Blue Azulian" blu-front.png blu-back.png \ blu-wr{1,2,3,4}.png blu-wl{1,2,3,4}.png azu-blu.doodad + doodad edit-doodad --tag "color=blue" azu-blu.doodad doodad install-script azulian.js azu-blu.doodad doodad convert -t "Red Azulian" red-front.png red-back.png \ red-wr{1,2,3,4}.png red-wl{1,2,3,4}.png azu-red.doodad - doodad install-script azulian-red.js azu-red.doodad + doodad edit-doodad --tag "color=red" azu-red.doodad + doodad install-script azulian.js azu-red.doodad # Tag the category for these doodads for i in *.doodad; do\ diff --git a/dev-assets/doodads/azulian/azulian-red.js b/dev-assets/doodads/azulian/azulian-red.js index f42d92d..aeb5f91 100644 --- a/dev-assets/doodads/azulian/azulian-red.js +++ b/dev-assets/doodads/azulian/azulian-red.js @@ -1,3 +1,6 @@ +// Azulian (Red) +// DEPRECATED: they both share azulian.js now. + function main() { var playerSpeed = 4; var gravity = 4; diff --git a/dev-assets/doodads/azulian/azulian.js b/dev-assets/doodads/azulian/azulian.js index 3aa7637..54db87e 100644 --- a/dev-assets/doodads/azulian/azulian.js +++ b/dev-assets/doodads/azulian/azulian.js @@ -1,38 +1,74 @@ -function main() { - var playerSpeed = 12; - var gravity = 4; - var Vx = Vy = 0; +// Azulian (Red and Blue) +var playerSpeed = 12, + animating = false, + direction = "right"; - var animating = false; - var animStart = animEnd = 0; - var animFrame = animStart; +function setupAnimations(color) { + var left = color === 'blue' ? 'blu-wl' : 'red-wl', + right = color === 'blue' ? 'blu-wr' : 'red-wr', + leftFrames = [left + '1', left + '2', left + '3', left + '4'], + rightFrames = [right + '1', right + '2', right + '3', right + '4']; + + Self.AddAnimation("walk-left", 100, leftFrames); + Self.AddAnimation("walk-right", 100, rightFrames); +} + +function main() { + var color = Self.GetTag("color"); + playerSpeed = color === 'blue' ? 2 : 4; Self.SetMobile(true); Self.SetGravity(true); Self.SetInventory(true); - Self.SetHitbox(7, 4, 17, 28); - 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"]); + Self.SetHitbox(0, 0, 24, 32); + setupAnimations(color); + if (Self.IsPlayer()) { + return playerControls(); + } + + // A.I. pattern: walks back and forth, turning around + // when it meets resistance. + + // Sample our X position every few frames and detect if we've hit a solid wall. + var sampleTick = 0; + var sampleRate = 5; + var lastSampledX = 0; + + setInterval(function () { + if (sampleTick % sampleRate === 0) { + var curX = Self.Position().X; + var delta = Math.abs(curX - lastSampledX); + if (delta < 5) { + direction = direction === "right" ? "left" : "right"; + } + lastSampledX = curX; + } + sampleTick++; + + var Vx = parseFloat(playerSpeed * (direction === "left" ? -1 : 1)); + Self.SetVelocity(Vector(Vx, 0.0)); + + if (!Self.IsAnimating()) { + Self.PlayAnimation("walk-" + direction, null); + } + }, 100); +} + +function playerControls() { + // Note: player speed is controlled by the engine. Events.OnKeypress(function (ev) { - Vx = 0; - Vy = 0; - if (ev.Right) { if (!Self.IsAnimating()) { Self.PlayAnimation("walk-right", null); } - Vx = playerSpeed; } else if (ev.Left) { if (!Self.IsAnimating()) { Self.PlayAnimation("walk-left", null); } - Vx = -playerSpeed; } else { Self.StopAnimation(); animating = false; } - - // Self.SetVelocity(Point(Vx, Vy)); }) } diff --git a/dev-assets/doodads/build.sh b/dev-assets/doodads/build.sh index 9c99564..d115872 100755 --- a/dev-assets/doodads/build.sh +++ b/dev-assets/doodads/build.sh @@ -91,5 +91,5 @@ objects onoff warpdoor doodad edit-doodad -quiet -lock -author "Noah" ../../assets/doodads/*.doodad -doodad edit-doodad -hide ../../assets/doodads/azu-blu.doodad +doodad edit-doodad ../../assets/doodads/azu-blu.doodad doodad edit-doodad -hide ../../assets/doodads/boy.doodad diff --git a/dev-assets/doodads/objects/Makefile b/dev-assets/doodads/objects/Makefile index c56b8ed..86e33ce 100644 --- a/dev-assets/doodads/objects/Makefile +++ b/dev-assets/doodads/objects/Makefile @@ -4,6 +4,7 @@ ALL: build build: # Start Flag doodad convert -t "Start Flag" start-flag.png start-flag.doodad + doodad install-script start-flag.js start-flag.doodad # Exit Flag doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad diff --git a/dev-assets/doodads/objects/start-flag.js b/dev-assets/doodads/objects/start-flag.js new file mode 100644 index 0000000..dc84a77 --- /dev/null +++ b/dev-assets/doodads/objects/start-flag.js @@ -0,0 +1,11 @@ +// Start Flag. +function main() { + Self.SetHitbox(22 + 16, 16, 75 - 16, 86); + + // Linking a doodad to the Start Flag sets the + // player character. Destroy the original doodads. + var links = Self.GetLinks(); + for (var i = 0; i < links.length; i++) { + links[i].Destroy(); + } +}