create-bloop 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bloop",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Create a new Bloop game",
5
5
  "type": "module",
6
6
  "bin": "./dist/index.js",
@@ -13,8 +13,8 @@
13
13
  "vite": "^7.2.2"
14
14
  },
15
15
  "dependencies": {
16
- "@bloopjs/bloop": "^0.0.91",
16
+ "@bloopjs/bloop": "^0.0.92",
17
17
  "@bloopjs/toodle": "^0.1.3",
18
- "@bloopjs/web": "^0.0.91"
18
+ "@bloopjs/web": "^0.0.92"
19
19
  }
20
20
  }
@@ -15,8 +15,8 @@
15
15
  "vite": "^7.2.2"
16
16
  },
17
17
  "dependencies": {
18
- "@bloopjs/bloop": "^0.0.91",
18
+ "@bloopjs/bloop": "^0.0.92",
19
19
  "@bloopjs/toodle": "^0.1.3",
20
- "@bloopjs/web": "^0.0.91"
20
+ "@bloopjs/web": "^0.0.92"
21
21
  }
22
22
  }
@@ -74,8 +74,8 @@ export function draw(g: typeof game, toodle: Toodle) {
74
74
 
75
75
  const viewport = toodle.Node({
76
76
  size: {
77
- width: toodle.resolution.width,
78
- height: toodle.resolution.height,
77
+ width: toodle.resolution.width / toodle.camera.zoom,
78
+ height: toodle.resolution.height / toodle.camera.zoom,
79
79
  },
80
80
  });
81
81
 
@@ -123,7 +123,7 @@ export function draw(g: typeof game, toodle: Toodle) {
123
123
 
124
124
  const p1Score = gameScreen.add(
125
125
  toodle.Text("Roboto", `P1: ${bag.p1.score}`, {
126
- fontSize: 16,
126
+ fontSize: 10,
127
127
  color: MARIO_COLOR,
128
128
  }),
129
129
  );
@@ -134,7 +134,7 @@ export function draw(g: typeof game, toodle: Toodle) {
134
134
 
135
135
  const p2Score = gameScreen.add(
136
136
  toodle.Text("Roboto", `P2: ${bag.p2.score}`, {
137
- fontSize: 16,
137
+ fontSize: 10,
138
138
  color: LUIGI_COLOR,
139
139
  }),
140
140
  );
@@ -1,4 +1,4 @@
1
- import { Bloop, Util } from "@bloopjs/bloop";
1
+ import { Bloop } from "@bloopjs/bloop";
2
2
  import * as cfg from "./config";
3
3
  import type { Flipbook } from "./flipbook";
4
4
  import { FLIPBOOKS } from "./sprites";
@@ -1,6 +1,55 @@
1
1
  import { Backends, Colors, type Toodle } from "@bloopjs/toodle";
2
2
 
3
- export function createChromaticAberrationEffect(toodle: Toodle): Backends.PostProcess {
3
+ export function setupGlitchEffect(toodle: Toodle): () => void {
4
+ let glitchEffect: Backends.PostProcess | null = null;
5
+ let glitchTimeout: number = -1;
6
+ let glitchQueued = false;
7
+
8
+ if (toodle.backend.type === "webgpu") {
9
+ glitchEffect = createChromaticAberrationEffect(toodle);
10
+ }
11
+
12
+ function doGlitchEffect() {
13
+ if (!glitchEffect) {
14
+ return console.warn(
15
+ `No glitch effect available - are we running on webgl2?`,
16
+ );
17
+ }
18
+
19
+ // Queue effect if page isn't visible or window doesn't have focus (IDE covering browser)
20
+ if (document.visibilityState === "hidden" || !document.hasFocus()) {
21
+ glitchQueued = true;
22
+ return;
23
+ }
24
+ if (glitchTimeout > 0) {
25
+ clearTimeout(glitchTimeout);
26
+ }
27
+ toodle.postprocess = glitchEffect;
28
+ glitchTimeout = setTimeout(() => {
29
+ toodle.postprocess = null;
30
+ }, 1000);
31
+ }
32
+
33
+ document.addEventListener("visibilitychange", () => {
34
+ if (document.visibilityState === "visible" && glitchQueued) {
35
+ glitchQueued = false;
36
+ doGlitchEffect();
37
+ }
38
+ });
39
+
40
+ // Handle case where another app (like IDE) covers the browser window
41
+ // visibilitychange doesn't fire for this, but focus does when clicking back
42
+ window.addEventListener("focus", () => {
43
+ if (glitchQueued) {
44
+ glitchQueued = false;
45
+ doGlitchEffect();
46
+ }
47
+ });
48
+
49
+ return doGlitchEffect;
50
+ }
51
+
52
+ function createChromaticAberrationEffect(toodle: Toodle): Backends.PostProcess {
4
53
  if (!(toodle.backend instanceof Backends.WebGPUBackend)) {
5
54
  throw new Error("Post-processing requires WebGPU backend");
6
55
  }
@@ -1,9 +1,11 @@
1
1
  import "./style.css";
2
2
  import { Toodle } from "@bloopjs/toodle";
3
3
  import { start } from "@bloopjs/web";
4
- import { createChromaticAberrationEffect } from "./chromatic-aberration";
5
- import { draw } from "./draw";
4
+ import { draw as drawFn } from "./draw";
6
5
  import { game } from "./game";
6
+ import { setupGlitchEffect } from "./glitchEffect";
7
+
8
+ let draw = drawFn;
7
9
 
8
10
  // boot up the game
9
11
  const app = await start({
@@ -14,17 +16,6 @@ const app = await start({
14
16
  },
15
17
  });
16
18
 
17
- // HMR support
18
- if (import.meta.hot) {
19
- import.meta.hot.accept("./game", async (newModule) => {
20
- await app.acceptHmr(newModule?.game);
21
- });
22
-
23
- // import.meta.hot.accept("./draw", async (newModule) => {
24
- // draw = newModule?.draw;
25
- // });
26
- }
27
-
28
19
  const canvas = app.canvas;
29
20
  if (!canvas) throw new Error("No canvas element found");
30
21
 
@@ -87,14 +78,17 @@ window.addEventListener("keydown", (e) => {
87
78
  }
88
79
  });
89
80
 
90
- // Debug: Press G to toggle glitch effect on webgpu backend
91
- if (toodle.backend.type === "webgpu") {
92
- const glitchEffect = createChromaticAberrationEffect(toodle);
93
- let glitchEnabled = false;
94
- window.addEventListener("keydown", (e) => {
95
- if (e.key === "g") {
96
- glitchEnabled = !glitchEnabled;
97
- toodle.postprocess = glitchEnabled ? glitchEffect : null;
98
- }
81
+ const doGlitchEffect = setupGlitchEffect(toodle);
82
+
83
+ // HMR support
84
+ if (import.meta.hot) {
85
+ import.meta.hot.accept("./game", async (newModule) => {
86
+ doGlitchEffect();
87
+ await app.acceptHmr(newModule?.game);
88
+ });
89
+
90
+ import.meta.hot.accept("./draw", async (newModule) => {
91
+ doGlitchEffect();
92
+ draw = newModule?.draw;
99
93
  });
100
94
  }