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).
44 lines • 1.55 kB
JavaScript
var MovementComponent = (function () {
function MovementComponent(position, newPos) {
this.position = position;
this.newPos = newPos;
}
MovementComponent.prototype.moveRight = function (speed) {
this.speedX = speed;
};
MovementComponent.prototype.moveLeft = function (speed) {
this.speedX = -speed;
};
MovementComponent.prototype.moveUp = function (speed) {
this.speedY = -speed;
};
MovementComponent.prototype.moveDown = function (speed) {
this.speedY = speed;
};
MovementComponent.prototype.clearMovement = function () {
this.speedY = 0;
this.speedX = 0;
};
MovementComponent.prototype.updateMovement = function () {
this.position.xPos += this.speedX;
this.position.yPos += this.speedY;
this.speedY += this.gravity;
if (this.newPos) {
this.travelpath();
}
};
MovementComponent.prototype.travelpath = function () {
var deltaX = this.newPos.x - this.position.xPos;
var deltaY = this.newPos.y - this.position.yPos;
var angle = Math.atan2(deltaY, deltaX);
this.speedX = this.newPos.speed * Math.cos(angle);
this.speedY = this.newPos.speed * Math.sin(angle);
if (this.newPos.infinit) {
this.newPos.x += deltaX;
this.newPos.y += deltaY;
}
};
return MovementComponent;
}());
export { MovementComponent };
//# sourceMappingURL=movement.component.js.map