1234567891011121314151617181920212223242526272829303132333435363738 |
- import Level from "./Level.js";
- import Player from "./entities/Player.js";
- import Platform from "./entities/Platform.js";
- import structures from "./structures.js";
- import Vec2 from "./Vec2.js";
-
- let canvas = document.getElementById("canvas");
-
- let level = new Level(canvas);
-
- level.spawnEntity(new Player(level), 10, 1);
- level.spawnEntity(new Platform(level), 16, 4);
- level.spawnStructure(structures.floor(4), 4, 4);
-
- level.start();
-
- // Pause the game when the tab has been out of focus for more than half a second
- let blurTimeout = null;
- window.addEventListener("focus", () => {
- if (blurTimeout != null) {
- clearTimeout(blurTimeout);
- blurTimeout = null;
- }
- level.start();
- });
- window.addEventListener("blur", () => {
- if (blurTimeout == null) {
- blurTimeout = setTimeout(() => level.stop(), 500);
- }
- });
-
- // Resize canvas
- function resize() {
- canvas.width = window.innerWidth;
- canvas.height = window.innerHeight;
- }
- window.addEventListener("resize", resize);
- resize();
|