123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import Level from "./Level.js";
- import Vec2 from "./Vec2.js";
-
- import Player from "./entities/Player.js";
- import FloatingPlatform from "./entities/FloatingPlatform.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.spawnStructure(structures.ground(new Vec2(22, 6)), 8, 8);
- level.spawnStructure(structures.groundPillar(new Vec2(2, 3)), 14, 6);
- level.spawnStructure(structures.groundPillar(new Vec2(1, 5)), 20, 4);
-
- level.spawnEntity(new BrokenPlatform(level), 22, 6);
- level.spawnEntity(new BrokenPlatform(level), 30, 5);
-
- 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();
|