migalib
Version:
MIGAlib - MInimal GAme LIBrary
54 lines (53 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = void 0;
var gameloop_1 = require("./gameloop");
var UtilsSingleton = /** @class */ (function () {
function UtilsSingleton() {
}
UtilsSingleton.prototype.intersects = function (x1, y1, width1, height1, x2, y2, width2, height2) {
return !(x2 - width2 / 2 > x1 + width1 / 2 ||
x2 + width2 / 2 < x1 - width1 / 2 ||
y2 - height2 / 2 > y1 + height1 / 2 ||
y2 + height2 / 2 < y1 - height1 / 2);
};
UtilsSingleton.prototype.rectContainsPoint = function (x1, y1, width1, height1, pointX, pointY) {
return (x1 <= pointX &&
pointX <= x1 + width1 &&
y1 <= pointY &&
pointY <= y1 + height1);
};
UtilsSingleton.prototype.interpolate = function (num) {
return Math.floor(num * gameloop_1.GameLoop.getDeltaTime());
};
UtilsSingleton.prototype.calculateRotationToPoint = function (sourceX, sourceY, destinationX, destinationY) {
return Math.atan2(destinationY - sourceY, destinationX - sourceX);
};
UtilsSingleton.prototype.lerp = function (a, b, t, transform) {
return (a * (1 - (transform ? transform(t) : t)) +
b * (transform ? transform(t) : t));
};
UtilsSingleton.prototype.getWebGLColor = function (originalHex, alphaChannel) {
if (alphaChannel === void 0) { alphaChannel = 0xff000000; }
return (alphaChannel +
((originalHex & 0xff0000) >>> 16) +
(originalHex & 0x00ff00) +
((originalHex & 0x0000ff) << 16));
};
UtilsSingleton.prototype.lerpPingPong = function (a, b, t, transform) {
return this.lerp(a, b, transform
? transform(1 - Math.abs((t % 2) - 1))
: 1 - Math.abs((t % 2) - 1));
};
UtilsSingleton.prototype.easeIn = function (t) {
return t * t;
};
UtilsSingleton.prototype.easeOut = function (t) {
return 1 - (1 - t) * (1 - t);
};
UtilsSingleton.prototype.easeInOut = function (t) {
return this.lerp(this.easeIn(t), this.easeOut(t), t);
};
return UtilsSingleton;
}());
exports.Utils = new UtilsSingleton();