Add More Trapdoor Doodads

* Add the other trapdoor directions: Left, Right and Up.
* UI: Show a color square in each Palette Swatch button in Edit Mode.
  * Instead of just the label like "solid", "fire", "decoration" it also
    shows a square box colored as the swatch color. The label and box
    are left-aligned in the button.
* Minor Play Mode physics update:
  * The player jump is now limited: they may only continue to move
    upwards for 20 ticks, after which they must touch ground before
    jumping again.
  * Remove the "press Down to move down" button. Only gravity moves you
    down.
* Fix a crash in the Editor Mode when you dragged doodads on top of each
  other. Source of bug was the loopActorCollision() function, which only
  should be useful to Play Mode, and it expected the scripting engine to
  be attached to the Canvas. In EditorMode there is no scripting engine.
This commit is contained in:
Noah 2019-07-05 15:02:22 -07:00
parent 3f8e4f1926
commit 91ed6457eb
14 changed files with 78 additions and 1 deletions

View File

@ -63,7 +63,13 @@ trapdoors() {
cd trapdoors/ cd trapdoors/
doodad convert -t "Trapdoor" down{1,2,3,4}.png trapdoor-down.doodad doodad convert -t "Trapdoor" down{1,2,3,4}.png trapdoor-down.doodad
doodad install-script down.js 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
cp trapdoor-*.doodad ../../../assets/doodads/ cp trapdoor-*.doodad ../../../assets/doodads/

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

View File

@ -0,0 +1,71 @@
function main() {
// What direction is the trapdoor facing?
// - Titles are like "Trapdoor Left" or "Trapdoor Right"
// - The default (down) is called just "Trapdoor"
var direction = Self.Doodad.Title.split(" ")[1];
if (!direction) {
direction = "down";
}
direction = direction.toLowerCase();
console.log("Trapdoor(%s) initialized", direction);
var timer = 0;
// Set our hitbox based on our orientation.
var thickness = 6;
var doodadSize = 72;
if (direction === "left") {
Self.SetHitbox(48, 0, doodadSize, doodadSize);
} else if (direction === "right") {
Self.SetHitbox(0, 0, thickness+4, doodadSize);
} else if (direction === "up") {
Self.SetHitbox(0, doodadSize - thickness, doodadSize, doodadSize);
} else { // Down, default.
Self.SetHitbox(0, 0, 72, 6);
}
var animationSpeed = 100;
var opened = false;
// Register our animations.
var frames = [];
for (var i = 1; i <= 4; i++) {
frames.push(direction + i);
}
Self.AddAnimation("open", animationSpeed, frames);
frames.reverse();
Self.AddAnimation("close", animationSpeed, frames);
Events.OnCollide( function(e) {
if (opened) {
return;
}
// Is the actor colliding our solid part?
if (e.InHitbox) {
// Are they touching our opening side?
if (direction === "left" && (e.Overlap.X+e.Overlap.W) < (doodadSize-thickness)) {
return false;
} else if (direction === "right" && e.Overlap.X > 0) {
return false;
} else if (direction === "up" && (e.Overlap.Y+e.Overlap.H) < doodadSize) {
return false;
} else if (direction === "down" && e.Overlap.Y > 0) {
return false;
} else {
opened = true;
Self.PlayAnimation("open", null);
}
}
});
Events.OnLeave(function() {
if (opened) {
Self.PlayAnimation("close", function() {
opened = false;
});
}
})
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B