diff --git a/README.md b/README.md index ee27f3f..ff81076 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This repository includes some example doodads for Sketchy Maze. You can learn from their scripts or use them as a base for your own custom doodads. -![Warp Door](warp-door/door-1.png) ![Character](character/stand-right.png) +![Warp Door](warp-door/door-1.png) ![Character](character/stand-right.png) ![Anvil](anvil/anvil.png) All of these doodads are built from PNG images using the `doodad` program that comes with the game. Check your guidebook @@ -18,6 +18,8 @@ example for the doodad commands used. built-in creatures. * [**Warp Door**](warp-door/): create your own compatible Warp Door that you can link to the built-in doors. +* [**Anvil**](anvil/): the harmless doodad that becomes dangerous + while falling. To do: diff --git a/anvil/Makefile b/anvil/Makefile new file mode 100644 index 0000000..2c685ea --- /dev/null +++ b/anvil/Makefile @@ -0,0 +1,5 @@ +ALL: build + +.PHONY: build +build: + ./build.sh \ No newline at end of file diff --git a/anvil/README.md b/anvil/README.md new file mode 100644 index 0000000..fb4a35c --- /dev/null +++ b/anvil/README.md @@ -0,0 +1,7 @@ +# Example Anvil + +![Example Anvil](anvil.png) + +This is basically the **Anvil** from the game. It has no solid +collision, it is affected by gravity, and it is dangerous when +falling. \ No newline at end of file diff --git a/anvil/anvil.js b/anvil/anvil.js new file mode 100644 index 0000000..2359bca --- /dev/null +++ b/anvil/anvil.js @@ -0,0 +1,51 @@ +// Anvil +var falling = false; + +function main() { + // Note: doodad is not "solid" but hurts if it falls on you. + Self.SetHitbox(0, 0, 48, 25); + Self.SetMobile(true); + Self.SetGravity(true); + + // Monitor our Y position to tell if we've been falling. + var lastPoint = Self.Position(); + setInterval(function () { + var nowAt = Self.Position(); + if (nowAt.Y > lastPoint.Y) { + falling = true; + } else { + falling = false; + } + lastPoint = nowAt; + }, 100); + + Events.OnCollide(function (e) { + if (!e.Settled) { + return; + } + + // Were we falling? + if (falling) { + if (e.InHitbox) { + if (e.Actor.IsPlayer()) { + // Fatal to the player. + Sound.Play("crumbly-break.wav"); + FailLevel("Watch out for anvils!"); + return; + } + else if (e.Actor.IsMobile()) { + // Destroy mobile doodads. + Sound.Play("crumbly-break.wav"); + e.Actor.Destroy(); + } + } + } + }); + + // When we receive power, we reset to our original position. + var origPoint = Self.Position(); + Message.Subscribe("power", function (powered) { + Self.MoveTo(origPoint); + Self.SetVelocity(Vector(0, 0)); + }); +} diff --git a/anvil/anvil.png b/anvil/anvil.png new file mode 100644 index 0000000..d379c11 Binary files /dev/null and b/anvil/anvil.png differ diff --git a/anvil/build.sh b/anvil/build.sh new file mode 100755 index 0000000..d0f6566 --- /dev/null +++ b/anvil/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +doodad convert -t "Example Anvil" anvil.png example-anvil.doodad +doodad edit-doodad --tag "category=objects" example-anvil.doodad +doodad install-script anvil.js example-anvil.doodad \ No newline at end of file