@moderrkowo/jsgl
Version:
Client-side JavaScript library for creating web 2D games. Focusing at objective game.
61 lines (60 loc) • 2.61 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DrawableGameObject = void 0;
var MathUtils_1 = require("../utils/math/MathUtils");
var GameObject_1 = require("./GameObject");
/**
* Represents drawable game object
* @group Game Objects
*/
var DrawableGameObject = /** @class */ (function (_super) {
__extends(DrawableGameObject, _super);
function DrawableGameObject() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* Defines is this game object visible in game.
* @property
*/
_this.visible = true;
return _this;
}
DrawableGameObject.IsTouching = function (gameObject, anotherGameObject) {
return (gameObject.visible &&
anotherGameObject.visible &&
(0, MathUtils_1.IsInRange)(gameObject.transform.position.x, anotherGameObject.transform.position.x, anotherGameObject.transform.position.x +
anotherGameObject.transform.scale.x) &&
(0, MathUtils_1.IsInRange)(gameObject.transform.position.y, anotherGameObject.transform.position.y, anotherGameObject.transform.position.y +
anotherGameObject.transform.scale.y));
};
/**
* Invoked at frame when drawing
* @method
* @param event - {@link DrawEvent}
* @virtual
* @example
* OnDraw(event){
* event.renderer.drawRectangle(0, 0, 1, 1);
* }
*/
DrawableGameObject.prototype.OnDraw = function (event) { };
DrawableGameObject.prototype.isTouching = function (anotherGameObject) {
return DrawableGameObject.IsTouching(this, anotherGameObject);
};
return DrawableGameObject;
}(GameObject_1.GameObject));
exports.DrawableGameObject = DrawableGameObject;