From 08ea9efc82675168772f7f3af51253f7c49da0a0 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 11 Aug 2021 20:40:31 -0700 Subject: [PATCH] Link Start Flags to Change Characters New feature: link a Start Flag to another doodad in your level and you will play as that doodad instead of Boy. All Creatures are designed to be playable. Playing as "other" doodads leads to interesting effects, like not being able to activate buttons, switches, or warp doors and not having an inventory to pick up keys. The Anvil is fun: it can destroy other mobile doodads by jumping on them. If the actor does not specify that it has gravity, the gameplay starts in antigravity mode. This will be the vast majority of non-mobile doodads and the Bird. Other changes: * The Blue and Red Azulians now share a doodad script. * The Azulians AI is still to walk back and forth, pickup keys and press buttons. The Blue Azulian walks slower than the red one. * The Blue Azulian is no longer hidden from the doodads list. * Actor UUID values in levels are now V1 UUIDs (time-ordered). This will help to reliably resolve conflicts in draw order of overlapping doodads (newest added to level wins). * Link Tool: clicking on a pair of already-linked doodads will now unlink them, so you don't have to delete one to delete the link. * Actor Tool: deleting an actor immediately calls PruneLinks() to clean up any links that the deleted doodad might have. --- dev-assets/doodads/azulian/Makefile | 4 +- dev-assets/doodads/azulian/azulian-red.js | 3 + dev-assets/doodads/azulian/azulian.js | 70 +++++++++++++++++------ dev-assets/doodads/build.sh | 2 +- dev-assets/doodads/objects/Makefile | 1 + dev-assets/doodads/objects/start-flag.js | 11 ++++ 6 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 dev-assets/doodads/objects/start-flag.js 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(); + } +}