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.
|
@ -63,7 +63,13 @@ trapdoors() {
|
|||
cd trapdoors/
|
||||
|
||||
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/
|
||||
|
||||
|
|
BIN
dev-assets/doodads/trapdoors/left1.png
Normal file
After Width: | Height: | Size: 912 B |
BIN
dev-assets/doodads/trapdoors/left2.png
Normal file
After Width: | Height: | Size: 1013 B |
BIN
dev-assets/doodads/trapdoors/left3.png
Normal file
After Width: | Height: | Size: 1009 B |
BIN
dev-assets/doodads/trapdoors/left4.png
Normal file
After Width: | Height: | Size: 765 B |
BIN
dev-assets/doodads/trapdoors/right1.png
Normal file
After Width: | Height: | Size: 933 B |
BIN
dev-assets/doodads/trapdoors/right2.png
Normal file
After Width: | Height: | Size: 1011 B |
BIN
dev-assets/doodads/trapdoors/right3.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
dev-assets/doodads/trapdoors/right4.png
Normal file
After Width: | Height: | Size: 789 B |
71
dev-assets/doodads/trapdoors/trapdoor.js
Normal 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;
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
BIN
dev-assets/doodads/trapdoors/up1.png
Normal file
After Width: | Height: | Size: 831 B |
BIN
dev-assets/doodads/trapdoors/up2.png
Normal file
After Width: | Height: | Size: 964 B |
BIN
dev-assets/doodads/trapdoors/up3.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
dev-assets/doodads/trapdoors/up4.png
Normal file
After Width: | Height: | Size: 846 B |