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).
78 lines • 3.4 kB
JavaScript
import { ObjectArray } from './ObjectLogic/ammo.component';
import { CrashComponent } from './ObjectLogic/crashLogic.component';
import { UpdateHandler } from './ObjectLogic/updateFrame.component';
import { GameObjectCategory } from './GameAreaLogic/object-category-setter';
var GameAreaObject = (function () {
function GameAreaObject(name, width, height) {
this.name = name;
this.width = width;
this.height = height;
this.gravity = 0;
this.canvas = document.createElement('canvas');
this.context = this.canvas.getContext('2d');
this.frame = 0;
this.startOn = false;
this.area = document.getElementById('area');
this.height = height;
this.width = width;
this.canvas.id = name + 'Canvas';
this.canvas.style.border = '1px solid black';
this.canvas.style.width = width;
this.canvas.style.height = height;
this.area.id = name;
this.area.appendChild(this.canvas);
this.gameObjects = new ObjectArray();
this.update = new UpdateHandler(this.gameObjects);
this.splitter = new GameObjectCategory(this.gameObjects);
this.crashHandler = new CrashComponent(this.splitter.nonBarriers, this.splitter.barriers);
}
GameAreaObject.prototype.start = function () {
var _this = this;
console.log('started');
if (this.startOn === false) {
if (this.doEveryFrame) {
this.interval = setInterval(function () { _this.clear(); _this.frame += 1; _this.doEveryFrame(); _this.splitter.clear(); _this.splitter.set(); _this.crashHandler.newPos(true); _this.update.update(); }, 20);
this.startOn = true;
}
}
};
GameAreaObject.prototype.clear = function () {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
};
GameAreaObject.prototype.stop = function () {
this.startOn = false;
clearInterval(this.interval);
this.gameObjects.items.forEach(function (res) {
// if (res.bullets.items) {
// res.bullets.items.forEach(bull => {
// this.context.clearRect(bull.postion.xPos, bull.postion.yPos, bull.design.width, bull.design.height)
// let index = _.findIndex(this.gameObjects.items, (o) => { return o === bull });
// this.gameObjects.items.splice(index, 1);
// })
// res.bullets.items = [];
// }
// this.context.clearRect(res.postion.xPos, res.postion.yPos, res.design.width, res.design.height)
// console.log('now: ' + res.postion.xPos);
// res.postion.xPos = res.startingPos.xPos;
// res.postion.yPos = res.startingPos.yPos;
// this.update.update();
});
// this.gameObjects.items = [];
this.splitter.clear();
this.frame = 0;
};
// remove(object: ObjectArray) {
// this.
// }
GameAreaObject.prototype.everyinterval = function (frames) {
if ((this.frame / frames) % 1 === 0) {
return true;
}
else {
return false;
}
};
return GameAreaObject;
}());
export { GameAreaObject };
//# sourceMappingURL=game-area.object.js.map