Crab.include() (Idea)

From 8x9craft
Revision as of 03:09, 23 February 2017 by Maciek (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

It would allow usage of libraries, including utility libraries like vector/matrix math, etc.

// Program: vector.lib
function Vector(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
    this.mag = function() {
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    }
}
Vector.prototype.add = function(a, b) {
    return new Vector(a.x + b.x, a.y + b.y, a.z + b.z);
}

// Program: ownerDistance
crab.include('vector.lib');
var crabPos = crab.getPos();
var ownerPos = owner.getPos();
var crabVec = new Vector(crabPos.x, crabPos.y, crabPos.z);
var ownerVec = new Vector(-ownerPos.x, -ownerPos.y, -ownerPos.z);
var diff = Vector.add(crabVec, ownerVec);
var dist = diff.mag();

See also

Navigation menu

Internal error

Jump to: navigation, search
[af4c5379107863d236dda6e8] 2024-03-29 06:40:43: Fatal exception of type "Error"

Navigation menu