Doodad Animations Managed In-Engine

* Add animation support for Doodad actors (Play Mode) into the core
  engine, so that the Doodad script can register named animations and
  play them without managing all the details themselves.
  * Doodad API functions on Self: AddAnimation, PlayAnimation,
    StopAnimation, IsAnimating
* CLI: the `doodad convert` command will name each layer after the
  filename used as the input image.
* CLI: fix the `doodad convert` command creating duplicate Palette
  colors when converting a series of input images into a Doodad.
This commit is contained in:
Noah 2019-05-05 16:32:30 -07:00
parent 1f0075b0f2
commit 8c82bba79a
4 changed files with 91 additions and 81 deletions

View File

@ -11,17 +11,61 @@ mkdir -p ../../assets/doodads
buttons() { buttons() {
cd buttons/ cd buttons/
doodad convert -t "Sticky Button" sticky1.png sticky2.png sticky-button.doodad doodad convert -t "Sticky Button" sticky1.png sticky2.png button-sticky.doodad
doodad install-script sticky.js sticky-button.doodad doodad install-script sticky.js button-sticky.doodad
cp sticky-button.doodad ../../../assets/doodads/
doodad convert -t "Button" button1.png button2.png button.doodad doodad convert -t "Button" button1.png button2.png button.doodad
doodad install-script button.js button.doodad doodad install-script button.js button.doodad
cp button.doodad ../../../assets/doodads/
doodad convert -t "Button Type B" typeB1.png typeB2.png button-typeB.doodad doodad convert -t "Button Type B" typeB1.png typeB2.png button-typeB.doodad
doodad install-script button.js button-typeB.doodad doodad install-script button.js button-typeB.doodad
cp button-typeB.doodad ../../../assets/doodads/
cp button*.doodad ../../../assets/doodads/
cd ..
}
doors() {
cd doors/
doodad convert -t "Red Door" red1.png red2.png 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 install-script locked-door.js door-blue.doodad
doodad convert -t "Green Door" green1.png green2.png 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 install-script locked-door.js door-yellow.doodad
doodad convert -t "Red Key" red-key.png key-red.doodad
doodad install-script keys.js key-red.doodad
doodad convert -t "Blue Key" blue-key.png key-blue.doodad
doodad install-script keys.js key-blue.doodad
doodad convert -t "Green Key" green-key.png key-green.doodad
doodad install-script keys.js key-green.doodad
doodad convert -t "Yellow Key" yellow-key.png 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/
cd ..
}
trapdoors() {
cd trapdoors/
doodad convert -t "Trapdoor" down{1,2,3,4}.png trapdoor-down.doodad
doodad install-script down.js trapdoor-down.doodad
cp trapdoor-*.doodad ../../../assets/doodads/
cd .. cd ..
} }
@ -32,10 +76,17 @@ azulians() {
doodad convert -t "Blue Azulian" blu-front.png blu-back.png \ 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 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 install-script azulian.js azu-blu.doodad
cp azu-blu.doodad ../../../assets/doodads/
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
cp azu-*.doodad ../../../assets/doodads/
cd .. cd ..
} }
buttons buttons
doors
trapdoors
azulians azulians

View File

@ -1,35 +1,16 @@
function main() { function main() {
console.log("%s initialized!", Self.Doodad.Title); console.log("%s initialized!", Self.Doodad.Title);
var timer = 0; var err = Self.AddAnimation("open", 100, [0, 1, 2, 3]);
console.error("door error: %s", err)
var animating = false;
// Animation frames. Events.OnCollide(function() {
var frame = 0; if (animating) {
var frames = Self.LayerCount();
var animationDirection = 1; // forward or backward
var animationSpeed = 100; // interval between frames when animating
var animating = false; // true if animation is actively happening
console.warn("Electric Door has %d frames", frames);
// Animation interval function.
setInterval(function() {
if (!animating) {
return; return;
} }
// Advance the frame forwards or backwards. animating = true;
frame += animationDirection; Self.PlayAnimation("open", null);
if (frame >= frames) { });
// Reached the last frame, start the pause and reverse direction.
animating = false;
frame = frames - 1;
}
Self.ShowLayer(frame);
}, animationSpeed);
Events.OnCollide( function() {
animating = true; // start the animation
})
} }

View File

@ -1,5 +1,13 @@
function main() { function main() {
Self.AddAnimation("open", 0, [1]);
var unlocked = false;
Events.OnCollide(function(e) { Events.OnCollide(function(e) {
Self.ShowLayer(1); if (unlocked) {
return;
}
unlocked = true;
Self.PlayAnimation("open", null);
}); });
} }

View File

@ -3,53 +3,23 @@ function main() {
var timer = 0; var timer = 0;
// Animation frames. var animationSpeed = 100;
var frame = 0; var animating = false;
var frames = Self.LayerCount(); Self.AddAnimation("open", animationSpeed, ["down1", "down2", "down3", "down4"]);
var animationDirection = 1; // forward or backward Self.AddAnimation("close", animationSpeed, ["down4", "down3", "down2", "down1"]);
var animationSpeed = 100; // interval between frames when animating
var animationDelay = 8; // delay ticks at the end before reversing, in
// multiples of animationSpeed
var delayCountdown = 0;
var animating = false; // true if animation is actively happening
console.warn("Trapdoor has %d frames", frames);
// Animation interval function.
setInterval(function() {
if (!animating) {
return;
}
// At the end of the animation (door is open), delay before resuming
// the close animation.
if (delayCountdown > 0) {
delayCountdown--;
return;
}
// Advance the frame forwards or backwards.
frame += animationDirection;
if (frame >= frames) {
// Reached the last frame, start the pause and reverse direction.
delayCountdown = animationDelay;
animationDirection = -1;
// also bounds check it
frame = frames - 1;
}
if (frame < 0) {
// reached the start again
frame = 0;
animationDirection = 1;
animating = false;
}
Self.ShowLayer(frame);
}, animationSpeed);
Events.OnCollide( function() { Events.OnCollide( function() {
animating = true; // start the animation if (animating) {
}) return;
}
animating = true;
Self.PlayAnimation("open", function() {
setTimeout(function() {
Self.PlayAnimation("close", function() {
animating = false;
});
}, 3000);
})
});
} }