import Level from "./Level.js"; import Vec2 from "./Vec2.js"; import Player from "./entities/Player.js"; import FloatingPlatform from "./entities/FloatingPlatform.js"; import FallingPlatform from "./entities/FallingPlatform.js"; import BrokenPlatform from "./entities/BrokenPlatform.js"; import structures from "./structures.js"; let canvas = document.getElementById("canvas"); let level = new Level(canvas); level.spawnEntity(new Player(level), 10, 1); level.spawnEntity(new FloatingPlatform(level), 16, 4); level.spawnEntity(new FallingPlatform(level), 20, 1); level.spawnEntity(new FallingPlatform(level), 20, 0); level.spawnEntity(new FallingPlatform(level), 20, -1); level.spawnEntity(new FallingPlatform(level), 20, -2); level.spawnStructure(structures.floor(8, 6), 4, 4); level.spawnEntity(new BrokenPlatform(level), 27, 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();