New Doodad: Anvil
* The Anvil doodad is affected by gravity and becomes dangerous when falling. If it lands on the player character, you die! If it lands on any other mobile doodad, it destroys it! It can land on solid doodads such as the Electric Trapdoor and the Crumbly Floor. It will activate a Crumbly Floor if it lands on one, and can activate buttons and switches that it passes. * JavaScript API: FailLevel(message) can be called from a doodad to kill the player character. The Anvil does this if it collides with the player while it's been falling.
This commit is contained in:
parent
4cb441dc46
commit
f8ddf512a9
|
@ -41,9 +41,6 @@ function main() {
|
||||||
// When we receive power, we reset to our original position.
|
// When we receive power, we reset to our original position.
|
||||||
var origPoint = Self.Position();
|
var origPoint = Self.Position();
|
||||||
Message.Subscribe("power", function (powered) {
|
Message.Subscribe("power", function (powered) {
|
||||||
console.error("Box received power! %+v", powered);
|
|
||||||
console.error("MoveTo: %+v", origPoint);
|
|
||||||
console.error("Keys: %+v", Object.keys(Self));
|
|
||||||
Self.MoveTo(origPoint);
|
Self.MoveTo(origPoint);
|
||||||
Self.SetVelocity(Vector(0, 0));
|
Self.SetVelocity(Vector(0, 0));
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,6 +58,10 @@ objects() {
|
||||||
cd box/
|
cd box/
|
||||||
make
|
make
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
cd crumbly-floor/
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
onoff() {
|
onoff() {
|
||||||
|
|
|
@ -2,10 +2,16 @@ ALL: build
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
|
# Start Flag
|
||||||
|
doodad convert -t "Start Flag" start-flag.png start-flag.doodad
|
||||||
|
|
||||||
|
# Exit Flag
|
||||||
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad
|
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad
|
||||||
doodad install-script exit-flag.js exit-flag.doodad
|
doodad install-script exit-flag.js exit-flag.doodad
|
||||||
|
|
||||||
doodad convert -t "Start Flag" start-flag.png start-flag.doodad
|
# Anvil
|
||||||
|
doodad convert -t "Anvil" anvil.png anvil.doodad
|
||||||
|
doodad install-script anvil.js anvil.doodad
|
||||||
|
|
||||||
for i in *.doodad; do\
|
for i in *.doodad; do\
|
||||||
doodad edit-doodad --tag "category=objects" $${i};\
|
doodad edit-doodad --tag "category=objects" $${i};\
|
||||||
|
|
51
dev-assets/doodads/objects/anvil.js
Normal file
51
dev-assets/doodads/objects/anvil.js
Normal file
|
@ -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));
|
||||||
|
});
|
||||||
|
}
|
BIN
dev-assets/doodads/objects/anvil.png
Normal file
BIN
dev-assets/doodads/objects/anvil.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 796 B |
|
@ -7,13 +7,13 @@ function main() {
|
||||||
var state = false;
|
var state = false;
|
||||||
var collide = false;
|
var collide = false;
|
||||||
|
|
||||||
Message.Subscribe("power", function(powered) {
|
Message.Subscribe("power", function (powered) {
|
||||||
state = powered;
|
state = powered;
|
||||||
showState(state);
|
showState(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.OnCollide(function(e) {
|
Events.OnCollide(function (e) {
|
||||||
if (!e.Settled) {
|
if (!e.Settled || !e.Actor.IsMobile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ function main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.OnLeave(function(e) {
|
Events.OnLeave(function (e) {
|
||||||
collide = false;
|
collide = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,11 @@ function setPoweredState(powered) {
|
||||||
Self.PlayAnimation("open", function () {
|
Self.PlayAnimation("open", function () {
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
animating = false;
|
animating = false;
|
||||||
|
|
||||||
|
// Had we lost power quickly?
|
||||||
|
if (!powerState) {
|
||||||
|
setPoweredState(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
animating = true;
|
animating = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user