Doodads: Crumbly Floor, Start Flag & State Blocks
Add new doodads: * Start Flag: place this in a level to set the spawn point of the player character. If no flag is found, the player spawns at 0,0 in the top corner of the map. Only use one Start Flag per level, otherwise the player will randomly spawn at one of them. * Crumbly Floor: a solid floor that begins to shake and then fall apart after a moment when a mobile character steps on it. The floor respawns after 5 seconds. * State Blocks: blue and orange blocks that toggle between solid and pass-thru whenever a State Button is activated. * State Button: a solid "ON/OFF" block that toggles State Blocks back and forth when touched. Only activates if touched on the side or bottom; acts as a solid floor when walked on from the top. New features for doodad scripts: * Actor scripts: call SetMobile(true) to mark an actor as a mobile mob (i.e. player character or enemy). Other doodads can check if the actor colliding with them IsMobile so they don't activate if placed too close to other (non-mobile) doodads in a level. The Blue and Red Azulians are the only mobile characters so far. * Message.Broadcast allows sending a pub/sub message out to ALL doodads in the level, instead of only to linked doodads as Message.Publish does. This is used for the State Blocks to globally communicate on/off status without needing to link them all together manually.
|
@ -7,6 +7,7 @@ function main() {
|
||||||
|
|
||||||
var direction = "right";
|
var direction = "right";
|
||||||
|
|
||||||
|
Self.SetMobile(true);
|
||||||
Self.SetGravity(true);
|
Self.SetGravity(true);
|
||||||
Self.AddAnimation("walk-left", 100, ["red-wl1", "red-wl2", "red-wl3", "red-wl4"]);
|
Self.AddAnimation("walk-left", 100, ["red-wl1", "red-wl2", "red-wl3", "red-wl4"]);
|
||||||
Self.AddAnimation("walk-right", 100, ["red-wr1", "red-wr2", "red-wr3", "red-wr4"]);
|
Self.AddAnimation("walk-right", 100, ["red-wr1", "red-wr2", "red-wr3", "red-wr4"]);
|
||||||
|
|
|
@ -7,6 +7,7 @@ function main() {
|
||||||
var animStart = animEnd = 0;
|
var animStart = animEnd = 0;
|
||||||
var animFrame = animStart;
|
var animFrame = animStart;
|
||||||
|
|
||||||
|
Self.SetMobile(true);
|
||||||
Self.SetGravity(true);
|
Self.SetGravity(true);
|
||||||
Self.SetHitbox(7, 4, 17, 28);
|
Self.SetHitbox(7, 4, 17, 28);
|
||||||
Self.AddAnimation("walk-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]);
|
Self.AddAnimation("walk-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]);
|
||||||
|
|
|
@ -115,6 +115,33 @@ objects() {
|
||||||
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad
|
doodad convert -t "Exit Flag" exit-flag.png exit-flag.doodad
|
||||||
doodad install-script exit-flag.js exit-flag.doodad
|
doodad install-script exit-flag.js exit-flag.doodad
|
||||||
|
|
||||||
|
doodad convert -t "Start Flag" start-flag.png start-flag.doodad
|
||||||
|
|
||||||
|
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
|
||||||
|
cp *.doodad ../../../assets/doodads/
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
cp *.doodad ../../../assets/doodads/
|
cp *.doodad ../../../assets/doodads/
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
@ -126,5 +153,6 @@ doors
|
||||||
trapdoors
|
trapdoors
|
||||||
azulians
|
azulians
|
||||||
objects
|
objects
|
||||||
|
onoff
|
||||||
doodad edit-doodad -quiet -lock -author "Noah" ../../assets/doodads/*.doodad
|
doodad edit-doodad -quiet -lock -author "Noah" ../../assets/doodads/*.doodad
|
||||||
doodad edit-doodad -hide ../../assets/doodads/azu-blu.doodad
|
doodad edit-doodad -hide ../../assets/doodads/azu-blu.doodad
|
||||||
|
|
60
dev-assets/doodads/crumbly-floor/crumbly-floor.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// Crumbly Floor.
|
||||||
|
function main() {
|
||||||
|
Self.SetHitbox(0, 0, 65, 7);
|
||||||
|
|
||||||
|
Self.AddAnimation("shake", 100, ["shake1", "shake2", "floor", "shake1", "shake2", "floor"]);
|
||||||
|
Self.AddAnimation("fall", 100, ["fall1", "fall2", "fall3", "fall4"]);
|
||||||
|
|
||||||
|
// Recover time for the floor to respawn.
|
||||||
|
var recover = 5000;
|
||||||
|
|
||||||
|
// States of the floor.
|
||||||
|
var stateSolid = 0;
|
||||||
|
var stateShaking = 1;
|
||||||
|
var stateFalling = 2;
|
||||||
|
var stateFallen = 3;
|
||||||
|
var state = stateSolid;
|
||||||
|
|
||||||
|
// Started the animation?
|
||||||
|
var startedAnimation = false;
|
||||||
|
|
||||||
|
Events.OnCollide(function(e) {
|
||||||
|
// Only trigger for mobile characters.
|
||||||
|
if (!e.Actor.IsMobile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the floor is falling, the player passes right thru.
|
||||||
|
if (state === stateFalling || state === stateFallen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Floor is solid until it begins to fall.
|
||||||
|
if (e.InHitbox && (state === stateSolid || state === stateShaking)) {
|
||||||
|
// Only activate when touched from the top.
|
||||||
|
if (e.Overlap.Y > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Begin the animation sequence if we're in the solid state.
|
||||||
|
if (state === stateSolid) {
|
||||||
|
state = stateShaking;
|
||||||
|
Self.PlayAnimation("shake", function() {
|
||||||
|
state = stateFalling;
|
||||||
|
Self.PlayAnimation("fall", function() {
|
||||||
|
state = stateFallen;
|
||||||
|
Self.ShowLayerNamed("fallen");
|
||||||
|
|
||||||
|
// Recover after a while.
|
||||||
|
setTimeout(function() {
|
||||||
|
Self.ShowLayer(0);
|
||||||
|
state = stateSolid;
|
||||||
|
}, recover);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
BIN
dev-assets/doodads/crumbly-floor/fall1.png
Normal file
After Width: | Height: | Size: 1021 B |
BIN
dev-assets/doodads/crumbly-floor/fall2.png
Normal file
After Width: | Height: | Size: 986 B |
BIN
dev-assets/doodads/crumbly-floor/fall3.png
Normal file
After Width: | Height: | Size: 957 B |
BIN
dev-assets/doodads/crumbly-floor/fall4.png
Normal file
After Width: | Height: | Size: 855 B |
BIN
dev-assets/doodads/crumbly-floor/fallen.png
Normal file
After Width: | Height: | Size: 652 B |
BIN
dev-assets/doodads/crumbly-floor/floor.png
Normal file
After Width: | Height: | Size: 868 B |
BIN
dev-assets/doodads/crumbly-floor/shake1.png
Normal file
After Width: | Height: | Size: 897 B |
BIN
dev-assets/doodads/crumbly-floor/shake2.png
Normal file
After Width: | Height: | Size: 891 B |
|
@ -23,8 +23,8 @@ function main() {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
animating = true;
|
animating = true;
|
||||||
opened = false;
|
|
||||||
Self.PlayAnimation("close", function() {
|
Self.PlayAnimation("close", function() {
|
||||||
|
opened = false;
|
||||||
animating = false;
|
animating = false;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
BIN
dev-assets/doodads/objects/start-flag.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
dev-assets/doodads/on-off/blue-button.png
Normal file
After Width: | Height: | Size: 741 B |
BIN
dev-assets/doodads/on-off/blue-off.png
Normal file
After Width: | Height: | Size: 648 B |
BIN
dev-assets/doodads/on-off/blue-on.png
Normal file
After Width: | Height: | Size: 683 B |
BIN
dev-assets/doodads/on-off/orange-button.png
Normal file
After Width: | Height: | Size: 751 B |
BIN
dev-assets/doodads/on-off/orange-off.png
Normal file
After Width: | Height: | Size: 650 B |
BIN
dev-assets/doodads/on-off/orange-on.png
Normal file
After Width: | Height: | Size: 687 B |
28
dev-assets/doodads/on-off/state-block-blue.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Blue State Block
|
||||||
|
function main() {
|
||||||
|
Self.SetHitbox(0, 0, 33, 33);
|
||||||
|
|
||||||
|
// Blue block is ON by default.
|
||||||
|
var state = true;
|
||||||
|
|
||||||
|
Message.Subscribe("broadcast:state-change", function(newState) {
|
||||||
|
state = !newState;
|
||||||
|
console.warn("BLUE BLOCK Received state=%+v, set mine to %+v", newState, state);
|
||||||
|
|
||||||
|
// Layer 0: ON
|
||||||
|
// Layer 1: OFF
|
||||||
|
if (state) {
|
||||||
|
Self.ShowLayer(0);
|
||||||
|
} else {
|
||||||
|
Self.ShowLayer(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Events.OnCollide(function(e) {
|
||||||
|
if (e.Actor.IsMobile() && e.InHitbox) {
|
||||||
|
if (state) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
28
dev-assets/doodads/on-off/state-block-orange.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Orange State Block
|
||||||
|
function main() {
|
||||||
|
Self.SetHitbox(0, 0, 33, 33);
|
||||||
|
|
||||||
|
// Orange block is OFF by default.
|
||||||
|
var state = false;
|
||||||
|
|
||||||
|
Message.Subscribe("broadcast:state-change", function(newState) {
|
||||||
|
state = newState;
|
||||||
|
console.warn("ORANGE BLOCK Received state=%+v, set mine to %+v", newState, state);
|
||||||
|
|
||||||
|
// Layer 0: OFF
|
||||||
|
// Layer 1: ON
|
||||||
|
if (state) {
|
||||||
|
Self.ShowLayer(1);
|
||||||
|
} else {
|
||||||
|
Self.ShowLayer(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Events.OnCollide(function(e) {
|
||||||
|
if (e.Actor.IsMobile() && e.InHitbox) {
|
||||||
|
if (state) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
47
dev-assets/doodads/on-off/state-button.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// State Block Control Button
|
||||||
|
function main() {
|
||||||
|
console.log("%s initialized!", Self.Doodad.Title);
|
||||||
|
Self.SetHitbox(0, 0, 33, 33);
|
||||||
|
|
||||||
|
// When the button is activated, don't keep toggling state until we're not
|
||||||
|
// being touched again.
|
||||||
|
var colliding = false;
|
||||||
|
|
||||||
|
// Button is "OFF" by default.
|
||||||
|
var state = false;
|
||||||
|
|
||||||
|
Events.OnCollide(function(e) {
|
||||||
|
if (colliding) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only trigger for mobile characters.
|
||||||
|
if (e.Actor.IsMobile()) {
|
||||||
|
console.log("Mobile actor %s touched the on/off button!", e.Actor.Actor.Filename);
|
||||||
|
|
||||||
|
// Only activate if touched from the bottom or sides.
|
||||||
|
if (e.Overlap.Y === 0) {
|
||||||
|
console.log("... but touched the top!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
colliding = true;
|
||||||
|
console.log(" -> emit state change");
|
||||||
|
state = !state;
|
||||||
|
Message.Broadcast("broadcast:state-change", state);
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
Self.ShowLayer(1);
|
||||||
|
} else {
|
||||||
|
Self.ShowLayer(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always a solid button.
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Events.OnLeave(function(e) {
|
||||||
|
colliding = false;
|
||||||
|
})
|
||||||
|
}
|