Noah Petherbridge
3 years ago
6 changed files with 71 additions and 1 deletions
@ -0,0 +1,5 @@ |
|||
ALL: build |
|||
|
|||
.PHONY: build |
|||
build: |
|||
./build.sh |
@ -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. |
@ -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)); |
|||
}); |
|||
} |
After Width: | Height: | Size: 7.4 KiB |
@ -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 |
Loading…
Reference in new issue