@moderrkowo/jsgl
Version:
Client-side JavaScript library for creating web 2D games. Focusing at objective game.
45 lines (44 loc) • 2.1 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.Shape = void 0;
var DrawSettings_1 = require("../structs/DrawSettings");
var ShapeType_1 = require("../enums/ShapeType");
var ClickableGameObject_1 = require("./ClickableGameObject");
/**
* Represents drawable, clickable shape on canvas
* @group Game Objects
*/
var Shape = /** @class */ (function (_super) {
__extends(Shape, _super);
function Shape() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = ShapeType_1.ShapeType.Rect;
_this.properties = Object.create(DrawSettings_1.defaultDrawSettings);
return _this;
}
Shape.prototype.OnDraw = function (event) {
if (this.type === ShapeType_1.ShapeType.Rect) {
event.renderer.drawRectangle(this.transform.position.x, this.transform.position.y, this.transform.scale.x, this.transform.scale.y, this.properties);
}
else if (this.type === ShapeType_1.ShapeType.Circle) {
event.renderer.drawCircle(this.transform.position.x, this.transform.position.y, Math.max(this.transform.scale.x, this.transform.scale.y), this.properties);
}
};
return Shape;
}(ClickableGameObject_1.ClickableGameObject));
exports.Shape = Shape;