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 49876c4fdf
commit 810ba193d9
21 changed files with 296 additions and 143 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));
});
// 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.
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() {
cd boy/
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/
make
cd ..
}
buttons() {
cd buttons/
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/
make
cd ..
}
switches() {
cd switches/
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/
make
cd ..
}
doors() {
cd doors/
./build.sh
make
cd ..
}
trapdoors() {
cd 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
for i in *.doodad; do doodad edit-doodad --tag "category=doors" $i; done
cp trapdoor-*.doodad ../../../assets/doodads/
make
cd ..
}
azulians() {
cd azulian/
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/
make
cd ..
}
mobs() {
cd bird/
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/
make
cd ..
}
objects() {
cd objects/
make
cd ..
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/
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 box/
make
cd ..
}
onoff() {
cd on-off/
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/
make
cd ..
}
warpdoor() {
cd warp-door/
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/
make
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
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/

View File

@ -1,5 +1,7 @@
package uix
import "git.kirsle.net/go/render"
// Functions relating to the Doodad JavaScript API for Canvas Actors.
// MakeSelfAPI generates the `Self` object for the scripting API in
@ -10,9 +12,13 @@ func (w *Canvas) MakeSelfAPI(actor *Actor) map[string]interface{} {
"Title": actor.Doodad().Title,
// functions
"ID": actor.ID,
"GetTag": actor.Doodad().Tag,
"Position": actor.Position,
"ID": actor.ID,
"GetTag": actor.Doodad().Tag,
"Position": actor.Position,
"MoveTo": func(p render.Point) {
actor.MoveTo(p)
actor.SetGrounded(false)
},
"SetHitbox": actor.SetHitbox,
"SetVelocity": actor.SetVelocity,
"SetMobile": actor.SetMobile,