diff --git a/dev-assets/doodads/build.sh b/dev-assets/doodads/build.sh index 3582229..f7afb2b 100755 --- a/dev-assets/doodads/build.sh +++ b/dev-assets/doodads/build.sh @@ -43,44 +43,7 @@ switches() { doors() { cd doors/ - - doodad convert -t "Red Door" red1.png red2.png door-red.doodad - doodad edit-doodad -q --tag color=red door-red.doodad - doodad install-script locked-door.js door-red.doodad - - doodad convert -t "Blue Door" blue1.png blue2.png door-blue.doodad - doodad edit-doodad -q --tag color=blue door-blue.doodad - doodad install-script locked-door.js door-blue.doodad - - doodad convert -t "Green Door" green1.png green2.png door-green.doodad - doodad edit-doodad -q --tag color=green door-green.doodad - doodad install-script locked-door.js door-green.doodad - - doodad convert -t "Yellow Door" yellow1.png yellow2.png door-yellow.doodad - doodad edit-doodad -q --tag color=yellow door-yellow.doodad - doodad install-script locked-door.js door-yellow.doodad - - doodad convert -t "Red Key" red-key.png key-red.doodad - doodad edit-doodad -q --tag color=red key-red.doodad - doodad install-script keys.js key-red.doodad - - doodad convert -t "Blue Key" blue-key.png key-blue.doodad - doodad edit-doodad -q --tag color=blue key-blue.doodad - doodad install-script keys.js key-blue.doodad - - doodad convert -t "Green Key" green-key.png key-green.doodad - doodad edit-doodad -q --tag color=green key-green.doodad - doodad install-script keys.js key-green.doodad - - doodad convert -t "Yellow Key" yellow-key.png key-yellow.doodad - doodad edit-doodad -q --tag color=yellow key-yellow.doodad - doodad install-script keys.js key-yellow.doodad - - doodad convert -t "Electric Door" electric{1,2,3,4}.png door-electric.doodad - doodad install-script electric-door.js door-electric.doodad - - cp door-*.doodad key-*.doodad ../../../assets/doodads/ - + ./build.sh cd .. } diff --git a/dev-assets/doodads/doors/blue-closed.png b/dev-assets/doodads/doors/blue-closed.png new file mode 100644 index 0000000..8db25c4 Binary files /dev/null and b/dev-assets/doodads/doors/blue-closed.png differ diff --git a/dev-assets/doodads/doors/blue-left.png b/dev-assets/doodads/doors/blue-left.png new file mode 100644 index 0000000..5be63c3 Binary files /dev/null and b/dev-assets/doodads/doors/blue-left.png differ diff --git a/dev-assets/doodads/doors/blue-right.png b/dev-assets/doodads/doors/blue-right.png new file mode 100644 index 0000000..af09c3e Binary files /dev/null and b/dev-assets/doodads/doors/blue-right.png differ diff --git a/dev-assets/doodads/doors/build.sh b/dev-assets/doodads/doors/build.sh new file mode 100755 index 0000000..1cdf245 --- /dev/null +++ b/dev-assets/doodads/doors/build.sh @@ -0,0 +1,48 @@ +# doodad convert -t "Red Door" red1.png red2.png door-red.doodad +# doodad edit-doodad -q --tag color=red door-red.doodad +# doodad install-script locked-door.js door-red.doodad + +doodad convert -t "Red Door" red-closed.png red-right.png red-left.png door-red.doodad +doodad edit-doodad -q --tag color=red door-red.doodad +doodad install-script colored-door.js door-red.doodad + +doodad convert -t "Blue Door" blue-closed.png blue-right.png blue-left.png door-blue.doodad +doodad edit-doodad -q --tag color=blue door-blue.doodad +doodad install-script colored-door.js door-blue.doodad + +doodad convert -t "Green Door" green-closed.png green-right.png green-left.png door-green.doodad +doodad edit-doodad -q --tag color=green door-green.doodad +doodad install-script colored-door.js door-green.doodad + +doodad convert -t "Yellow Door" yellow-closed.png yellow-right.png yellow-left.png door-yellow.doodad +doodad edit-doodad -q --tag color=yellow door-yellow.doodad +doodad install-script colored-door.js door-yellow.doodad + +# doodad convert -t "Green Door" green1.png green2.png door-green.doodad +# doodad edit-doodad -q --tag color=green door-green.doodad +# doodad install-script locked-door.js door-green.doodad +# +# doodad convert -t "Yellow Door" yellow1.png yellow2.png door-yellow.doodad +# doodad edit-doodad -q --tag color=yellow door-yellow.doodad +# doodad install-script locked-door.js door-yellow.doodad + +doodad convert -t "Red Key" red-key.png key-red.doodad +doodad edit-doodad -q --tag color=red key-red.doodad +doodad install-script keys.js key-red.doodad + +doodad convert -t "Blue Key" blue-key.png key-blue.doodad +doodad edit-doodad -q --tag color=blue key-blue.doodad +doodad install-script keys.js key-blue.doodad + +doodad convert -t "Green Key" green-key.png key-green.doodad +doodad edit-doodad -q --tag color=green key-green.doodad +doodad install-script keys.js key-green.doodad + +doodad convert -t "Yellow Key" yellow-key.png key-yellow.doodad +doodad edit-doodad -q --tag color=yellow key-yellow.doodad +doodad install-script keys.js key-yellow.doodad + +doodad convert -t "Electric Door" electric{1,2,3,4}.png door-electric.doodad +doodad install-script electric-door.js door-electric.doodad + +cp door-*.doodad key-*.doodad ../../../assets/doodads/ diff --git a/dev-assets/doodads/doors/colored-door.js b/dev-assets/doodads/doors/colored-door.js new file mode 100644 index 0000000..baf7ac4 --- /dev/null +++ b/dev-assets/doodads/doors/colored-door.js @@ -0,0 +1,56 @@ + +function main() { + var color = Self.Doodad.Tag("color"); + + // Layers in the doodad image. + var layer = { + closed: 0, + right: 1, + left: 2, + }; + + // Variables that change in event handler. + var unlocked = false; // Key has been used to unlock the door (one time). + var opened = false; // If door is currently showing its opened state. + var enterSide = 0; // Side of player entering the door, -1 or 1, left or right. + + Self.SetHitbox(23, 0, 23, 64); + + Events.OnCollide(function(e) { + // Record the side that this actor has touched us, in case the door + // needs to open. + if (enterSide === 0) { + enterSide = e.Overlap.X > 0 ? 1 : -1; + } + + if (opened) { + return; + } + + if (e.InHitbox) { + if (unlocked) { + Self.ShowLayer(enterSide < 0 ? layer.right : layer.left); + opened = true; + return; + } + + var data = e.Actor.GetData("key:" + color); + if (data === "") { + // Door is locked. + return false; + } + + if (e.Settled) { + unlocked = true; + Self.ShowLayer(enterSide < 0 ? layer.right : layer.left); + } + } + }); + Events.OnLeave(function(e) { + Self.ShowLayer(layer.closed); + + // Reset collision state. + opened = false; + enterSide = 0; + }); +} diff --git a/dev-assets/doodads/doors/green-closed.png b/dev-assets/doodads/doors/green-closed.png new file mode 100644 index 0000000..014d2db Binary files /dev/null and b/dev-assets/doodads/doors/green-closed.png differ diff --git a/dev-assets/doodads/doors/green-left.png b/dev-assets/doodads/doors/green-left.png new file mode 100644 index 0000000..11b15c6 Binary files /dev/null and b/dev-assets/doodads/doors/green-left.png differ diff --git a/dev-assets/doodads/doors/green-right.png b/dev-assets/doodads/doors/green-right.png new file mode 100644 index 0000000..a057821 Binary files /dev/null and b/dev-assets/doodads/doors/green-right.png differ diff --git a/dev-assets/doodads/doors/locked-door.js b/dev-assets/doodads/doors/locked-door.js index 9844b81..3ad7a8a 100644 --- a/dev-assets/doodads/doors/locked-door.js +++ b/dev-assets/doodads/doors/locked-door.js @@ -1,3 +1,4 @@ +// DEPRECATED: old locked door script. Superceded by colored-door.js. function main() { Self.AddAnimation("open", 0, [1]); var unlocked = false; diff --git a/dev-assets/doodads/doors/red-closed.png b/dev-assets/doodads/doors/red-closed.png new file mode 100644 index 0000000..0b02e02 Binary files /dev/null and b/dev-assets/doodads/doors/red-closed.png differ diff --git a/dev-assets/doodads/doors/red-left.png b/dev-assets/doodads/doors/red-left.png new file mode 100644 index 0000000..4fce4f2 Binary files /dev/null and b/dev-assets/doodads/doors/red-left.png differ diff --git a/dev-assets/doodads/doors/red-right.png b/dev-assets/doodads/doors/red-right.png new file mode 100644 index 0000000..a9f7183 Binary files /dev/null and b/dev-assets/doodads/doors/red-right.png differ diff --git a/dev-assets/doodads/doors/yellow-closed.png b/dev-assets/doodads/doors/yellow-closed.png new file mode 100644 index 0000000..8f1f008 Binary files /dev/null and b/dev-assets/doodads/doors/yellow-closed.png differ diff --git a/dev-assets/doodads/doors/yellow-left.png b/dev-assets/doodads/doors/yellow-left.png new file mode 100644 index 0000000..6d3946b Binary files /dev/null and b/dev-assets/doodads/doors/yellow-left.png differ diff --git a/dev-assets/doodads/doors/yellow-right.png b/dev-assets/doodads/doors/yellow-right.png new file mode 100644 index 0000000..1eb9ac9 Binary files /dev/null and b/dev-assets/doodads/doors/yellow-right.png differ