Noah Petherbridge
3892087932
* The "Use Key" (Q or Spacebar) now activates the Warp Door instead of a collision event doing so. * Warp Doors are now functional: the player opens a door, disappears, the door closes; player is teleported to the linked door which opens, appears the player and closes. * If the player exits thru a Blue or Orange door which is disabled (dotted outline), the door still opens and drops the player off but returns to a Disabled state, acting as a one-way door. * Clean up several debug log lines from Doodle and doodad scripts.
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
// Red bird mob.
|
|
function main() {
|
|
var speed = 4;
|
|
var Vx = Vy = 0;
|
|
var altitude = Self.Position().Y; // original height in the level
|
|
|
|
var direction = "left";
|
|
var states = {
|
|
flying: 0,
|
|
diving: 1,
|
|
};
|
|
var state = states.flying;
|
|
|
|
Self.SetMobile(true);
|
|
Self.SetGravity(false);
|
|
Self.SetHitbox(0, 10, 46, 32);
|
|
Self.AddAnimation("fly-left", 100, ["left-1", "left-2"]);
|
|
Self.AddAnimation("fly-right", 100, ["right-1", "right-2"]);
|
|
|
|
Events.OnCollide(function(e) {
|
|
if (e.Actor.IsMobile() && e.InHitbox) {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
// Sample our X position every few frames and detect if we've hit a solid wall.
|
|
var sampleTick = 0;
|
|
var sampleRate = 2;
|
|
var lastSampledX = 0;
|
|
var lastSampledY = 0;
|
|
|
|
setInterval(function() {
|
|
if (sampleTick % sampleRate === 0) {
|
|
var curX = Self.Position().X;
|
|
var delta = Math.abs(curX - lastSampledX);
|
|
if (delta < 5) {
|
|
direction = direction === "right" ? "left" : "right";
|
|
}
|
|
lastSampledX = curX;
|
|
}
|
|
sampleTick++;
|
|
|
|
// TODO: Vector() requires floats, pain in the butt for JS,
|
|
// the JS API should be friendlier and custom...
|
|
var Vx = parseFloat(speed * (direction === "left" ? -1 : 1));
|
|
Self.SetVelocity(Vector(Vx, 0.0));
|
|
|
|
if (!Self.IsAnimating()) {
|
|
Self.PlayAnimation("fly-"+direction, null);
|
|
}
|
|
}, 100);
|
|
}
|