minimojs 1.0.0-alpha.4 → 1.0.0-alpha.5

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/minimo.d.ts CHANGED
@@ -1009,6 +1009,9 @@ export declare class Game {
1009
1009
  * gesture (click, keypress) before audio can play — always call `sound()` in
1010
1010
  * response to user input or a game event triggered by input.
1011
1011
  *
1012
+ * If you need a melody/sequence, use {@link Game.soundSequence} instead of
1013
+ * multiple `sound()` calls in the same frame.
1014
+ *
1012
1015
  * The tone fades out exponentially over `durationMs` to avoid clicks.
1013
1016
  *
1014
1017
  * @param freq - Frequency in Hz. Middle C = 261.6. Typical range: 100–4000 Hz.
@@ -1022,6 +1025,20 @@ export declare class Game {
1022
1025
  * ```
1023
1026
  */
1024
1027
  sound(freq: number, durationMs: number): void;
1028
+ /**
1029
+ * Plays multiple square-wave tones in strict sequence.
1030
+ *
1031
+ * Each tuple is `[frequencyHz, durationMs]`. The next tone starts when the
1032
+ * previous one ends.
1033
+ *
1034
+ * @param tones - Tone tuples in playback order.
1035
+ *
1036
+ * @example
1037
+ * ```ts
1038
+ * game.soundSequence([660, 80], [820, 90], [980, 110], [1180, 150]);
1039
+ * ```
1040
+ */
1041
+ soundSequence(...tones: Array<readonly [number, number]>): void;
1025
1042
  /**
1026
1043
  * Animates a sprite's {@link Sprite.alpha} from its current value to `to`
1027
1044
  * over `durationMs` milliseconds using **linear interpolation**.
package/dist/minimo.js CHANGED
@@ -1157,6 +1157,9 @@ export class Game {
1157
1157
  * gesture (click, keypress) before audio can play — always call `sound()` in
1158
1158
  * response to user input or a game event triggered by input.
1159
1159
  *
1160
+ * If you need a melody/sequence, use {@link Game.soundSequence} instead of
1161
+ * multiple `sound()` calls in the same frame.
1162
+ *
1160
1163
  * The tone fades out exponentially over `durationMs` to avoid clicks.
1161
1164
  *
1162
1165
  * @param freq - Frequency in Hz. Middle C = 261.6. Typical range: 100–4000 Hz.
@@ -1188,6 +1191,49 @@ export class Game {
1188
1191
  oscillator.start(ctx.currentTime);
1189
1192
  oscillator.stop(ctx.currentTime + durationMs / 1000);
1190
1193
  }
1194
+ /**
1195
+ * Plays multiple square-wave tones in strict sequence.
1196
+ *
1197
+ * Each tuple is `[frequencyHz, durationMs]`. The next tone starts when the
1198
+ * previous one ends.
1199
+ *
1200
+ * @param tones - Tone tuples in playback order.
1201
+ *
1202
+ * @example
1203
+ * ```ts
1204
+ * game.soundSequence([660, 80], [820, 90], [980, 110], [1180, 150]);
1205
+ * ```
1206
+ */
1207
+ soundSequence(...tones) {
1208
+ if (tones.length === 0)
1209
+ return;
1210
+ if (!this._audioCtx) {
1211
+ this._audioCtx = new AudioContext();
1212
+ }
1213
+ const ctx = this._audioCtx;
1214
+ if (ctx.state === "suspended") {
1215
+ ctx.resume();
1216
+ }
1217
+ let startTime = ctx.currentTime;
1218
+ for (const [freq, durationMs] of tones) {
1219
+ if (!Number.isFinite(freq) || !Number.isFinite(durationMs))
1220
+ continue;
1221
+ if (freq <= 0 || durationMs <= 0)
1222
+ continue;
1223
+ const durationSec = durationMs / 1000;
1224
+ const oscillator = ctx.createOscillator();
1225
+ const gain = ctx.createGain();
1226
+ oscillator.type = "square";
1227
+ oscillator.frequency.setValueAtTime(freq, startTime);
1228
+ gain.gain.setValueAtTime(0.08, startTime);
1229
+ gain.gain.exponentialRampToValueAtTime(0.001, startTime + durationSec);
1230
+ oscillator.connect(gain);
1231
+ gain.connect(ctx.destination);
1232
+ oscillator.start(startTime);
1233
+ oscillator.stop(startTime + durationSec);
1234
+ startTime += durationSec;
1235
+ }
1236
+ }
1191
1237
  // -------------------------------------------------------------------------
1192
1238
  // Animations
1193
1239
  // -------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimojs",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "MinimoJS v1 — ultra-minimal, flat, deterministic 2D web game engine. Emoji-only sprites, rAF loop, TypeScript-first, LLM-friendly.",
5
5
  "type": "module",
6
6
  "main": "dist/minimo.js",