Noah Petherbridge
2c1185cc9f
* The blue and orange ON/OFF state blocks have all been increased in size to better match the player character (42x42 up from 33x33) * Added a new mob: the Red Bird. It flies back and forth while maintaining its altitude, similar to the Red Azulian. Planned AI behavior is to divebomb the player when it gets close. Dive sprites are included but not yet hooked up in JavaScript. * Warp Doors! (WIP). They have a golden "W" on them and come in three varieties: Brown, Blue and Orange. The blue and orange ones are sensitive to the State Block and will become dotted outlines when inactive (and can not be entered in this state). The door opens for the player character, makes him disappear, then closes again. The plan is it will then warp you to the location of a linked Warp Door elsewhere on the level, but for now it will just make the player re-appear after completing the Close Door animation.
55 lines
1.3 KiB
JavaScript
55 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
|
|
|
|
console.log("Bird altitude is %d", altitude);
|
|
|
|
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);
|
|
}
|