UNPKG

raingame

Version:
72 lines (71 loc) 2.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StandardObject = void 0; var Position_1 = __importDefault(require("./Position")); var Types_1 = require("./types/Types"); var movement_1 = require("./movement/movement"); var StandardObject = /** @class */ (function () { function StandardObject(_a) { var x = _a.x, y = _a.y, width = _a.width, height = _a.height, material = _a.material; this.userData = {}; this.type = "StandardObject"; var me = this; this._position_ = new Position_1.default(x, y); this.position = new Position_1.default(x, y); Object.defineProperty(me, 'position', { get: function () { return me._position_; }, set: function (position) { var width = me.width, height = me.height; var x = position.x, y = position.y; me.center.set(x + width / 2, y + height / 2); me._position_ = position; } }); this.width = width; this.height = height; this.center = new Position_1.default(x + width / 2, y + height / 2); if (material) { this.material = material; } } StandardObject.prototype.render = function (ctx, renderTarget) { if (this.material) { ctx.drawImage(this.material.image, this.position.x, this.position.y, this.width, this.height); } }; StandardObject.prototype.onClick = function (e) { console.log(e); }; StandardObject.prototype.moveTo = function (options) { switch (options.type) { case Types_1.moveTypes.NORMAL: if (options.position) { this.position = options.position; } break; case Types_1.moveTypes.GRADULLY: if (options.position && options.duration) { movement_1.gradullyMoveActions(options, this); } else { throw new Error('Mobile mode: transition, need to set the transition time---duration'); } break; default: break; } }; StandardObject.prototype.setUserData = function (data) { this.userData = data; }; StandardObject.prototype.getUserData = function () { return JSON.parse(JSON.stringify(this.userData)); }; return StandardObject; }()); exports.StandardObject = StandardObject;