New Doodad: Box

The Box can be pushed around by the player or other mobile doodads.

It is affected by gravity and can be pushed off ledges.

If the player gets under a box they can bump it up with their head.
This commit is contained in:
Noah 2021-07-18 21:22:53 -07:00
parent 5d4fe7b99a
commit 89c1e58e69
6 changed files with 57 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,51 @@
// Pushable Box.
var speed = 4;
var size = 75;
function main() {
Self.SetMobile(true);
Self.SetGravity(true);
Self.SetHitbox(0, 0, size, size);
Events.OnCollide(function (e) {
if (e.Actor.IsMobile() && e.InHitbox) {
var overlap = e.Overlap;
if (overlap.Y === 0) {
// Standing on top, ignore.
return false;
} else if (overlap.Y === size) {
// From the bottom, boop it up.
Self.SetVelocity(Vector(0, -speed * 2))
}
// If touching from the sides, slide away.
if (overlap.X === 0) {
Self.SetVelocity(Vector(speed, 0))
} else if (overlap.X === size) {
Self.SetVelocity(Vector(-speed, 0))
}
return false;
}
});
Events.OnLeave(function (e) {
Self.SetVelocity(Vector(0, 0));
});
// Start animation on a loop.
animate();
}
function animate() {
Self.AddAnimation("animate", 100, [0, 1, 2, 3, 2, 1]);
var running = false;
setInterval(function () {
if (!running) {
running = true;
Self.PlayAnimation("animate", function () {
running = false;
})
}
}, 100);
}

View File

@ -127,6 +127,12 @@ objects() {
doodad install-script crumbly-floor.js crumbly-floor.doodad doodad install-script crumbly-floor.js crumbly-floor.doodad
cp *.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/
cd ../box
doodad convert -t "Box" box-1.png box-2.png box-3.png box-4.png box.doodad
doodad install-script box.js box.doodad
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }