You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.js 776B

12345678910111213141516171819202122232425262728293031323334
  1. import Level from './Level';
  2. import Player from './entities/Player';
  3. import Vec2 from './Vec2';
  4. let canvas = document.getElementById("canvas");
  5. let level = new Level(canvas);
  6. level.spawn(new Player(level), 20, 20);
  7. level.start();
  8. // Pause the game when the tab has been out of focus for more than half a second
  9. let blurTimeout = null;
  10. window.addEventListener("focus", () => {
  11. if (blurTimeout != null) {
  12. clearTimeout(blurTimeout);
  13. blurTimeout = null;
  14. }
  15. level.start();
  16. });
  17. window.addEventListener("blur", () => {
  18. if (blurTimeout == null) {
  19. blurTimeout = setTimeout(() => level.stop(), 500);
  20. }
  21. });
  22. // Resize canvas
  23. function resize() {
  24. canvas.width = window.innerWidth;
  25. canvas.height = window.innerHeight;
  26. }
  27. window.addEventListener("resize", resize);
  28. resize();