* 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.
Этот коммит содержится в:
Noah 2021-08-08 21:54:37 -07:00
родитель 4cb441dc46
Коммит f8ddf512a9
7 изменённых файлов: 71 добавлений и 8 удалений

Просмотреть файл

@ -41,9 +41,6 @@ function main() {
// When we receive power, we reset to our original position.
var origPoint = Self.Position();
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.SetVelocity(Vector(0, 0));
});

Просмотреть файл

@ -58,6 +58,10 @@ objects() {
cd box/
make
cd ..
cd crumbly-floor/
make
cd ..
}
onoff() {

Просмотреть файл

@ -2,10 +2,16 @@ ALL: build
.PHONY: 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 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\
doodad edit-doodad --tag "category=objects" $${i};\

51
dev-assets/doodads/objects/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));
});
}

Двоичные данные
dev-assets/doodads/objects/anvil.png Обычный файл

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 796 B

Просмотреть файл

@ -13,7 +13,7 @@ function main() {
});
Events.OnCollide(function (e) {
if (!e.Settled) {
if (!e.Settled || !e.Actor.IsMobile()) {
return;
}

Просмотреть файл

@ -49,6 +49,11 @@ function setPoweredState(powered) {
Self.PlayAnimation("open", function () {
isOpen = true;
animating = false;
// Had we lost power quickly?
if (!powerState) {
setPoweredState(false);
}
});
} else {
animating = true;