1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- class Ship {
- constructor() {
- }
- init() {
- this.status = "adrift";
- this.name = "Dulce et Decorum est";
- this.position = { x: 0, y: 0 };
- this.rotation = -37;
- this.damage = 2;
- this.targetAngle = -37;
- }
- update(delta) {
- switch (this.status) {
- case "adrift":
- this.rotation -= 0.05 * delta;
- break;
- case "active":
- if (this.rotation != this.targetAngle) {
- if (Math.abs(this.rotation - this.targetAngle) >= 180) {
- this.rotation -= Math.min(Math.abs(this.rotation - this.targetAngle), 1);
- } else {
- this.rotation += Math.min((this.targetAngle - this.rotation), 1);
- }
- }
- break;
- }
- this.rotation %= 360;
- }
- draw(context, delta) {
- this.update(delta);
- context.save();
- context.translate(game.center.x, game.center.y);
- context.rotate(this.rotation * (Math.PI / 180));
- game.atlas.drawCentered(context, "playerShip1_blue.png", this.position);
- if (this.damage > 0) {
- game.atlas.drawCentered(context, `playerShip1_damage${this.damage}.png`, this.position);
- }
- if (this.status == "traveling") {
- game.atlas.drawBottomCentered(context, `fire10.png`, { x: this.position.x + 1, y: this.position.y + 17 });
- }
- context.restore();
- }
- repair() {
- this.damage = Math.max(this.damage - 1, 0);
- if (this.damage == 0) {
- this.status = "active";
- game.playerHud.ship.updateShipStatus();
- return true;
- }
- return false;
- }
- move() {
- this.status = "traveling";
- game.playerHud.ship.updateShipStatus();
- }
- stop() {
- this.status = "active";
- game.playerHud.ship.updateShipStatus();
- }
- setLocation(newLocation) {
- }
- handleOrientation(event) {
- }
- animateRotation(targetAngle) {
- this.targetAngle = targetAngle;
- }
- dock() {
- this.status = "docked";
- game.playerHud.dialog.rightSay("Ship Docking Coupling Engaged", "");
- }
- undock() {
- this.status = "active";
- }
- isDocked() {
- return this.status == "docked";
- }
- }
|