doodle/assets/scripts/generic-fire.js
Noah Petherbridge 7866f618da First-class Doodad Hitboxes + Generic Item Script
A new property is added to the Doodad struct: Hitbox (Rect).

The uix.Actor for Play Mode will defer to the Doodad.Hitbox until the
JavaScript has manually set its own via Self.SetHitbox(). So in effect,
scripts no longer need to worry about their hitbox! The one assigned to
the Doodad will be the default.

Scripts can check if their hitbox is zero before setting a default:

  if (Self.Hitbox().IsZero()) {
    var size = Self.Size()           // get doodad canvas size
    Self.SetHitbox(0, 0, size, size) // the full square
  }

The built-in generic doodad scripts have made this change, so that your
simple doodad can have a custom hitbox defined easily using in-game
tools.

Other changes:

* New script: Generic Collectible Item. Selecting it will add a
  "quantity" tag to your doodad, to easily configure the script.
* JavaScript API: "Self.Hitbox()" returns your doodad's current hitbox.
  You can check "Self.Hitbox.IsZero()" to check if it's empty.
2021-09-03 20:39:44 -07:00

38 lines
989 B
JavaScript

// Generic "Fire" Doodad Script
/*
The entire square shape of your doodad acts similar to "Fire"
pixels - killing the player character upon contact.
Can be attached to any doodad.
*/
function main() {
// Make the hitbox be the full canvas size of this doodad.
// Adjust if you want a narrower hitbox.
if (Self.Hitbox().IsZero()) {
var size = Self.Size()
Self.SetHitbox(0, 0, size.W, size.H)
}
Events.OnCollide(function (e) {
if (!e.Settled || !e.InHitbox) {
return;
}
// Turn mobile actors black, like real fire does.
if (e.Actor.IsMobile()) {
e.Actor.Canvas.MaskColor = RGBA(1, 1, 1, 255)
}
// End the level if it's the player.
if (e.Actor.IsPlayer()) {
FailLevel("Watch out for " + Self.Title + "!");
}
})
Events.OnLeave(function (e) {
if (e.Actor.IsMobile()) {
e.Actor.MaskColor = RGBA(0, 0, 0, 0)
}
})
}