Noah Petherbridge
38614ee280
* Tightens up the surface area of API methods available to the JavaScript VMs for doodads. Variables and functions are carefully passed in one-by-one so the doodad script can only access intended functions and not snoop on undocumented APIs. * Wrote tons of user documentation for Doodad Scripts: documented the full surface area of the exposed JavaScript API now that the surface area is known and limited. * Early WIP code for the Campaign JSON
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
function main() {
|
|
console.log("Azulian '%s' initialized!", Self.Title);
|
|
|
|
var playerSpeed = 4;
|
|
var gravity = 4;
|
|
var Vx = Vy = 0;
|
|
|
|
var direction = "right";
|
|
|
|
Self.SetMobile(true);
|
|
Self.SetGravity(true);
|
|
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"]);
|
|
|
|
// Sample our X position every few frames and detect if we've hit a solid wall.
|
|
var sampleTick = 0;
|
|
var sampleRate = 5;
|
|
var lastSampledX = 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(playerSpeed * (direction === "left" ? -1 : 1));
|
|
Self.SetVelocity(Vector(Vx, 0.0));
|
|
|
|
if (!Self.IsAnimating()) {
|
|
Self.PlayAnimation("walk-"+direction, null);
|
|
}
|
|
}, 100);
|
|
}
|