Doodads: Electric Trapdoor and Resettable Box

* New doodad: Electric Trapdoor. It is a horizontal version of the
  Electric Door. Opens while powered by a button or a switch and closes
  when it loses power.
* The Box doodad will reset to its original location if it receives a
  power signal from a linked Button or Switch. So for box pushing
  puzzles you can add a reset button in case the boxes get stuck.
* Refactored the Doodad build scripts into many Makefiles for easier
  iteration (don't need to compile ALL doodads to test one).

Updates to the JavaScript API for doodads:

* Self.MoveTo(Point) is now available to set the actor's position in
  world coordinates.
This commit is contained in:
Noah 2021-08-08 20:10:42 -07:00
parent fb15577b33
commit 4cb441dc46
20 changed files with 287 additions and 140 deletions

View File

@ -0,0 +1,18 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Blue Azulian" blu-front.png blu-back.png \
blu-wr{1,2,3,4}.png blu-wl{1,2,3,4}.png azu-blu.doodad
doodad install-script azulian.js azu-blu.doodad
doodad convert -t "Red Azulian" red-front.png red-back.png \
red-wr{1,2,3,4}.png red-wl{1,2,3,4}.png azu-red.doodad
doodad install-script azulian-red.js azu-red.doodad
# Tag the category for these doodads
for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,14 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Bird (red)" left-1.png left-2.png right-1.png right-2.png \
dive-left.png dive-right.png bird-red.doodad
doodad install-script bird.js bird-red.doodad
# Tag the category for these doodads
for i in *.doodad; do\
doodad edit-doodad --tag "category=creatures" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,13 @@
ALL: build
.PHONY: build
build:
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
for i in *.doodad; do \
doodad edit-doodad --tag "category=objects" $${i}; \
done
cp *.doodad ../../../assets/doodads/

View File

@ -38,6 +38,16 @@ function main() {
Self.SetVelocity(Vector(0, 0)); Self.SetVelocity(Vector(0, 0));
}); });
// 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));
});
// Start animation on a loop. // Start animation on a loop.
animate(); animate();
} }

View File

@ -0,0 +1,13 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Boy" stand-right.png stand-left.png \
walk-right-1.png walk-right-2.png walk-right-3.png \
walk-left-1.png walk-left-2.png walk-left-3.png \
boy.doodad
doodad install-script boy.js boy.doodad
doodad edit-doodad --tag "category=creatures" boy.doodad
cp *.doodad ../../../assets/doodads/

View File

