UNPKG

2d-gaming

Version:

This is an Angular package fo developing 2d games in angular. [Please report issues/questions/any ideas to better help this package](https://github.com/CWestBlue/2d-gaming/issues).

103 lines 4.12 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { MovementComponent } from './ObjectLogic/movement.component'; import { ObjectArray } from './ObjectLogic/ammo.component'; import { UpdateHandler } from './ObjectLogic/updateFrame.component'; var ObjectComponent = (function (_super) { __extends(ObjectComponent, _super); function ObjectComponent(game, design, postion, isBarrier, isObjectDependent) { var _this = _super.call(this, postion) || this; _this.game = game; _this.design = design; _this.postion = postion; _this.isBarrier = isBarrier; _this.score = 1; _this.bullets = new ObjectArray(); // this.movement = new MovementComponent(postion); // this.startingPos = new PositionObject(postion.xPos, postion.yPos); _this.create(); _this.game.gameObjects.add(_this); _this.update = new UpdateHandler(_this.bullets); _this.draw(); return _this; } ObjectComponent.prototype.draw = function () { switch (this.design.shape) { case 'image': // console.log(this.design.image); this.ctx.drawImage(this.design.image, this.postion.xPos, this.postion.yPos, this.design.width, this.design.height); break; case 'text': this.ctx.font = this.design.width + " " + this.design.height; this.ctx.fillStyle = this.design.color; this.ctx.fillText(this.design.text, this.postion.xPos, this.postion.yPos); break; case 'circle': this.ctx.beginPath(); this.ctx.arc(this.postion.xPos + this.design.centerX, this.postion.yPos + this.design.centerY, this.design.radius, 0, 2 * Math.PI, false); this.ctx.fillStyle = this.design.color; this.ctx.fill(); break; default: this.ctx.fillStyle = this.design.color; this.ctx.fillRect(this.postion.xPos, this.postion.yPos, this.design.width, this.design.height); break; } ; this.update.update(); }; ObjectComponent.prototype.shoot = function (x, y, speed, object) { // console.log('shoot') // let arrow = new ObjectComponent(this.game, object.design); // arrow.isShoot = true; // arrow.path = { // x: x, // y: y, // speed: speed, // infinit: false // } // this.bullets.push(arrow); object.newPos = { x: x, y: y, speed: speed, infinit: true }; this.bullets.add(object); }; // update() { // this.barrier = barrier; // if (this.barriers.length > 0) { // this.barriers.forEach(res => { // res.update(false) // }) // } // if (this.bullets.length > 0) { // this.bullets.forEach(res => { // res.update(false); // }) // } // this.travelpath(); // this.newPos(barrier); // this.ctx = this.game.context; // this.typeOf(); // } ObjectComponent.prototype.create = function () { this.speedX = 0; this.speedY = 0; this.gravity = this.game.gravity; this.speedY = 0; this.ctx = this.game.context; }; return ObjectComponent; }(MovementComponent)); export { ObjectComponent }; //# sourceMappingURL=game.objects.component.js.map