create-spud 0.1.6 → 0.1.7
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/example/index.html +2 -0
- package/example/src/canvas.ts +0 -6
- package/example/src/gameplay.ts +5 -10
- package/index.ts +4 -1
- package/package.json +1 -1
package/example/index.html
CHANGED
package/example/src/canvas.ts
CHANGED
|
@@ -10,10 +10,6 @@ type Bounds = ReturnType<typeof createBounds>;
|
|
|
10
10
|
and then setting a matching transform so that the drawing coords
|
|
11
11
|
can stay in CSS pixels.
|
|
12
12
|
|
|
13
|
-
`bounds` is mutated in place and kept in sync with the canvas via a
|
|
14
|
-
ResizeObserver, so it's cheap to read bounds.width/height from your
|
|
15
|
-
update and draw functions.
|
|
16
|
-
|
|
17
13
|
see also: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Optimizing_canvas
|
|
18
14
|
*/
|
|
19
15
|
export function scaleAndObserveCanvasSize(ctx: CanvasRenderingContext2D, bounds: Bounds) {
|
|
@@ -25,8 +21,6 @@ export function scaleAndObserveCanvasSize(ctx: CanvasRenderingContext2D, bounds:
|
|
|
25
21
|
|
|
26
22
|
canvas.width = width * dpr;
|
|
27
23
|
canvas.height = height * dpr;
|
|
28
|
-
canvas.style.width = `${width}px`;
|
|
29
|
-
canvas.style.height = `${height}px`;
|
|
30
24
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
31
25
|
|
|
32
26
|
bounds.x = x;
|
package/example/src/gameplay.ts
CHANGED
|
@@ -3,18 +3,12 @@ import type { State } from "./state";
|
|
|
3
3
|
/* moon_sprite_import */
|
|
4
4
|
/* audio_import */
|
|
5
5
|
|
|
6
|
-
/*
|
|
7
|
-
the update loop runs in a fixed time-step and should be used for any
|
|
8
|
-
state updates. `dt` is the fixed simulation step in seconds (see gameLoop.ts).
|
|
9
|
-
read state.bounds here if you need to clamp or wrap positions to the play area.
|
|
10
|
-
*/
|
|
11
6
|
export function update(state: State, dt: number) {
|
|
7
|
+
// handle inputs and update state here
|
|
12
8
|
state.elapsedSeconds += dt;
|
|
13
|
-
|
|
14
|
-
/* audio_shoot_sfx */
|
|
15
|
-
}
|
|
9
|
+
/* audio_shoot_sfx */
|
|
16
10
|
|
|
17
|
-
// handle any post-update cleanup below
|
|
11
|
+
// handle any post-update cleanup below
|
|
18
12
|
gamepads.clearInputs();
|
|
19
13
|
}
|
|
20
14
|
|
|
@@ -26,6 +20,7 @@ export function render(state: State, ctx: CanvasRenderingContext2D) {
|
|
|
26
20
|
// clear out the background
|
|
27
21
|
ctx.fillStyle = "#0b0d1a";
|
|
28
22
|
ctx.fillRect(0, 0, width, height);
|
|
23
|
+
ctx.fillStyle = "white";
|
|
29
24
|
|
|
30
25
|
// draw an orbiting circle
|
|
31
26
|
const moon = {
|
|
@@ -38,10 +33,10 @@ export function render(state: State, ctx: CanvasRenderingContext2D) {
|
|
|
38
33
|
return centerY + Math.sin(state.elapsedSeconds) * moon.orbitRadius;
|
|
39
34
|
},
|
|
40
35
|
};
|
|
36
|
+
|
|
41
37
|
/* moon_sprite_draw */
|
|
42
38
|
|
|
43
39
|
// write some text
|
|
44
|
-
ctx.fillStyle = "white";
|
|
45
40
|
ctx.textAlign = "center";
|
|
46
41
|
ctx.textBaseline = "middle";
|
|
47
42
|
/* fonts_ctx_font */
|
package/index.ts
CHANGED
|
@@ -180,10 +180,13 @@ async function copyDir(
|
|
|
180
180
|
.replaceAll(
|
|
181
181
|
" /* audio_shoot_sfx */\n",
|
|
182
182
|
replacements.features.includes(Feature.Audio)
|
|
183
|
-
|
|
183
|
+
}
|
|
184
|
+
? ` if (gamepads.anyPlayer.buttonJustPressed(Button.RightTrigger)) {
|
|
185
|
+
sfx("shoot").play({
|
|
184
186
|
detune: -1000 + Math.random() * 2000,
|
|
185
187
|
playbackRate: 0.5 + Math.random(),
|
|
186
188
|
});
|
|
189
|
+
}
|
|
187
190
|
`
|
|
188
191
|
: " /* handle inputs and update state */\n",
|
|
189
192
|
)
|