terminull-arcade 1.0.1 → 1.0.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/index.js CHANGED
@@ -6,12 +6,11 @@ import {
6
6
  APP_VERSION,
7
7
  AchievementManager,
8
8
  ArcadeMenu,
9
- ByteRunnerGame,
10
9
  CyberViperGame,
11
10
  DeterministicRNG,
11
+ HashMatrixGame,
12
12
  MIN_TERMINAL_COLUMNS,
13
13
  MIN_TERMINAL_ROWS,
14
- NeonCircuitGame,
15
14
  PacketManGame,
16
15
  StorageManager,
17
16
  THEMES,
@@ -20,6 +19,7 @@ import {
20
19
  TerminullEngine,
21
20
  UserProfileSchema,
22
21
  UserSettingsSchema,
22
+ VoidInvadersGame,
23
23
  checkTerminalDimensions,
24
24
  clamp,
25
25
  defaultAchievements,
@@ -28,9 +28,965 @@ import {
28
28
  defaultStorage,
29
29
  formatTime,
30
30
  getTheme,
31
- padCenter,
32
- playTerminalBell
33
- } from "./chunk-WCZVPTEK.js";
31
+ padRightVisible,
32
+ playArcadeLoadingScreen,
33
+ playTerminalBell,
34
+ stripAnsi,
35
+ visibleLength,
36
+ wordWrap
37
+ } from "./chunk-BIOTUQT7.js";
38
+
39
+ // src/games/neon-circuit/index.ts
40
+ var NeonCircuitGame = class {
41
+ id = "neon-circuit";
42
+ metadata = ALL_GAMES_METADATA["neon-circuit"];
43
+ config = null;
44
+ renderer = defaultRenderer;
45
+ input = new TerminalInputHandler();
46
+ rng = new DeterministicRNG();
47
+ state = {
48
+ grid: [],
49
+ width: 5,
50
+ height: 5,
51
+ cursorX: 0,
52
+ cursorY: 0,
53
+ movesRemaining: 25,
54
+ maxMoves: 25,
55
+ score: 0,
56
+ level: 1,
57
+ targetsRemaining: 1,
58
+ totalTargets: 1,
59
+ isWon: false,
60
+ isGameOver: false
61
+ };
62
+ isPaused = false;
63
+ pauseMenuIndex = 0;
64
+ showTutorial = true;
65
+ init(config) {
66
+ this.config = config;
67
+ this.renderer.setTheme(config.theme);
68
+ this.rng = new DeterministicRNG(config.seed || Date.now());
69
+ if (config.skipTutorial !== void 0) {
70
+ this.showTutorial = !config.skipTutorial;
71
+ }
72
+ this.setupLevel(1, config.difficulty);
73
+ }
74
+ start() {
75
+ this.isPaused = false;
76
+ this.render();
77
+ this.input.start(
78
+ (key) => this.handleInput(key),
79
+ () => {
80
+ this.destroy();
81
+ process.exit(0);
82
+ }
83
+ );
84
+ }
85
+ pause() {
86
+ this.isPaused = true;
87
+ }
88
+ resume() {
89
+ this.isPaused = false;
90
+ this.render();
91
+ }
92
+ restart() {
93
+ if (this.config) {
94
+ this.state.score = 0;
95
+ this.setupLevel(1, this.config.difficulty);
96
+ this.render();
97
+ }
98
+ }
99
+ saveState() {
100
+ return {
101
+ state: this.state,
102
+ showTutorial: this.showTutorial
103
+ };
104
+ }
105
+ loadState(saved) {
106
+ if (saved["state"]) {
107
+ this.state = saved["state"];
108
+ }
109
+ if (saved["showTutorial"] !== void 0) {
110
+ this.showTutorial = !!saved["showTutorial"];
111
+ }
112
+ this.updatePowerFlow();
113
+ }
114
+ destroy() {
115
+ this.input.stop();
116
+ }
117
+ setupLevel(level, difficulty) {
118
+ let size = 5;
119
+ let moves = 20;
120
+ switch (difficulty) {
121
+ case "easy":
122
+ size = 4;
123
+ moves = 25;
124
+ break;
125
+ case "normal":
126
+ size = 5;
127
+ moves = 22;
128
+ break;
129
+ case "hard":
130
+ size = 6;
131
+ moves = 20;
132
+ break;
133
+ case "insane":
134
+ size = 7;
135
+ moves = 18;
136
+ break;
137
+ }
138
+ this.state.width = size;
139
+ this.state.height = size;
140
+ this.state.level = level;
141
+ this.state.maxMoves = moves;
142
+ this.state.movesRemaining = moves;
143
+ this.state.cursorX = 0;
144
+ this.state.cursorY = 0;
145
+ this.state.isWon = false;
146
+ this.state.isGameOver = false;
147
+ const grid = [];
148
+ for (let y = 0; y < size; y++) {
149
+ const row = [];
150
+ for (let x = 0; x < size; x++) {
151
+ row.push(this.createRandomTile(x, y, size, difficulty));
152
+ }
153
+ row.push();
154
+ grid.push(row);
155
+ }
156
+ grid[0][0] = {
157
+ type: "source",
158
+ rotation: 0,
159
+ baseConnections: [false, true, true, false],
160
+ currentConnections: [false, true, true, false],
161
+ isPowered: true,
162
+ isFixed: true
163
+ };
164
+ grid[size - 1][size - 1] = {
165
+ type: "target",
166
+ rotation: 0,
167
+ baseConnections: [true, false, false, true],
168
+ currentConnections: [true, false, false, true],
169
+ isPowered: false,
170
+ isFixed: true
171
+ };
172
+ if (difficulty === "insane") {
173
+ grid[0][size - 1] = {
174
+ type: "target",
175
+ rotation: 0,
176
+ baseConnections: [false, false, true, true],
177
+ currentConnections: [false, false, true, true],
178
+ isPowered: false,
179
+ isFixed: true
180
+ };
181
+ this.state.totalTargets = 2;
182
+ this.state.targetsRemaining = 2;
183
+ } else {
184
+ this.state.totalTargets = 1;
185
+ this.state.targetsRemaining = 1;
186
+ }
187
+ this.state.grid = grid;
188
+ this.updatePowerFlow();
189
+ }
190
+ createRandomTile(x, y, size, difficulty) {
191
+ if ((difficulty === "hard" || difficulty === "insane") && this.rng.next() < 0.12 && (x > 0 || y > 0)) {
192
+ return {
193
+ type: "blocked",
194
+ rotation: 0,
195
+ baseConnections: [false, false, false, false],
196
+ currentConnections: [false, false, false, false],
197
+ isPowered: false,
198
+ isFixed: true
199
+ };
200
+ }
201
+ const roll = this.rng.next();
202
+ let type = "corner";
203
+ let base = [true, true, false, false];
204
+ if (roll < 0.4) {
205
+ type = "straight";
206
+ base = [true, false, true, false];
207
+ } else if (roll < 0.75) {
208
+ type = "corner";
209
+ base = [true, true, false, false];
210
+ } else if (roll < 0.92) {
211
+ type = "t-shape";
212
+ base = [true, true, false, true];
213
+ } else {
214
+ type = "cross";
215
+ base = [true, true, true, true];
216
+ }
217
+ const rotation = this.rng.nextInt(0, 3);
218
+ const current = this.rotateMask(base, rotation);
219
+ return {
220
+ type,
221
+ rotation,
222
+ baseConnections: base,
223
+ currentConnections: current,
224
+ isPowered: false,
225
+ isFixed: false
226
+ };
227
+ }
228
+ rotateMask(mask, times) {
229
+ const res = [...mask];
230
+ for (let i = 0; i < times % 4; i++) {
231
+ const [top, right, bottom, left] = res;
232
+ res[0] = left;
233
+ res[1] = top;
234
+ res[2] = right;
235
+ res[3] = bottom;
236
+ }
237
+ return res;
238
+ }
239
+ rotateTileAt(x, y) {
240
+ const tile = this.state.grid[y]?.[x];
241
+ if (!tile || tile.isFixed || this.state.isWon || this.state.isGameOver) return false;
242
+ tile.rotation = (tile.rotation + 1) % 4;
243
+ tile.currentConnections = this.rotateMask(tile.baseConnections, tile.rotation);
244
+ this.state.movesRemaining--;
245
+ this.updatePowerFlow();
246
+ if (this.config?.soundEnabled) {
247
+ playTerminalBell();
248
+ }
249
+ if (this.state.isWon) {
250
+ const bonus = this.state.movesRemaining * 100;
251
+ this.state.score += 500 + bonus;
252
+ this.config?.onScoreUpdate?.(this.state.score);
253
+ this.config?.onAchievementUnlock?.("first_spark");
254
+ if (this.state.movesRemaining >= 5) {
255
+ this.config?.onAchievementUnlock?.("overclocked");
256
+ }
257
+ if (this.config?.difficulty === "insane") {
258
+ this.config?.onAchievementUnlock?.("grid_master");
259
+ }
260
+ } else if (this.state.movesRemaining <= 0) {
261
+ this.state.isGameOver = true;
262
+ this.config?.onGameOver?.(this.state.score);
263
+ }
264
+ return true;
265
+ }
266
+ updatePowerFlow() {
267
+ const { width, height, grid } = this.state;
268
+ for (let y = 0; y < height; y++) {
269
+ for (let x = 0; x < width; x++) {
270
+ if (grid[y][x].type !== "source") {
271
+ grid[y][x].isPowered = false;
272
+ }
273
+ }
274
+ }
275
+ const queue = [[0, 0]];
276
+ const visited = /* @__PURE__ */ new Set();
277
+ visited.add("0,0");
278
+ let targetsLit = 0;
279
+ const dx = [0, 1, 0, -1];
280
+ const dy = [-1, 0, 1, 0];
281
+ const oppositeDir = [2, 3, 0, 1];
282
+ while (queue.length > 0) {
283
+ const [cx, cy] = queue.shift();
284
+ const curr = grid[cy][cx];
285
+ for (let dir = 0; dir < 4; dir++) {
286
+ if (!curr.currentConnections[dir]) continue;
287
+ const nx = cx + dx[dir];
288
+ const ny = cy + dy[dir];
289
+ if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
290
+ const key = `${nx},${ny}`;
291
+ if (visited.has(key)) continue;
292
+ const neighbor = grid[ny][nx];
293
+ if (neighbor.type === "blocked") continue;
294
+ const opp = oppositeDir[dir];
295
+ if (neighbor.currentConnections[opp]) {
296
+ neighbor.isPowered = true;
297
+ visited.add(key);
298
+ queue.push([nx, ny]);
299
+ if (neighbor.type === "target") {
300
+ targetsLit++;
301
+ }
302
+ }
303
+ }
304
+ }
305
+ this.state.targetsRemaining = this.state.totalTargets - targetsLit;
306
+ if (this.state.targetsRemaining === 0) {
307
+ this.state.isWon = true;
308
+ }
309
+ }
310
+ handleInput(key) {
311
+ if (this.showTutorial) {
312
+ if (key.name === "return" || key.name === "space") {
313
+ this.showTutorial = false;
314
+ this.render();
315
+ } else if (key.name === "escape" || key.name === "q") {
316
+ this.destroy();
317
+ this.config?.onExit?.();
318
+ }
319
+ return;
320
+ }
321
+ if (this.isPaused) {
322
+ if (key.name === "up" || key.name === "w") {
323
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
324
+ this.render();
325
+ } else if (key.name === "down" || key.name === "s") {
326
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
327
+ this.render();
328
+ } else if (key.name === "return" || key.name === "space") {
329
+ if (this.pauseMenuIndex === 0) {
330
+ this.isPaused = false;
331
+ this.render();
332
+ } else if (this.pauseMenuIndex === 1) {
333
+ this.isPaused = false;
334
+ this.setupLevel(this.state.level, this.config?.difficulty || "normal");
335
+ this.render();
336
+ } else if (this.pauseMenuIndex === 2) {
337
+ this.destroy();
338
+ this.config?.onExit?.();
339
+ }
340
+ } else if (key.name === "escape" || key.name === "p") {
341
+ this.isPaused = false;
342
+ this.render();
343
+ } else if (key.name === "q") {
344
+ this.destroy();
345
+ this.config?.onExit?.();
346
+ }
347
+ return;
348
+ }
349
+ if (key.name === "escape" || key.name === "p") {
350
+ this.isPaused = true;
351
+ this.pauseMenuIndex = 0;
352
+ this.render();
353
+ return;
354
+ }
355
+ if (key.name === "q") {
356
+ this.destroy();
357
+ this.config?.onExit?.();
358
+ return;
359
+ }
360
+ if (this.state.isWon) {
361
+ if (key.name === "return" || key.name === "space") {
362
+ this.setupLevel(this.state.level + 1, this.config?.difficulty || "normal");
363
+ this.render();
364
+ } else if (key.name === "escape" || key.name === "q") {
365
+ this.destroy();
366
+ this.config?.onExit?.();
367
+ }
368
+ return;
369
+ }
370
+ if (this.state.isGameOver) {
371
+ if (key.name === "r") {
372
+ this.restart();
373
+ } else if (key.name === "escape" || key.name === "q") {
374
+ this.destroy();
375
+ this.config?.onExit?.();
376
+ }
377
+ return;
378
+ }
379
+ if (key.name === "up" || key.name === "w") {
380
+ this.state.cursorY = Math.max(0, this.state.cursorY - 1);
381
+ this.render();
382
+ } else if (key.name === "down" || key.name === "s") {
383
+ this.state.cursorY = Math.min(this.state.height - 1, this.state.cursorY + 1);
384
+ this.render();
385
+ } else if (key.name === "left" || key.name === "a") {
386
+ this.state.cursorX = Math.max(0, this.state.cursorX - 1);
387
+ this.render();
388
+ } else if (key.name === "right" || key.name === "d") {
389
+ this.state.cursorX = Math.min(this.state.width - 1, this.state.cursorX + 1);
390
+ this.render();
391
+ } else if (key.name === "space" || key.name === "return") {
392
+ this.rotateTileAt(this.state.cursorX, this.state.cursorY);
393
+ this.render();
394
+ } else if (key.name === "r") {
395
+ this.setupLevel(this.state.level, this.config?.difficulty || "normal");
396
+ this.render();
397
+ }
398
+ }
399
+ render() {
400
+ const t = this.renderer.getTheme();
401
+ if (this.showTutorial) {
402
+ const tutorialLines = [
403
+ "",
404
+ t.highlight("OBJECTIVE: ROUTE HIGH-VOLTAGE FLUX"),
405
+ "",
406
+ "\u2022 Navigate cursor using Arrow Keys or WASD.",
407
+ "\u2022 Press Space or Enter to rotate circuit tiles clockwise.",
408
+ "\u2022 Connect the glowing [S] Power Source to the [T] Target nodes.",
409
+ "\u2022 Watch your Capacity (Moves Remaining) meter.",
410
+ "\u2022 Obstacles [\u2593] cannot conduct energy or rotate.",
411
+ "",
412
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
413
+ t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
414
+ ];
415
+ const box = this.renderer.createBox(tutorialLines, 64, "CIRCUIT PROTOCOL MANUAL");
416
+ this.renderer.clear();
417
+ this.renderer.draw(`
418
+
419
+ ${box}
420
+ `);
421
+ return;
422
+ }
423
+ if (this.isPaused) {
424
+ const pauseItems = ["Resume Circuit (Esc / Enter)", "Restart Level (R)", "Quit to Arcade / Terminal (Q)"];
425
+ const pauseLines = [
426
+ "",
427
+ t.highlight("\u2550\u2550\u2550 CIRCUIT SUBROUTINE PAUSED \u2550\u2550\u2550"),
428
+ "",
429
+ ...pauseItems.map((item, idx) => {
430
+ if (idx === this.pauseMenuIndex) {
431
+ return t.primary(` \u25B6 ${t.highlight(item)}`);
432
+ }
433
+ return t.muted(` ${item}`);
434
+ }),
435
+ "",
436
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
437
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
438
+ ];
439
+ const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
440
+ this.renderer.clear();
441
+ this.renderer.draw(`
442
+
443
+ ${pauseBox}
444
+ `);
445
+ return;
446
+ }
447
+ const header = this.renderer.renderHeader({
448
+ title: "NEON CIRCUIT",
449
+ category: "PUZZLE",
450
+ difficulty: this.config?.difficulty,
451
+ score: this.state.score,
452
+ level: this.state.level
453
+ });
454
+ const lines = [];
455
+ const { width, height, grid, cursorX, cursorY } = this.state;
456
+ lines.push(` Level: ${t.primary(this.state.level.toString())} Moves: ${this.state.movesRemaining > 5 ? t.success(this.state.movesRemaining.toString()) : t.error(this.state.movesRemaining.toString())} Targets: ${t.accent(`${this.state.totalTargets - this.state.targetsRemaining}/${this.state.totalTargets}`)}`);
457
+ lines.push("");
458
+ for (let y = 0; y < height; y++) {
459
+ let rowStr = " ";
460
+ for (let x = 0; x < width; x++) {
461
+ const tile = grid[y][x];
462
+ const isCursor = x === cursorX && y === cursorY;
463
+ const glyph = this.getTileGlyph(tile);
464
+ let formatted = glyph;
465
+ if (tile.isPowered) {
466
+ formatted = t.highlight(glyph);
467
+ } else {
468
+ formatted = t.muted(glyph);
469
+ }
470
+ if (isCursor) {
471
+ rowStr += `[${t.accent(glyph)}] `;
472
+ } else {
473
+ rowStr += ` ${formatted} `;
474
+ }
475
+ }
476
+ lines.push(rowStr);
477
+ lines.push("");
478
+ }
479
+ if (this.state.isWon) {
480
+ lines.push(` ${t.success("\u26A1 CIRCUIT SYNCHRONIZED! ALL NODES POWERED!")}`);
481
+ lines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
482
+ } else if (this.state.isGameOver) {
483
+ lines.push(` ${t.error("\u274C CAPACITY EXHAUSTED! POWER COLLAPSE.")}`);
484
+ lines.push(` ${t.muted("Press R to Retry Level, or P for Pause Menu.")}`);
485
+ } else {
486
+ lines.push(` ${t.muted("Controls: Arrows/WASD: Move \u2502 Space: Rotate \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
487
+ }
488
+ this.renderer.clear();
489
+ this.renderer.draw(`
490
+ ${header}
491
+ ${lines.join("\n")}
492
+ `);
493
+ }
494
+ getTileGlyph(tile) {
495
+ if (tile.type === "source") return "S";
496
+ if (tile.type === "target") return "T";
497
+ if (tile.type === "blocked") return "\u2593";
498
+ const [top, right, bottom, left] = tile.currentConnections;
499
+ if (top && bottom && !right && !left) return "\u2502";
500
+ if (!top && !bottom && right && left) return "\u2500";
501
+ if (bottom && right && !top && !left) return "\u250C";
502
+ if (bottom && left && !top && !right) return "\u2510";
503
+ if (top && right && !bottom && !left) return "\u2514";
504
+ if (top && left && !bottom && !right) return "\u2518";
505
+ if (top && bottom && right && !left) return "\u251C";
506
+ if (top && bottom && !right && left) return "\u2524";
507
+ if (!top && bottom && right && left) return "\u252C";
508
+ if (top && !bottom && right && left) return "\u2534";
509
+ if (top && bottom && right && left) return "\u253C";
510
+ return "\u2022";
511
+ }
512
+ getState() {
513
+ return this.state;
514
+ }
515
+ };
516
+
517
+ // src/games/byte-runner/index.ts
518
+ var HIGHWAY_HEIGHT = 16;
519
+ var LANE_COUNT = 3;
520
+ var ByteRunnerGame = class {
521
+ id = "byte-runner";
522
+ metadata = ALL_GAMES_METADATA["byte-runner"];
523
+ config = null;
524
+ renderer = defaultRenderer;
525
+ input = new TerminalInputHandler();
526
+ rng = new DeterministicRNG();
527
+ gameLoopTimer = null;
528
+ entityIdCounter = 0;
529
+ entities = [];
530
+ state = {
531
+ playerLane: 1,
532
+ isJumping: false,
533
+ jumpTicksRemaining: 0,
534
+ score: 0,
535
+ distance: 0,
536
+ cleanBytesCollected: 0,
537
+ activeShield: false,
538
+ slowMotionTicks: 0,
539
+ magnetTicks: 0,
540
+ doubleScoreTicks: 0,
541
+ speedMs: 110,
542
+ isGameOver: false,
543
+ multiplier: 1
544
+ };
545
+ isPaused = false;
546
+ pauseMenuIndex = 0;
547
+ showTutorial = true;
548
+ init(config) {
549
+ this.config = config;
550
+ this.renderer.setTheme(config.theme);
551
+ this.rng = new DeterministicRNG(config.seed || Date.now());
552
+ if (config.skipTutorial !== void 0) {
553
+ this.showTutorial = !config.skipTutorial;
554
+ }
555
+ this.resetState(config.difficulty);
556
+ }
557
+ start() {
558
+ this.isPaused = false;
559
+ this.render();
560
+ this.input.start(
561
+ (key) => this.handleInput(key),
562
+ () => {
563
+ this.destroy();
564
+ process.exit(0);
565
+ }
566
+ );
567
+ this.scheduleNextTick();
568
+ }
569
+ pause() {
570
+ this.isPaused = true;
571
+ if (this.gameLoopTimer) {
572
+ clearTimeout(this.gameLoopTimer);
573
+ this.gameLoopTimer = null;
574
+ }
575
+ }
576
+ resume() {
577
+ this.isPaused = false;
578
+ this.scheduleNextTick();
579
+ this.render();
580
+ }
581
+ restart() {
582
+ if (this.config) {
583
+ this.resetState(this.config.difficulty);
584
+ this.scheduleNextTick();
585
+ this.render();
586
+ }
587
+ }
588
+ saveState() {
589
+ return {
590
+ state: this.state,
591
+ entities: this.entities,
592
+ showTutorial: this.showTutorial
593
+ };
594
+ }
595
+ loadState(saved) {
596
+ if (saved["state"]) {
597
+ this.state = saved["state"];
598
+ }
599
+ if (saved["entities"]) {
600
+ this.entities = saved["entities"];
601
+ }
602
+ if (saved["showTutorial"] !== void 0) {
603
+ this.showTutorial = !!saved["showTutorial"];
604
+ }
605
+ }
606
+ destroy() {
607
+ if (this.gameLoopTimer) {
608
+ clearTimeout(this.gameLoopTimer);
609
+ this.gameLoopTimer = null;
610
+ }
611
+ this.input.stop();
612
+ }
613
+ resetState(difficulty) {
614
+ let baseSpeed = 110;
615
+ switch (difficulty) {
616
+ case "easy":
617
+ baseSpeed = 140;
618
+ break;
619
+ case "normal":
620
+ baseSpeed = 110;
621
+ break;
622
+ case "hard":
623
+ baseSpeed = 85;
624
+ break;
625
+ case "insane":
626
+ baseSpeed = 65;
627
+ break;
628
+ }
629
+ this.state = {
630
+ playerLane: 1,
631
+ isJumping: false,
632
+ jumpTicksRemaining: 0,
633
+ score: 0,
634
+ distance: 0,
635
+ cleanBytesCollected: 0,
636
+ activeShield: false,
637
+ slowMotionTicks: 0,
638
+ magnetTicks: 0,
639
+ doubleScoreTicks: 0,
640
+ speedMs: baseSpeed,
641
+ isGameOver: false,
642
+ multiplier: 1
643
+ };
644
+ this.entities = [];
645
+ }
646
+ scheduleNextTick() {
647
+ if (this.gameLoopTimer) {
648
+ clearTimeout(this.gameLoopTimer);
649
+ }
650
+ if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
651
+ let delay = this.state.speedMs;
652
+ if (this.state.slowMotionTicks > 0) {
653
+ delay = Math.round(delay * 1.6);
654
+ }
655
+ this.gameLoopTimer = setTimeout(() => {
656
+ this.tick();
657
+ this.scheduleNextTick();
658
+ }, delay);
659
+ }
660
+ tick() {
661
+ if (this.state.isGameOver || this.isPaused || this.showTutorial) return;
662
+ this.state.distance += 1;
663
+ const pointGain = 1 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
664
+ this.state.score += pointGain;
665
+ if (this.state.jumpTicksRemaining > 0) {
666
+ this.state.jumpTicksRemaining--;
667
+ if (this.state.jumpTicksRemaining === 0) {
668
+ this.state.isJumping = false;
669
+ }
670
+ }
671
+ if (this.state.slowMotionTicks > 0) this.state.slowMotionTicks--;
672
+ if (this.state.magnetTicks > 0) this.state.magnetTicks--;
673
+ if (this.state.doubleScoreTicks > 0) this.state.doubleScoreTicks--;
674
+ for (const ent of this.entities) {
675
+ ent.y += 1;
676
+ if (this.state.magnetTicks > 0 && ent.type === "clean" && ent.y >= HIGHWAY_HEIGHT - 6) {
677
+ ent.lane = this.state.playerLane;
678
+ }
679
+ }
680
+ const playerY = HIGHWAY_HEIGHT - 2;
681
+ const remainingEntities = [];
682
+ for (const ent of this.entities) {
683
+ if (ent.y === playerY && ent.lane === this.state.playerLane) {
684
+ if (ent.type === "corrupt") {
685
+ if (this.state.isJumping) {
686
+ remainingEntities.push(ent);
687
+ continue;
688
+ }
689
+ if (this.state.activeShield) {
690
+ this.state.activeShield = false;
691
+ this.config?.onAchievementUnlock?.("shield_matrix");
692
+ if (this.config?.soundEnabled) playTerminalBell();
693
+ continue;
694
+ }
695
+ this.state.isGameOver = true;
696
+ this.config?.onGameOver?.(this.state.score);
697
+ if (this.config?.soundEnabled) playTerminalBell();
698
+ break;
699
+ } else if (ent.type === "clean") {
700
+ this.state.cleanBytesCollected++;
701
+ this.state.score += 100 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
702
+ this.config?.onScoreUpdate?.(this.state.score);
703
+ if (this.state.cleanBytesCollected >= 50) {
704
+ this.config?.onAchievementUnlock?.("packet_chaser");
705
+ }
706
+ if (this.config?.soundEnabled) playTerminalBell();
707
+ continue;
708
+ } else if (ent.type === "powerup") {
709
+ this.activatePowerUp(ent.subType);
710
+ if (this.config?.soundEnabled) playTerminalBell();
711
+ continue;
712
+ }
713
+ }
714
+ if (ent.y < HIGHWAY_HEIGHT) {
715
+ remainingEntities.push(ent);
716
+ }
717
+ }
718
+ this.entities = remainingEntities;
719
+ if (this.state.distance >= 5e3) {
720
+ this.config?.onAchievementUnlock?.("hyperspeed");
721
+ }
722
+ if (this.state.distance % 2 === 0) {
723
+ this.spawnHighwayWave();
724
+ }
725
+ if (this.state.distance % 200 === 0 && this.state.speedMs > 45) {
726
+ this.state.speedMs -= 2;
727
+ }
728
+ this.render();
729
+ }
730
+ activatePowerUp(type) {
731
+ switch (type) {
732
+ case "shield":
733
+ this.state.activeShield = true;
734
+ break;
735
+ case "slow":
736
+ this.state.slowMotionTicks = 60;
737
+ break;
738
+ case "magnet":
739
+ this.state.magnetTicks = 70;
740
+ break;
741
+ case "double":
742
+ this.state.doubleScoreTicks = 80;
743
+ break;
744
+ }
745
+ }
746
+ spawnHighwayWave() {
747
+ const roll = this.rng.next();
748
+ const lane = this.rng.nextInt(0, LANE_COUNT - 1);
749
+ if (roll < 0.45) {
750
+ const labels = ["[CORRUPT]", "[BAD_MEM]", "[NULL_PTR]", "[SEG_FLT]"];
751
+ this.entities.push({
752
+ id: ++this.entityIdCounter,
753
+ lane,
754
+ y: 0,
755
+ type: "corrupt",
756
+ label: this.rng.pick(labels)
757
+ });
758
+ } else if (roll < 0.8) {
759
+ const labels = ["0x7F", "0xFF", "[CLEAN]", "[PACKET]"];
760
+ this.entities.push({
761
+ id: ++this.entityIdCounter,
762
+ lane,
763
+ y: 0,
764
+ type: "clean",
765
+ label: this.rng.pick(labels)
766
+ });
767
+ } else if (roll < 0.95) {
768
+ const powerups = ["shield", "slow", "magnet", "double"];
769
+ const chosen = this.rng.pick(powerups);
770
+ const labels = {
771
+ shield: "\u{1F6E1}\uFE0F [SHLD]",
772
+ slow: "\u23F1\uFE0F [SLOW]",
773
+ magnet: "\u{1F9F2} [MAG]",
774
+ double: "\u26A1 [2X]"
775
+ };
776
+ this.entities.push({
777
+ id: ++this.entityIdCounter,
778
+ lane,
779
+ y: 0,
780
+ type: "powerup",
781
+ subType: chosen,
782
+ label: labels[chosen]
783
+ });
784
+ }
785
+ }
786
+ handleInput(key) {
787
+ if (this.showTutorial) {
788
+ if (key.name === "return" || key.name === "space") {
789
+ this.showTutorial = false;
790
+ this.scheduleNextTick();
791
+ this.render();
792
+ } else if (key.name === "escape" || key.name === "q") {
793
+ this.destroy();
794
+ this.config?.onExit?.();
795
+ }
796
+ return;
797
+ }
798
+ if (this.isPaused) {
799
+ if (key.name === "up" || key.name === "w") {
800
+ this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
801
+ this.render();
802
+ } else if (key.name === "down" || key.name === "s") {
803
+ this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
804
+ this.render();
805
+ } else if (key.name === "return" || key.name === "space") {
806
+ if (this.pauseMenuIndex === 0) {
807
+ this.isPaused = false;
808
+ this.scheduleNextTick();
809
+ this.render();
810
+ } else if (this.pauseMenuIndex === 1) {
811
+ this.isPaused = false;
812
+ this.restart();
813
+ } else if (this.pauseMenuIndex === 2) {
814
+ this.destroy();
815
+ this.config?.onExit?.();
816
+ }
817
+ } else if (key.name === "escape" || key.name === "p") {
818
+ this.isPaused = false;
819
+ this.scheduleNextTick();
820
+ this.render();
821
+ } else if (key.name === "q") {
822
+ this.destroy();
823
+ this.config?.onExit?.();
824
+ }
825
+ return;
826
+ }
827
+ if (key.name === "escape" || key.name === "p") {
828
+ this.isPaused = true;
829
+ this.pauseMenuIndex = 0;
830
+ if (this.gameLoopTimer) {
831
+ clearTimeout(this.gameLoopTimer);
832
+ this.gameLoopTimer = null;
833
+ }
834
+ this.render();
835
+ return;
836
+ }
837
+ if (key.name === "q") {
838
+ this.destroy();
839
+ this.config?.onExit?.();
840
+ return;
841
+ }
842
+ if (this.state.isGameOver) {
843
+ if (key.name === "r") {
844
+ this.restart();
845
+ } else if (key.name === "escape" || key.name === "q") {
846
+ this.destroy();
847
+ this.config?.onExit?.();
848
+ }
849
+ return;
850
+ }
851
+ if (key.name === "left" || key.name === "a") {
852
+ if (this.state.playerLane > 0) {
853
+ this.state.playerLane--;
854
+ this.render();
855
+ }
856
+ } else if (key.name === "right" || key.name === "d") {
857
+ if (this.state.playerLane < LANE_COUNT - 1) {
858
+ this.state.playerLane++;
859
+ this.render();
860
+ }
861
+ } else if (key.name === "up" || key.name === "w" || key.name === "space") {
862
+ if (!this.state.isJumping) {
863
+ this.state.isJumping = true;
864
+ this.state.jumpTicksRemaining = 3;
865
+ this.render();
866
+ }
867
+ } else if (key.name === "down" || key.name === "s") {
868
+ this.state.isJumping = false;
869
+ this.state.jumpTicksRemaining = 0;
870
+ this.render();
871
+ }
872
+ }
873
+ render() {
874
+ const t = this.renderer.getTheme();
875
+ if (this.showTutorial) {
876
+ const lines = [
877
+ "",
878
+ t.highlight("OBJECTIVE: SPRINT THE FIBER HIGHWAY"),
879
+ "",
880
+ "\u2022 Use Left/Right (or A/D) to switch between 3 data lanes.",
881
+ "\u2022 Press Up / Space to Phase Jump over low corrupted blocks.",
882
+ "\u2022 Collect Clean Byte packets to boost your score.",
883
+ "\u2022 Grab Power-ups: [SHLD] Shield, [SLOW] Buffer, [MAG] Magnet, [2X] Double.",
884
+ "\u2022 Speed escalates continuously with distance.",
885
+ "",
886
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
887
+ t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
888
+ ];
889
+ const box = this.renderer.createBox(lines, 64, "BYTE RUNNER MANUAL");
890
+ this.renderer.clear();
891
+ this.renderer.draw(`
892
+
893
+ ${box}
894
+ `);
895
+ return;
896
+ }
897
+ if (this.isPaused) {
898
+ const pauseItems = ["Resume Runner (Esc / Enter)", "Restart Run (R)", "Quit to Arcade / Terminal (Q)"];
899
+ const pauseLines = [
900
+ "",
901
+ t.highlight("\u2550\u2550\u2550 HIGHWAY PACKET STREAM PAUSED \u2550\u2550\u2550"),
902
+ "",
903
+ ...pauseItems.map((item, idx) => {
904
+ if (idx === this.pauseMenuIndex) {
905
+ return t.primary(` \u25B6 ${t.highlight(item)}`);
906
+ }
907
+ return t.muted(` ${item}`);
908
+ }),
909
+ "",
910
+ t.border("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),
911
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
912
+ ];
913
+ const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
914
+ this.renderer.clear();
915
+ this.renderer.draw(`
916
+
917
+ ${pauseBox}
918
+ `);
919
+ return;
920
+ }
921
+ const header = this.renderer.renderHeader({
922
+ title: "BYTE RUNNER",
923
+ category: "ARCADE",
924
+ difficulty: this.config?.difficulty,
925
+ score: this.state.score
926
+ });
927
+ const hudLines = [];
928
+ const distStr = `${t.muted("Distance:")} ${t.primary(`${this.state.distance}m`)}`;
929
+ const bytesStr = `${t.muted("Clean Bytes:")} ${t.accent(this.state.cleanBytesCollected.toString())}`;
930
+ const buffs = [];
931
+ if (this.state.activeShield) buffs.push(t.success("[SHIELD ACTIVE]"));
932
+ if (this.state.slowMotionTicks > 0) buffs.push(t.warning(`[SLOW-MO ${Math.ceil(this.state.slowMotionTicks / 10)}s]`));
933
+ if (this.state.magnetTicks > 0) buffs.push(t.secondary(`[MAGNET ${Math.ceil(this.state.magnetTicks / 10)}s]`));
934
+ if (this.state.doubleScoreTicks > 0) buffs.push(t.highlight(`[2X SCORE ${Math.ceil(this.state.doubleScoreTicks / 10)}s]`));
935
+ hudLines.push(` ${distStr} ${bytesStr} ${buffs.join(" ")}`);
936
+ hudLines.push("");
937
+ const trackWidth = 54;
938
+ const laneWidth = 18;
939
+ const trackLines = [];
940
+ trackLines.push(` ${t.border("\u250C" + "\u2500".repeat(trackWidth) + "\u2510")}`);
941
+ for (let y = 0; y < HIGHWAY_HEIGHT; y++) {
942
+ let rowContent = "";
943
+ for (let lane = 0; lane < LANE_COUNT; lane++) {
944
+ const ent = this.entities.find((e) => e.lane === lane && e.y === y);
945
+ let cellText = " ".repeat(laneWidth);
946
+ if (ent) {
947
+ let formattedLabel = ent.label;
948
+ if (ent.type === "corrupt") {
949
+ formattedLabel = t.error(ent.label);
950
+ } else if (ent.type === "clean") {
951
+ formattedLabel = t.success(ent.label);
952
+ } else if (ent.type === "powerup") {
953
+ formattedLabel = t.highlight(ent.label);
954
+ }
955
+ const cleanLen = ent.label.length;
956
+ const leftPad = Math.floor((laneWidth - cleanLen) / 2);
957
+ const rightPad = laneWidth - cleanLen - leftPad;
958
+ cellText = " ".repeat(Math.max(0, leftPad)) + formattedLabel + " ".repeat(Math.max(0, rightPad));
959
+ }
960
+ if (y === HIGHWAY_HEIGHT - 2 && lane === this.state.playerLane) {
961
+ const avatar = this.state.isJumping ? "\u25B2 [AIRBORNE] \u25B2" : "\u25B2\u2550\u2550[RUNNER]\u2550\u2550\u25B2";
962
+ const colored = this.state.activeShield ? t.highlight(avatar) : t.primary(avatar);
963
+ const pad = Math.max(0, Math.floor((laneWidth - 14) / 2));
964
+ cellText = " ".repeat(pad) + colored + " ".repeat(Math.max(0, laneWidth - 14 - pad));
965
+ }
966
+ rowContent += cellText + (lane < LANE_COUNT - 1 ? t.border("\u2506") : "");
967
+ }
968
+ trackLines.push(` ${t.border("\u2502")}${rowContent}${t.border("\u2502")}`);
969
+ }
970
+ trackLines.push(` ${t.border("\u2514" + "\u2500".repeat(trackWidth) + "\u2518")}`);
971
+ if (this.state.isGameOver) {
972
+ trackLines.push(`
973
+ ${t.error("\u{1F4A5} SYSTEM FAULT: PACKET CORRUPTED!")}`);
974
+ trackLines.push(` ${t.accent(`Final Distance: ${this.state.distance}m \u2502 Final Score: ${this.state.score}`)}`);
975
+ trackLines.push(` ${t.muted("Press R to Re-engage Runner, or Esc / Q to Exit.")}`);
976
+ } else {
977
+ trackLines.push(` ${t.muted("Controls: Left/Right: Lane \u2502 Up/Space: Jump \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
978
+ }
979
+ this.renderer.clear();
980
+ this.renderer.draw(`
981
+ ${header}
982
+ ${hudLines.join("\n")}
983
+ ${trackLines.join("\n")}
984
+ `);
985
+ }
986
+ getState() {
987
+ return this.state;
988
+ }
989
+ };
34
990
  export {
35
991
  ALL_GAMES_METADATA,
36
992
  APP_NAME,
@@ -41,6 +997,7 @@ export {
41
997
  ByteRunnerGame,
42
998
  CyberViperGame,
43
999
  DeterministicRNG,
1000
+ HashMatrixGame,
44
1001
  MIN_TERMINAL_COLUMNS,
45
1002
  MIN_TERMINAL_ROWS,
46
1003
  NeonCircuitGame,
@@ -52,6 +1009,7 @@ export {
52
1009
  TerminullEngine,
53
1010
  UserProfileSchema,
54
1011
  UserSettingsSchema,
1012
+ VoidInvadersGame,
55
1013
  checkTerminalDimensions,
56
1014
  clamp,
57
1015
  defaultAchievements,
@@ -60,7 +1018,11 @@ export {
60
1018
  defaultStorage,
61
1019
  formatTime,
62
1020
  getTheme,
63
- padCenter,
64
- playTerminalBell
1021
+ padRightVisible,
1022
+ playArcadeLoadingScreen,
1023
+ playTerminalBell,
1024
+ stripAnsi,
1025
+ visibleLength,
1026
+ wordWrap
65
1027
  };
66
1028
  //# sourceMappingURL=index.js.map