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 +1 -1
- package/templates/hello/package.json +2 -2
- package/templates/mario/package.json +2 -2
- package/templates/mario/src/draw.ts +4 -4
- package/templates/mario/src/game.ts +1 -1
- package/templates/mario/src/{chromatic-aberration.ts → glitchEffect.ts} +50 -1
- package/templates/mario/src/main.ts +16 -22
package/package.json
CHANGED
|
@@ -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:
|
|
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:
|
|
137
|
+
fontSize: 10,
|
|
138
138
|
color: LUIGI_COLOR,
|
|
139
139
|
}),
|
|
140
140
|
);
|
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
import { Backends, Colors, type Toodle } from "@bloopjs/toodle";
|
|
2
2
|
|
|
3
|
-
export function
|
|
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 {
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
}
|