minimojs 1.0.0-alpha.1 → 1.0.0-alpha.2
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/dist/animations.js +30 -0
- package/dist/audio.js +17 -0
- package/dist/game.js +1105 -0
- package/dist/input.js +185 -0
- package/dist/internal-types.js +4 -0
- package/dist/minimo.d.ts +123 -0
- package/dist/minimo.js +308 -39
- package/dist/physics.js +10 -0
- package/dist/pointer-info.js +1 -0
- package/dist/render.js +75 -0
- package/dist/sprite.js +149 -0
- package/dist/timers.js +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function scheduleAnimation(animations, sprite, property, to, durationMs, onComplete) {
|
|
2
|
+
const nextAnimations = animations.filter((animation) => !(animation.sprite === sprite && animation.property === property));
|
|
3
|
+
nextAnimations.push({
|
|
4
|
+
sprite,
|
|
5
|
+
property,
|
|
6
|
+
from: sprite[property],
|
|
7
|
+
to,
|
|
8
|
+
durationMs,
|
|
9
|
+
elapsed: 0,
|
|
10
|
+
onComplete,
|
|
11
|
+
});
|
|
12
|
+
return nextAnimations;
|
|
13
|
+
}
|
|
14
|
+
export function updateAnimations(animations, dtMs) {
|
|
15
|
+
const toRemove = [];
|
|
16
|
+
for (let i = 0; i < animations.length; i++) {
|
|
17
|
+
const animation = animations[i];
|
|
18
|
+
animation.elapsed += dtMs;
|
|
19
|
+
const t = Math.min(animation.elapsed / animation.durationMs, 1);
|
|
20
|
+
animation.sprite[animation.property] =
|
|
21
|
+
animation.from + (animation.to - animation.from) * t;
|
|
22
|
+
if (t >= 1) {
|
|
23
|
+
toRemove.push(i);
|
|
24
|
+
animation.onComplete?.();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (let i = toRemove.length - 1; i >= 0; i--) {
|
|
28
|
+
animations.splice(toRemove[i], 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/audio.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function playSquareTone(audioCtx, freq, durationMs) {
|
|
2
|
+
const ctx = audioCtx ?? new AudioContext();
|
|
3
|
+
if (ctx.state === "suspended") {
|
|
4
|
+
ctx.resume();
|
|
5
|
+
}
|
|
6
|
+
const oscillator = ctx.createOscillator();
|
|
7
|
+
const gain = ctx.createGain();
|
|
8
|
+
oscillator.type = "square";
|
|
9
|
+
oscillator.frequency.setValueAtTime(freq, ctx.currentTime);
|
|
10
|
+
gain.gain.setValueAtTime(0.08, ctx.currentTime);
|
|
11
|
+
gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + durationMs / 1000);
|
|
12
|
+
oscillator.connect(gain);
|
|
13
|
+
gain.connect(ctx.destination);
|
|
14
|
+
oscillator.start(ctx.currentTime);
|
|
15
|
+
oscillator.stop(ctx.currentTime + durationMs / 1000);
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|