SectorStation.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class SectorStation {
  2. constructor(x, y) {
  3. this.sectorCoordinates = { x: x, y: y };
  4. this.position = { x: 280, y: -700 };
  5. this.dockPosition = { x: 280, y: 170 };
  6. this.rotation = 0;
  7. this.velocity = { x: 0, y: 0 };
  8. }
  9. init() {
  10. }
  11. getCoordinates() {
  12. return this.sectorCoordinates;
  13. }
  14. update(delta) {
  15. if (!game.ship.isDocked() && this.position.y < this.dockPosition.y) {
  16. this.position.y += this.velocity.y;
  17. } else if (!game.ship.isDocked()) {
  18. game.dockingFinished();
  19. }
  20. //this.rotation += 0.1;
  21. this.rotation %= 360;
  22. }
  23. draw(context, delta) {
  24. this.update(delta);
  25. context.save();
  26. context.translate(this.position.x + game.center.x, this.position.y + game.center.y);
  27. context.rotate(this.rotation * (Math.PI / 180));
  28. game.atlas.drawCentered(context, "spaceStation_026.png", { x: 0, y: 0 });
  29. context.restore();
  30. }
  31. drawNav(context, gridSize, halfGridSize) {
  32. context.save();
  33. context.translate(this.sectorCoordinates.x * gridSize + halfGridSize, this.sectorCoordinates.y * gridSize + halfGridSize);
  34. context.scale(0.05, 0.05);
  35. game.atlas.drawCentered(context, "spaceStation_026.png", { x: 0, y: 0 });
  36. context.restore();
  37. }
  38. handleResize(event) {
  39. }
  40. dock() {
  41. this.position = { x: 280, y: -700 };
  42. this.velocity.y = 0.1;
  43. }
  44. }