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"; } }