Noah Petherbridge
08e65c32b5
* Player character now experiences acceleration and friction when walking around the map! * Actor position and movement had to be converted from int's (render.Point) to float64's to support fine-grained acceleration steps. * Added "physics" package and physics.Vector to be a float64 counterpart for render.Point. Vector is used for uix.Actor.Position() for the sake of movement math. Vector is flattened back to a render.Point for collision purposes, since the levels and hitboxes are pixel-bound. * Refactor the uix.Actor to no longer extend the doodads.Drawing (so it can have a Position that's a Vector instead of a Point). This broke some code that expected `.Doodad` to directly reference the Drawing.Doodad: now you had to refer to it as `a.Drawing.Doodad` which was ugly. Added convenience method .Doodad() for a shortcut. * Moved functions like GetBoundingRect() from doodads package to collision, where it uses its own slimmer Actor interface for just the relevant methods it needs.
35 lines
644 B
JavaScript
35 lines
644 B
JavaScript
function main() {
|
|
console.log("%s initialized!", Self.Doodad().Title);
|
|
|
|
var timer = 0;
|
|
|
|
Events.OnCollide(function(e) {
|
|
if (!e.Settled) {
|
|
return;
|
|
}
|
|
|
|
// Verify they've touched the button.
|
|
if (e.Overlap.Y + e.Overlap.H < 24) {
|
|
return;
|
|
}
|
|
|
|
Message.Publish("power", true);
|
|
|
|
if (timer > 0) {
|
|
clearTimeout(timer);
|
|
}
|
|
|
|
Self.ShowLayer(1);
|
|
timer = setTimeout(function() {
|
|
Self.ShowLayer(0);
|
|
Message.Publish("power", false);
|
|
timer = 0;
|
|
}, 200);
|
|
});
|
|
|
|
// Events.OnLeave(function(e) {
|
|
// console.log("%s has stopped touching %s", e, Self.Doodad().Title)
|
|
// Self.Canvas.SetBackground(RGBA(0, 0, 1, 0));
|
|
// })
|
|
}
|