@ -10,191 +10,65 @@ mkdir -p ../../assets/doodads
boy() { boy() {
cd boy/ cd boy/
make
doodad convert -t "Boy" stand-right.png stand-left.png \
walk-right-1.png walk-right-2.png walk-right-3.png \
walk-left-1.png walk-left-2.png walk-left-3.png \
boy.doodad
doodad install-script boy.js boy.doodad
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }
buttons() { buttons() {
cd buttons/ cd buttons/
make
doodad convert -t "Sticky Button" sticky1.png sticky2.png button-sticky.doodad
doodad install-script sticky.js button-sticky.doodad
doodad convert -t "Button" button1.png button2.png button.doodad
doodad install-script button.js button.doodad
doodad convert -t "Button Type B" typeB1.png typeB2.png button-typeB.doodad
doodad install-script button.js button-typeB.doodad
# Tag the category for these doodads
for i in *.doodad; do doodad edit-doodad --tag "category=gizmos" $i; done
cp button*.doodad ../../../assets/doodads/
cd .. cd ..
} }
switches() { switches() {
cd switches/ cd switches/
make
doodad convert -t "Switch" switch-off.png switch-on.png switch.doodad
doodad convert -t "Floor Switch" down-off.png down-on.png switch-down.doodad
doodad convert -t "Left Switch" left-off.png left-on.png switch-left.doodad
doodad convert -t "Right Switch" right-off.png right-on.png switch-right.doodad
doodad install-script switch.js switch.doodad
doodad install-script switch.js switch-down.doodad
doodad install-script switch.js switch-left.doodad
doodad install-script switch.js switch-right.doodad
# Tag the category for these doodads
for i in *.doodad; do doodad edit-doodad --tag "category=gizmos" $i; done
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }
doors() { doors() {
cd doors/ cd doors/
./build.sh make
cd .. cd ..
} }
trapdoors() { trapdoors() {
cd trapdoors/ cd trapdoors/
make
doodad convert -t "Trapdoor" down{1,2,3,4}.png trapdoor-down.doodad
doodad convert -t "Trapdoor Left" left{1,2,3,4}.png trapdoor-left.doodad
doodad convert -t "Trapdoor Right" right{1,2,3,4}.png trapdoor-right.doodad
doodad convert -t "Trapdoor Up" up{1,2,3,4}.png trapdoor-up.doodad
doodad install-script trapdoor.js trapdoor-down.doodad
doodad install-script trapdoor.js trapdoor-left.doodad
doodad install-script trapdoor.js trapdoor-right.doodad
doodad install-script trapdoor.js trapdoor-up.doodad
doodad edit-doodad -q --tag direction=down trapdoor-down.doodad
doodad edit-doodad -q --tag direction=left trapdoor-left.doodad
doodad edit-doodad -q --tag direction=right trapdoor-right.doodad
doodad edit-doodad -q --tag direction=up trapdoor-up.doodad
# Tag the category for these doodads
for i in *.doodad; do doodad edit-doodad --tag "category=doors" $i; done
cp trapdoor-*.doodad ../../../assets/doodads/
cd .. cd ..
} }
azulians() { azulians() {
cd azulian/ cd azulian/
make
doodad convert -t "Blue Azulian" blu-front.png blu-back.png \
blu-wr{1,2,3,4}.png blu-wl{1,2,3,4}.png azu-blu.doodad
doodad install-script azulian.js azu-blu.doodad
doodad convert -t "Red Azulian" red-front.png red-back.png \
red-wr{1,2,3,4}.png red-wl{1,2,3,4}.png azu-red.doodad
doodad install-script azulian-red.js azu-red.doodad
# Tag the category for these doodads
for i in *.doodad; do doodad edit-doodad --tag "category=creatures" $i; done
cp azu-*.doodad ../../../assets/doodads/
cd .. cd ..
} }
mobs() { mobs() {
cd bird/ cd bird/
make
doodad convert -t "Bird (red)" left-1.png left-2.png right-1.png right-2.png \
dive-left.png dive-right.png bird-red.doodad
doodad install-script bird.js bird-red.doodad
# Tag the category for these doodads
for i in *.doodad; do doodad edit-doodad --tag "category=creatures" $i; done
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }
objects() { objects() {
cd objects/ cd objects/
make
cd ..
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad cd box/
doodad install-script exit-flag.js exit-flag.doodad make
doodad convert -t "Start Flag" start-flag.png start-flag.doodad
for i in *.doodad; do doodad edit-doodad --tag "category=objects" $i; done
cp *.doodad ../../../assets/doodads/
cd ../crumbly-floor
doodad convert -t "Crumbly Floor" floor.png shake1.png shake2.png \
fall1.png fall2.png fall3.png fall4.png fallen.png \
crumbly-floor.doodad
doodad install-script crumbly-floor.js crumbly-floor.doodad
for i in *.doodad; do doodad edit-doodad --tag "category=objects" $i; done
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
for i in *.doodad; do doodad edit-doodad --tag "category=objects" $i; done
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }
onoff() { onoff() {
cd on-off/ cd on-off/
make
doodad convert -t "State Button" blue-button.png orange-button.png state-button.doodad
doodad install-script state-button.js state-button.doodad
doodad convert -t "State Block (Blue)" blue-on.png blue-off.png state-block-blue.doodad
doodad install-script state-block-blue.js state-block-blue.doodad
doodad convert -t "State Block (Orange)" orange-off.png orange-on.png state-block-orange.doodad
doodad install-script state-block-orange.js state-block-orange.doodad
for i in *.doodad; do doodad edit-doodad --tag "category=gizmos" $i; done
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }
warpdoor() { warpdoor() {
cd warp-door/ cd warp-door/
make
doodad convert -t "Warp Door" door-1.png door-2.png door-3.png door-4.png warp-door.doodad
doodad edit-doodad -q --tag color=none warp-door.doodad
doodad install-script warp-door.js warp-door.doodad
doodad convert -t "Warp Door (Blue)" blue-1.png blue-2.png blue-3.png blue-4.png blue-off.png \
warp-door-blue.doodad
doodad edit-doodad -q --tag color=blue warp-door-blue.doodad
doodad install-script warp-door.js warp-door-blue.doodad
doodad convert -t "Warp Door (Orange)" orange-off.png orange-1.png orange-2.png orange-3.png orange-4.png \
warp-door-orange.doodad
doodad edit-doodad -q --tag color=orange warp-door-orange.doodad
doodad install-script warp-door.js warp-door-orange.doodad
for i in *.doodad; do doodad edit-doodad --tag "category=doors" $i; done
for i in warp-door-*.doodad; do doodad edit-doodad --tag "category=doors,gizmos" $i; done
cp *.doodad ../../../assets/doodads/
cd .. cd ..
} }

View File

@ -0,0 +1,19 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Sticky Button" sticky1.png sticky2.png button-sticky.doodad
doodad install-script sticky.js button-sticky.doodad
doodad convert -t "Button" button1.png button2.png button.doodad
doodad install-script button.js button.doodad
doodad convert -t "Button Type B" typeB1.png typeB2.png button-typeB.doodad
doodad install-script button.js button-typeB.doodad
# Tag the category for these doodads
for i in *.doodad; do\
doodad edit-doodad --tag "category=gizmos" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,12 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Crumbly Floor" floor.png shake1.png shake2.png \
fall1.png fall2.png fall3.png fall4.png fallen.png \
crumbly-floor.doodad
doodad install-script crumbly-floor.js crumbly-floor.doodad
for i in *.doodad; do\
doodad edit-doodad --tag "category=objects" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,5 @@
ALL: build
.PHONY: build
build:
./build.sh

View File

@ -49,4 +49,4 @@ doodad install-script electric-door.js door-electric.doodad
for i in *.doodad; do doodad edit-doodad --tag "category=doors" $i; done for i in *.doodad; do doodad edit-doodad --tag "category=doors" $i; done
doodad edit-doodad --tag "category=doors,gizmos" door-electric.doodad doodad edit-doodad --tag "category=doors,gizmos" door-electric.doodad
cp door-*.doodad key-*.doodad small-*.doodad ../../../assets/doodads/ cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,13 @@
ALL: build
.PHONY: build
build:
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
for i in *.doodad; do\
doodad edit-doodad --tag "category=objects" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,18 @@
ALL: build
.PHONY: build
build:
doodad convert -t "State Button" blue-button.png orange-button.png state-button.doodad
doodad install-script state-button.js state-button.doodad
doodad convert -t "State Block (Blue)" blue-on.png blue-off.png state-block-blue.doodad
doodad install-script state-block-blue.js state-block-blue.doodad
doodad convert -t "State Block (Orange)" orange-off.png orange-on.png state-block-orange.doodad
doodad install-script state-block-orange.js state-block-orange.doodad
for i in *.doodad; do\
doodad edit-doodad --tag "category=gizmos" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,20 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Switch" switch-off.png switch-on.png switch.doodad
doodad convert -t "Floor Switch" down-off.png down-on.png switch-down.doodad
doodad convert -t "Left Switch" left-off.png left-on.png switch-left.doodad
doodad convert -t "Right Switch" right-off.png right-on.png switch-right.doodad
doodad install-script switch.js switch.doodad
doodad install-script switch.js switch-down.doodad
doodad install-script switch.js switch-left.doodad
doodad install-script switch.js switch-right.doodad
# Tag the category for these doodads
for i in *.doodad; do\
doodad edit-doodad --tag "category=gizmos" $${i};\
done
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,32 @@
ALL: build
.PHONY: build
build:
# Build the four basic trapdoors.
doodad convert -t "Trapdoor" down{1,2,3,4}.png trapdoor-down.doodad
doodad convert -t "Trapdoor Left" left{1,2,3,4}.png trapdoor-left.doodad
doodad convert -t "Trapdoor Right" right{1,2,3,4}.png trapdoor-right.doodad
doodad convert -t "Trapdoor Up" up{1,2,3,4}.png trapdoor-up.doodad
doodad install-script trapdoor.js trapdoor-down.doodad
doodad install-script trapdoor.js trapdoor-left.doodad
doodad install-script trapdoor.js trapdoor-right.doodad
doodad install-script trapdoor.js trapdoor-up.doodad
doodad edit-doodad -q --tag direction=down trapdoor-down.doodad
doodad edit-doodad -q --tag direction=left trapdoor-left.doodad
doodad edit-doodad -q --tag direction=right trapdoor-right.doodad
doodad edit-doodad -q --tag direction=up trapdoor-up.doodad
# Tag the category for these doodads
ls -hal *.doodad
for i in *.doodad; do\
echo $${i};\
doodad edit-doodad -q --tag "category=doors" $${i};\
done
# Build the Electric Trapdoor.
doodad convert -t "Electric Trapdoor" electric{1,2,3,4}.png electric-trapdoor.doodad
doodad install-script electric-trapdoor.js electric-trapdoor.doodad
doodad edit-doodad -q --tag "category=doors,gizmos" electric-trapdoor.doodad
cp *.doodad ../../../assets/doodads/

View File

@ -0,0 +1,60 @@
// Electric Trapdoor
var animationSpeed = 100,
spriteWidth = 114,
thickness = 7,
isOpen = false,
animating = false,
powerState = false;
function main() {
Self.SetHitbox(0, 2, spriteWidth, thickness);
Self.AddAnimation("open", animationSpeed, [0, 1, 2, 3]);
Self.AddAnimation("close", animationSpeed, [3, 2, 1, 0]);
// Subscribe to Switches and other power sources. Note: if a
// switch toggles us, we ignore the immediately following
// power signal which will be coming from the same switch.
// The electric trapdoor always toggles when hit by a switch.
var ignoreNextPower = false;
Message.Subscribe("switch:toggle", function (powered) {
ignoreNextPower = true
setPoweredState(!powerState);
});
Message.Subscribe("power", function (powered) {
if (ignoreNextPower) {
ignoreNextPower = false;
return;
}
setPoweredState(powered);
});
Events.OnCollide(function (e) {
if (e.InHitbox && !isOpen) {
return false;
}
})
}
function setPoweredState(powered) {
powerState = powered;
if (powered) {
if (animating || isOpen) {
return;
}
animating = true;
Self.PlayAnimation("open", function () {
isOpen = true;
animating = false;
});
} else {
animating = true;
Self.PlayAnimation("close", function () {
isOpen = false;
animating = false;
});
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 972 B

View File

@ -0,0 +1,26 @@
ALL: build
.PHONY: build
build:
doodad convert -t "Warp Door" door-1.png door-2.png door-3.png door-4.png warp-door.doodad
doodad edit-doodad -q --tag color=none warp-door.doodad
doodad install-script warp-door.js warp-door.doodad
doodad convert -t "Warp Door (Blue)" blue-1.png blue-2.png blue-3.png blue-4.png blue-off.png \
warp-door-blue.doodad
doodad edit-doodad -q --tag color=blue warp-door-blue.doodad
doodad install-script warp-door.js warp-door-blue.doodad
doodad convert -t "Warp Door (Orange)" orange-off.png orange-1.png orange-2.png orange-3.png orange-4.png \
warp-door-orange.doodad
doodad edit-doodad -q --tag color=orange warp-door-orange.doodad
doodad install-script warp-door.js warp-door-orange.doodad
for i in *.doodad; do\
doodad edit-doodad --tag "category=doors" $${i};\
done
for i in warp-door-*.doodad; do\
doodad edit-doodad --tag "category=doors,gizmos" $${i};\
done
cp *.doodad ../../../assets/doodads/