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.
@@ -29,8 +29,8 @@ var ALL_GAMES_METADATA = {
29
29
  "cyber-viper": {
30
30
  id: "cyber-viper",
31
31
  name: "Cyber Viper",
32
- tagline: "Slither through the grid, feast on energy apples, avoid your tail",
33
- description: "The definitive classic snake arcade: grow longer with every bite, snag golden bonus orbs, and test your reflexes.",
32
+ tagline: "Feast on energy apples, grow longer, avoid your tail",
33
+ description: "The definitive snake arcade: steer your viper, feast on glowing energy apples, and snag rare golden bonus orbs.",
34
34
  category: "arcade",
35
35
  difficultyLevels: ["easy", "normal", "hard", "insane"],
36
36
  controls: [
@@ -45,192 +45,43 @@ var ALL_GAMES_METADATA = {
45
45
  { id: "long_viper", title: "Anaconda Protocol", description: "Reach a snake length of 25 segments" }
46
46
  ]
47
47
  },
48
- "neon-circuit": {
49
- id: "neon-circuit",
50
- name: "Neon Circuit",
51
- tagline: "Route pure energy through node grids",
52
- description: "Pipe puzzle: rotate circuit conduits to bridge power source to target nodes before moves run out.",
53
- category: "puzzle",
54
- difficultyLevels: ["easy", "normal", "hard", "insane"],
55
- controls: [
56
- { key: "Arrow Keys / WASD", action: "Navigate Grid", description: "Move circuit cursor" },
57
- { key: "Space / Enter", action: "Rotate Tile", description: "Rotate wire 90 degrees clockwise" },
58
- { key: "R", action: "Reset Grid", description: "Reset puzzle to initial state" },
59
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
60
- ],
61
- achievements: [
62
- { id: "first_spark", title: "First Spark", description: "Complete your first circuit" },
63
- { id: "overclocked", title: "Overclocked Flow", description: "Complete a level with 5+ moves remaining" },
64
- { id: "grid_master", title: "Grid Overlord", description: "Solve an insane circuit puzzle" }
65
- ]
66
- },
67
- "byte-runner": {
68
- id: "byte-runner",
69
- name: "Byte Runner",
70
- tagline: "Sprint down the endless 3-lane packet highway",
71
- description: "High-speed lane runner: dodge obstacles, jump over blocks, collect bytes, and grab shields.",
72
- category: "arcade",
73
- difficultyLevels: ["easy", "normal", "hard", "insane"],
74
- controls: [
75
- { key: "Left / Right / A / D", action: "Change Lane", description: "Shift between 3 lanes" },
76
- { key: "Up / W / Space", action: "Phase Jump", description: "Hop over obstacles" },
77
- { key: "Down / S", action: "Dive / Slide", description: "Fast drop" },
78
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
79
- ],
80
- achievements: [
81
- { id: "packet_chaser", title: "Packet Chaser", description: "Collect 50 clean byte clusters" },
82
- { id: "shield_matrix", title: "Hardened Buffer", description: "Absorb a collision with an active shield" },
83
- { id: "hyperspeed", title: "Fiber Velocity", description: "Reach a distance score over 5,000" }
84
- ]
85
- },
86
48
  "void-invaders": {
87
49
  id: "void-invaders",
88
- name: "Void Invaders",
89
- tagline: "Defend orbital defenses against descending alien waves",
90
- description: "Classic vertical space shooter: maneuver laser gunship, blast invaders, and shoot mystery saucers.",
50
+ name: "Space Invaders",
51
+ tagline: "Shoot descending alien invaders before they hit ground",
52
+ description: "Classic space shooter: slide your cannon left and right, blast descending alien scouts, and defend earth across 3 lives.",
91
53
  category: "arcade",
92
54
  difficultyLevels: ["easy", "normal", "hard", "insane"],
93
55
  controls: [
94
- { key: "Left / Right / A / D", action: "Move Cannon", description: "Slide gunship along bottom" },
56
+ { key: "Left / Right / A / D", action: "Move Cannon", description: "Slide laser cannon" },
95
57
  { key: "Space", action: "Fire Laser", description: "Shoot plasma cannons" },
96
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
97
- ],
98
- achievements: [
99
- { id: "alien_down", title: "First Contact", description: "Destroy your first alien invader" },
100
- { id: "mothership_shot", title: "UFO Hunter", description: "Shoot down a high-value red mothership" },
101
- { id: "wave_cleared", title: "Sky Guardian", description: "Clear an entire invader armada wave" }
102
- ]
103
- },
104
- "bit-breaker": {
105
- id: "bit-breaker",
106
- name: "Bit Breaker",
107
- tagline: "Smash through walls of multi-colored arcade bricks",
108
- description: "Addictive paddle breakout: angle ricocheting balls, shatter bricks, and unleash multi-ball chaos.",
109
- category: "arcade",
110
- difficultyLevels: ["easy", "normal", "hard", "insane"],
111
- controls: [
112
- { key: "Left / Right / A / D", action: "Move Paddle", description: "Control paddle position" },
113
- { key: "Space", action: "Launch Ball", description: "Release ball from paddle" },
114
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
115
- ],
116
- achievements: [
117
- { id: "brick_crusher", title: "First Smash", description: "Break 20 arcade bricks" },
118
- { id: "paddle_virtuoso", title: "Iron Reflexes", description: "Maintain a 30-hit paddle rally" },
119
- { id: "board_clear", title: "Demolition Pro", description: "Clear an entire brick formation" }
120
- ]
121
- },
122
- "stack-tower": {
123
- id: "stack-tower",
124
- name: "Stack Tower",
125
- tagline: "Rotate and drop falling geometric blocks into complete lines",
126
- description: "The all-time classic block-stacker: clear lines, trigger 4-line combos, and survive speedups.",
127
- category: "puzzle",
128
- difficultyLevels: ["easy", "normal", "hard", "insane"],
129
- controls: [
130
- { key: "Left / Right", action: "Move Block", description: "Shift block horizontally" },
131
- { key: "Up / Space", action: "Rotate", description: "Rotate block 90 degrees" },
132
- { key: "Down", action: "Soft Drop", description: "Accelerate fall" },
133
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
134
- ],
135
- achievements: [
136
- { id: "line_clear", title: "Single Clear", description: "Clear your first horizontal line" },
137
- { id: "quad_clear", title: "Tetra Smash", description: "Clear 4 lines in a single drop" },
138
- { id: "tower_master", title: "Block Master", description: "Score over 10,000 points" }
139
- ]
140
- },
141
- "data-hopper": {
142
- id: "data-hopper",
143
- name: "Data Hopper",
144
- tagline: "Hop across busy highways and rushing rivers",
145
- description: "Frogger-style road crosser: dodge speeding traffic, leap onto floating logs, and reach home safely.",
146
- category: "arcade",
147
- difficultyLevels: ["easy", "normal", "hard", "insane"],
148
- controls: [
149
- { key: "Arrow Keys / WASD", action: "Hop Direction", description: "Leap one grid tile" },
150
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
151
- { key: "R", action: "Restart Hop", description: "Restart crossing" },
152
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
153
- ],
154
- achievements: [
155
- { id: "safe_crossing", title: "First Crossing", description: "Deliver a hopper safely home" },
156
- { id: "traffic_dodger", title: "Speedy Legs", description: "Cross the highway without stopping" },
157
- { id: "all_home", title: "Family Reunion", description: "Fill all 5 home bases" }
158
- ]
159
- },
160
- "flappy-byte": {
161
- id: "flappy-byte",
162
- name: "Flappy Byte",
163
- tagline: "Tap to flap through narrow pipe gaps",
164
- description: "Fast-paced flapping arcade: maintain altitude, navigate pipe gates, and chase high score streaks.",
165
- category: "arcade",
166
- difficultyLevels: ["easy", "normal", "hard", "insane"],
167
- controls: [
168
- { key: "Space / Up", action: "Flap Wings", description: "Thrust upward against gravity" },
169
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
170
- { key: "R", action: "Restart Flight", description: "Try again immediately" },
171
- { key: "Q", action: "Quit", description: "Return to arcade menu" }
172
- ],
173
- achievements: [
174
- { id: "first_pipe", title: "First Flight", description: "Pass your first obstacle pipe" },
175
- { id: "bronze_flyer", title: "Bronze Aviator", description: "Score 10 consecutive gates" },
176
- { id: "silver_flyer", title: "Silver Aviator", description: "Score 25 consecutive gates" }
177
- ]
178
- },
179
- "cyber-pong": {
180
- id: "cyber-pong",
181
- name: "Cyber Pong",
182
- tagline: "High-speed tennis rally against smart AI opponent",
183
- description: "The quintessential arcade rally: deflection angles, spin shots, and first to 7 points takes victory.",
184
- category: "arcade",
185
- difficultyLevels: ["easy", "normal", "hard", "insane"],
186
- controls: [
187
- { key: "Up / Down / W / S", action: "Move Paddle", description: "Adjust paddle height" },
188
58
  { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" },
189
- { key: "R", action: "Restart Match", description: "New set" },
59
+ { key: "R", action: "Restart", description: "Try again immediately" },
190
60
  { key: "Q", action: "Quit", description: "Return to arcade menu" }
191
61
  ],
192
62
  achievements: [
193
- { id: "first_point", title: "First Serve", description: "Score a point against opponent" },
194
- { id: "shutout", title: "Flawless Set", description: "Win a match without conceding a point" },
195
- { id: "rally_champion", title: "Table Sovereign", description: "Win on insane difficulty" }
63
+ { id: "alien_down", title: "First Contact", description: "Destroy your first alien invader" },
64
+ { id: "mothership_shot", title: "UFO Hunter", description: "Shoot down a high-value red mothership" },
65
+ { id: "wave_cleared", title: "Sky Guardian", description: "Clear 20 descending invaders" }
196
66
  ]
197
67
  },
198
- "meteor-drift": {
199
- id: "meteor-drift",
200
- name: "Meteor Drift",
201
- tagline: "Thrust, rotate, and blast space rocks into dust",
202
- description: "Asteroids-style space drift: 360-degree rotation, momentum thrust physics, and asteroid splitting.",
68
+ "hash-matrix": {
69
+ id: "hash-matrix",
70
+ name: "Hash Matrix",
71
+ tagline: "Hollywood hacker cascade of crypto hashes and symbols",
72
+ description: "Hypnotic hacker visualizer: random cryptographic hashes, memory hex dumps, and matrix rain streaming harmlessly across your screen.",
203
73
  category: "arcade",
204
74
  difficultyLevels: ["easy", "normal", "hard", "insane"],
205
75
  controls: [
206
- { key: "Left / Right", action: "Rotate Ship", description: "Turn ship heading" },
207
- { key: "Up / W", action: "Thrust Engine", description: "Accelerate forward" },
208
- { key: "Space", action: "Fire Cannons", description: "Blast space rocks" },
209
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
76
+ { key: "Ctrl+C / Q / Esc", action: "Exit to Menu", description: "Stop hacker stream" },
77
+ { key: "Space", action: "Freeze / Pause", description: "Pause hash cascade" },
78
+ { key: "M", action: "Switch Mode", description: "Cycle rain, hash, hex modes" },
79
+ { key: "C / T", action: "Cycle Colors", description: "Matrix green, cyan, amber, red" }
210
80
  ],
211
81
  achievements: [
212
- { id: "rock_smasher", title: "First Stardust", description: "Break your first giant asteroid" },
213
- { id: "drift_king", title: "Inertia Master", description: "Destroy 10 rocks while coasting" },
214
- { id: "sector_clear", title: "Cosmic Ace", description: "Survive 3 asteroid waves" }
215
- ]
216
- },
217
- "core-defuser": {
218
- id: "core-defuser",
219
- name: "Core Defuser",
220
- tagline: "Uncover safe tiles and flag hidden mines",
221
- description: "Classic minesweeper logic: reveal numbers, deduce danger zones, and flag every hidden explosive.",
222
- category: "puzzle",
223
- difficultyLevels: ["easy", "normal", "hard", "insane"],
224
- controls: [
225
- { key: "Arrow Keys / WASD", action: "Move Pointer", description: "Inspect grid cells" },
226
- { key: "Space", action: "Reveal Cell", description: "Uncover target cell" },
227
- { key: "F", action: "Flag Mine", description: "Mark dangerous tile" },
228
- { key: "Esc / P", action: "Pause Menu", description: "Open pause dialog" }
229
- ],
230
- achievements: [
231
- { id: "safe_step", title: "First Discovery", description: "Reveal a cell with zero casualties" },
232
- { id: "flag_master", title: "EOD Technician", description: "Flag 5 real mines correctly" },
233
- { id: "grid_defused", title: "Bomb Squad Master", description: "Complete a minefield without detonation" }
82
+ { id: "first_breach", title: "Script Kiddie", description: "Run the hacker stream for 10 seconds" },
83
+ { id: "hash_miner", title: "Crypto Sovereign", description: "Compute 5,000 hashes in one session" },
84
+ { id: "matrix_unlocked", title: "The White Rabbit", description: "Cycle through all visual modes" }
234
85
  ]
235
86
  }
236
87
  };
@@ -605,14 +456,20 @@ var TerminalRenderer = class {
605
456
  }
606
457
  createBox(lines, width = 76, title = "") {
607
458
  const t = this.currentTheme;
608
- const topBarLen = Math.max(0, width - 4 - (title ? title.length + 2 : 0));
459
+ const topBarLen = Math.max(0, width - 3 - (title ? title.length + 2 : 0));
609
460
  const titleSection = title ? ` ${t.primary(title)} ` : "";
610
461
  const top = t.border(`\u250C\u2500${titleSection}${"\u2500".repeat(topBarLen)}\u2510`);
611
462
  const bottom = t.border(`\u2514${"\u2500".repeat(width - 2)}\u2518`);
463
+ const maxInner = width - 4;
612
464
  const middle = lines.map((line) => {
613
- const cleanLen = line.replace(/\x1b\[[0-9;]*m/g, "").length;
614
- const padLen = Math.max(0, width - 4 - cleanLen);
615
- return `${t.border("\u2502")} ${line}${" ".repeat(padLen)}${t.border("\u2502")}`;
465
+ let content = line;
466
+ const cleanLen = content.replace(/\x1b\[[0-9;]*m/g, "").length;
467
+ if (cleanLen > maxInner) {
468
+ content = content.slice(0, content.length - (cleanLen - maxInner));
469
+ }
470
+ const finalCleanLen = content.replace(/\x1b\[[0-9;]*m/g, "").length;
471
+ const padLen = Math.max(0, maxInner - finalCleanLen);
472
+ return `${t.border("\u2502")} ${content}${" ".repeat(padLen)}${t.border("\u2502")}`;
616
473
  });
617
474
  return [top, ...middle, bottom].join("\n");
618
475
  }
@@ -880,14 +737,121 @@ function formatTime(seconds) {
880
737
  function clamp(val, min, max) {
881
738
  return Math.max(min, Math.min(max, val));
882
739
  }
883
- function padCenter(str, width) {
884
- if (str.length >= width) return str.slice(0, width);
885
- const left = Math.floor((width - str.length) / 2);
886
- const right = width - str.length - left;
887
- return " ".repeat(left) + str + " ".repeat(right);
740
+ function stripAnsi(str) {
741
+ return str.replace(/\x1b\[[0-9;]*m/g, "");
742
+ }
743
+ function visibleLength(str) {
744
+ return stripAnsi(str).length;
745
+ }
746
+ function padRightVisible(str, targetWidth) {
747
+ const vLen = stripAnsi(str).length;
748
+ if (vLen >= targetWidth) return str;
749
+ return str + " ".repeat(targetWidth - vLen);
750
+ }
751
+ function wordWrap(text, maxWidth) {
752
+ const words = text.split(" ");
753
+ const lines = [];
754
+ let current = "";
755
+ for (const word of words) {
756
+ if (!current) {
757
+ current = word;
758
+ } else if (stripAnsi(current + " " + word).length <= maxWidth) {
759
+ current += " " + word;
760
+ } else {
761
+ lines.push(current);
762
+ current = word;
763
+ }
764
+ }
765
+ if (current) lines.push(current);
766
+ return lines;
888
767
  }
889
768
 
890
769
  // src/core/menu.ts
770
+ import chalk2 from "chalk";
771
+ var HACKER_STAGE_1 = [
772
+ "ACCESSING ORBITAL DEFENSE SATELLITE...",
773
+ "LOCATING PENTAGON FIBER-OPTIC TRUNK...",
774
+ "CONNECTING TO ENCRYPTED SWISS BANK NODE...",
775
+ "INTERCEPTING TOP-SECRET NASA RADAR...",
776
+ "ESTABLISHING SECURE PROXY IN BERMUDA...",
777
+ "PINGING DEEP-SEA MILITARY SUBMARINE..."
778
+ ];
779
+ var HACKER_STAGE_2 = [
780
+ "HACKING INTO FBI MAINFRAME... [BYPASS OK]",
781
+ "DOWNLOADING 64GB OF EXTRA CLOUD RAM...",
782
+ "OVERCLOCKING POTATO POWERED CPU TO 5.0 GHz...",
783
+ "CRACKING AREA 51 ALIEN ENCRYPTION CODES...",
784
+ "DISABLING NSA COVERT SURVEILLANCE CAMERAS...",
785
+ "MINING BITCOIN ON SMART REFRIGERATOR..."
786
+ ];
787
+ var HACKER_STAGE_3 = [
788
+ "RE-ROUTING POWER FROM FLUX CAPACITOR...",
789
+ "ORDERING EXTRA PEPPERONI PIZZA VIA CMD...",
790
+ "INVERTING WARP TACHYON EMITTERS...",
791
+ "BRIBERY ATTEMPT: SENDING MEMES TO SYSTEM ADMIN...",
792
+ "SPOOFING IP ADDRESS TO 127.0.0.1 (WAIT WHAT)...",
793
+ "CONVERTING COFFEE DIRECTLY INTO MACHINE CODE..."
794
+ ];
795
+ var HACKER_STAGE_4 = [
796
+ "BYPASSING FINAL FIREWALL WITH ELECTRIC TOASTER...",
797
+ "OVERRIDING MAINFRAME AIR CONDITIONING...",
798
+ "DELETING SEARCH BROWSER HISTORY JUST IN CASE...",
799
+ "INITIALIZING 80s HOLLYWOOD KEYBOARD TYPING...",
800
+ "ARMING RETRO PHOSPHOR SCANLINE CANNONS...",
801
+ "QUANTUM KERNEL COMPILED: ACCESS GRANTED..."
802
+ ];
803
+ var HACKER_STAGE_5 = [
804
+ "WE ARE IN! FULL ROOT ACCESS GRANTED!",
805
+ "MATRIX BREACHED! LAUNCHING SYSTEM NOW!",
806
+ "SECURITY PROTOCOLS CRACKED! WE HAVE TAKEOVER!",
807
+ "MAINFRAME BYPASSED! WELCOME TO THE MATRIX!"
808
+ ];
809
+ async function playArcadeLoadingScreen(game, renderer = defaultRenderer, storage = defaultStorage) {
810
+ const profile = storage.getProfile();
811
+ if (profile.settings.reducedMotion) return;
812
+ const t = renderer.getTheme();
813
+ const width = 74;
814
+ const barWidth = 36;
815
+ const tips = {
816
+ "packet-man": "Tip: Grab Super Capacitors to hunt blue daemons for combos!",
817
+ "cyber-viper": "Tip: Snag rare golden bonus orbs quickly for 5x points!",
818
+ "void-invaders": "Tip: Blast descending aliens before they touch ground! 3 lives.",
819
+ "hash-matrix": "Tip: Press Space to freeze stream, M for mode, C for color theme!"
820
+ };
821
+ const tip = tips[game.id] || "Tip: Press Esc or P at any time to pause or access settings.";
822
+ const pick = (arr) => arr[Math.floor(Math.random() * arr.length)];
823
+ const steps = [
824
+ { fill: 6, pct: 15, label: pick(HACKER_STAGE_1), delay: 350 },
825
+ { fill: 14, pct: 40, label: pick(HACKER_STAGE_2), delay: 350 },
826
+ { fill: 23, pct: 65, label: pick(HACKER_STAGE_3), delay: 350 },
827
+ { fill: 31, pct: 85, label: pick(HACKER_STAGE_4), delay: 350 },
828
+ { fill: 36, pct: 100, label: pick(HACKER_STAGE_5), delay: 400 }
829
+ ];
830
+ for (const step of steps) {
831
+ const bar = "\u2588".repeat(step.fill) + "\u2591".repeat(barWidth - step.fill);
832
+ const title = ` INITIALIZING: ${game.name.toUpperCase()} `;
833
+ const meter = `[${bar}] ${step.pct.toString().padStart(3)}%`;
834
+ const status = step.label;
835
+ const innerLines = [
836
+ "",
837
+ " ".repeat(Math.max(0, Math.floor((width - 4 - title.length) / 2))) + t.highlight(title),
838
+ "",
839
+ " ".repeat(Math.max(0, Math.floor((width - 4 - meter.length) / 2))) + t.primary(meter),
840
+ " ".repeat(Math.max(0, Math.floor((width - 4 - status.length) / 2))) + t.secondary(status),
841
+ "",
842
+ " ".repeat(Math.max(0, Math.floor((width - 4 - tip.length) / 2))) + t.muted(tip),
843
+ ""
844
+ ];
845
+ const box = renderer.createBox(innerLines, width, "TERMINULL ARCADE SYSTEM");
846
+ renderer.draw(`
847
+
848
+
849
+ ${box}
850
+
851
+ `);
852
+ await new Promise((r) => setTimeout(r, step.delay));
853
+ }
854
+ }
891
855
  var ArcadeMenu = class {
892
856
  storage;
893
857
  achievements;
@@ -899,6 +863,8 @@ var ArcadeMenu = class {
899
863
  currentTab = "arcade";
900
864
  selectedDifficulty = "normal";
901
865
  onSelectCallback = null;
866
+ animTimer = null;
867
+ animFrame = 0;
902
868
  constructor(storage = defaultStorage, achievements = defaultAchievements, renderer = defaultRenderer) {
903
869
  this.storage = storage;
904
870
  this.achievements = achievements;
@@ -911,18 +877,34 @@ var ArcadeMenu = class {
911
877
  this.renderer.setTheme(profile.settings.theme);
912
878
  this.renderer.enterScreen();
913
879
  this.render();
880
+ if (!profile.settings.reducedMotion) {
881
+ this.animTimer = setInterval(() => {
882
+ this.animFrame = (this.animFrame + 1) % 2;
883
+ this.render();
884
+ }, 700);
885
+ }
914
886
  this.input.start(
915
887
  (key) => this.handleInput(key),
916
888
  () => {
917
- this.renderer.exitScreen();
889
+ this.close();
918
890
  process.exit(0);
919
891
  }
920
892
  );
921
893
  }
922
894
  close() {
895
+ if (this.animTimer) {
896
+ clearInterval(this.animTimer);
897
+ this.animTimer = null;
898
+ }
923
899
  this.input.stop();
924
900
  this.renderer.exitScreen();
925
901
  }
902
+ ringBell() {
903
+ const profile = this.storage.getProfile();
904
+ if (profile.settings.soundEnabled) {
905
+ process.stdout.write("\x07");
906
+ }
907
+ }
926
908
  getFilteredGames() {
927
909
  const all = Object.values(ALL_GAMES_METADATA);
928
910
  if (!this.searchQuery.trim()) return all;
@@ -931,6 +913,22 @@ var ArcadeMenu = class {
931
913
  (g) => g.name.toLowerCase().includes(q) || g.category.toLowerCase().includes(q) || g.id.toLowerCase().includes(q) || g.description.toLowerCase().includes(q)
932
914
  );
933
915
  }
916
+ async triggerLaunch(game) {
917
+ if (this.animTimer) {
918
+ clearInterval(this.animTimer);
919
+ this.animTimer = null;
920
+ }
921
+ this.input.stop();
922
+ this.ringBell();
923
+ await playArcadeLoadingScreen(game, this.renderer, this.storage);
924
+ if (this.onSelectCallback) {
925
+ this.onSelectCallback({
926
+ action: "play",
927
+ gameId: game.id,
928
+ difficulty: this.selectedDifficulty
929
+ });
930
+ }
931
+ }
934
932
  handleInput(key) {
935
933
  const filtered = this.getFilteredGames();
936
934
  if (this.isSearching) {
@@ -950,33 +948,62 @@ var ArcadeMenu = class {
950
948
  const tabs = ["arcade", "stats", "settings"];
951
949
  const nextIdx = (tabs.indexOf(this.currentTab) + 1) % tabs.length;
952
950
  this.currentTab = tabs[nextIdx];
951
+ this.ringBell();
953
952
  this.render();
954
953
  return;
955
954
  }
956
955
  if (this.currentTab === "arcade") {
957
- if (key.name === "up" || key.name === "k") {
956
+ const num = parseInt(key.sequence || key.name, 10);
957
+ if (!isNaN(num) && num >= 1 && num <= filtered.length) {
958
+ const targetIdx = num - 1;
959
+ const targetGame = filtered[targetIdx];
960
+ if (targetGame) {
961
+ if (this.selectedIndex === targetIdx) {
962
+ this.triggerLaunch(targetGame);
963
+ return;
964
+ }
965
+ this.selectedIndex = targetIdx;
966
+ this.ringBell();
967
+ this.render();
968
+ return;
969
+ }
970
+ }
971
+ if (key.name === "up" || key.name === "w" || key.name === "k") {
958
972
  this.selectedIndex = (this.selectedIndex - 1 + filtered.length) % Math.max(1, filtered.length);
973
+ this.ringBell();
959
974
  this.render();
960
- } else if (key.name === "down" || key.name === "j") {
975
+ } else if (key.name === "down" || key.name === "s" || key.name === "j") {
961
976
  this.selectedIndex = (this.selectedIndex + 1) % Math.max(1, filtered.length);
977
+ this.ringBell();
962
978
  this.render();
963
- } else if (key.name === "d") {
979
+ } else if (key.name === "d" || key.sequence === "d") {
964
980
  const diffs = ["easy", "normal", "hard", "insane"];
965
981
  const curr = diffs.indexOf(this.selectedDifficulty);
966
982
  this.selectedDifficulty = diffs[(curr + 1) % diffs.length];
983
+ this.ringBell();
984
+ this.render();
985
+ } else if (key.name === "t" || key.sequence === "t") {
986
+ const themes = ["default", "retro-green", "neon", "minimal", "high-contrast"];
987
+ const profile = this.storage.getProfile();
988
+ const currIdx = themes.indexOf(profile.settings.theme);
989
+ const nextTheme = themes[(currIdx + 1) % themes.length];
990
+ this.storage.updateSettings({ theme: nextTheme });
991
+ this.renderer.setTheme(nextTheme);
992
+ this.ringBell();
993
+ this.render();
994
+ } else if (key.name === "b" || key.sequence === "b") {
995
+ const profile = this.storage.getProfile();
996
+ const nextVal = !profile.settings.soundEnabled;
997
+ this.storage.updateSettings({ soundEnabled: nextVal });
998
+ if (nextVal) this.ringBell();
967
999
  this.render();
968
1000
  } else if (key.name === "slash" || key.sequence === "/") {
969
1001
  this.isSearching = true;
970
1002
  this.render();
971
1003
  } else if (key.name === "return" || key.name === "space") {
972
1004
  const game = filtered[this.selectedIndex];
973
- if (game && this.onSelectCallback) {
974
- this.input.stop();
975
- this.onSelectCallback({
976
- action: "play",
977
- gameId: game.id,
978
- difficulty: this.selectedDifficulty
979
- });
1005
+ if (game) {
1006
+ this.triggerLaunch(game);
980
1007
  }
981
1008
  } else if (key.name === "q") {
982
1009
  this.close();
@@ -992,10 +1019,13 @@ var ArcadeMenu = class {
992
1019
  const nextTheme = themes[(currIdx + 1) % themes.length];
993
1020
  this.storage.updateSettings({ theme: nextTheme });
994
1021
  this.renderer.setTheme(nextTheme);
1022
+ this.ringBell();
995
1023
  this.render();
996
1024
  } else if (key.name === "b") {
997
1025
  const profile = this.storage.getProfile();
998
- this.storage.updateSettings({ soundEnabled: !profile.settings.soundEnabled });
1026
+ const nextVal = !profile.settings.soundEnabled;
1027
+ this.storage.updateSettings({ soundEnabled: nextVal });
1028
+ if (nextVal) this.ringBell();
999
1029
  this.render();
1000
1030
  } else if (key.name === "m") {
1001
1031
  const profile = this.storage.getProfile();
@@ -1013,11 +1043,11 @@ var ArcadeMenu = class {
1013
1043
  }
1014
1044
  }
1015
1045
  render() {
1016
- const t = this.renderer.getTheme();
1017
1046
  const { width, height } = this.renderer.isWindowAdequate();
1018
- if (width < 80 || height < 24) {
1019
- this.renderer.clear();
1020
- this.renderer.draw(this.renderer.renderSizeWarning());
1047
+ if (!width || !height) {
1048
+ this.renderer.draw(
1049
+ this.renderer.renderHeader({ title: APP_NAME }) + chalk2.redBright("\n\n Terminal window size too small!\n Please resize to at least 80x24.\n")
1050
+ );
1021
1051
  return;
1022
1052
  }
1023
1053
  let body = "";
@@ -1028,45 +1058,89 @@ var ArcadeMenu = class {
1028
1058
  } else if (this.currentTab === "settings") {
1029
1059
  body = this.renderSettingsTab();
1030
1060
  }
1031
- this.renderer.clear();
1032
1061
  this.renderer.draw(body);
1033
1062
  }
1063
+ renderFunkyBanner() {
1064
+ const t = this.renderer.getTheme();
1065
+ const profile = this.storage.getProfile();
1066
+ const themeName = profile.settings.theme;
1067
+ let row12Color = t.highlight;
1068
+ let row34Color = t.secondary;
1069
+ let row56Color = t.muted;
1070
+ if (themeName === "default") {
1071
+ row12Color = (str) => chalk2.cyanBright.bold(str);
1072
+ row34Color = (str) => chalk2.magentaBright.bold(str);
1073
+ row56Color = (str) => chalk2.gray(str);
1074
+ } else if (themeName === "retro-green") {
1075
+ row12Color = (str) => chalk2.greenBright.bold(str);
1076
+ row34Color = (str) => chalk2.green.bold(str);
1077
+ row56Color = (str) => chalk2.hex("#1f5f1f")(str);
1078
+ } else if (themeName === "neon") {
1079
+ row12Color = (str) => chalk2.hex("#00ffff").bold(str);
1080
+ row34Color = (str) => chalk2.hex("#ff007f").bold(str);
1081
+ row56Color = (str) => chalk2.hex("#553377")(str);
1082
+ } else if (themeName === "minimal") {
1083
+ row12Color = (str) => chalk2.whiteBright.bold(str);
1084
+ row34Color = (str) => chalk2.white(str);
1085
+ row56Color = (str) => chalk2.gray(str);
1086
+ } else if (themeName === "high-contrast") {
1087
+ row12Color = (str) => chalk2.yellowBright.bold(str);
1088
+ row34Color = (str) => chalk2.cyanBright.bold(str);
1089
+ row56Color = (str) => chalk2.white(str);
1090
+ }
1091
+ const bannerLines = [
1092
+ row12Color(` \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 `),
1093
+ row12Color(` \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1094
+ row34Color(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1095
+ row34Color(` \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1096
+ row56Color(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557`),
1097
+ row56Color(` \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D`),
1098
+ ` ${t.accent(APP_TAGLINE)} \u2502 ${t.muted("Tab: Switch Views \u2502 /: Search \u2502 Q: Quit")}`,
1099
+ ` ${t.border("\u2500".repeat(74))}`
1100
+ ];
1101
+ return bannerLines.join("\n");
1102
+ }
1103
+ renderDifficultyBadge(diff) {
1104
+ if (diff === "easy") return chalk2.greenBright("[ EASY ]");
1105
+ if (diff === "normal") return chalk2.cyanBright("[ NORMAL ]");
1106
+ if (diff === "hard") return chalk2.yellowBright("[ HARD ]");
1107
+ return chalk2.redBright.bold("[ INSANE ]");
1108
+ }
1034
1109
  renderArcadeTab() {
1035
1110
  const t = this.renderer.getTheme();
1036
1111
  const filtered = this.getFilteredGames();
1037
1112
  const activeGame = filtered[this.selectedIndex];
1038
1113
  const profile = this.storage.getProfile();
1039
- const banner = [
1040
- t.highlight(` \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 `),
1041
- t.highlight(` \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1042
- t.primary(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1043
- t.secondary(` \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 `),
1044
- t.muted(` \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557`),
1045
- t.muted(` \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D`),
1046
- ` ${t.accent(APP_TAGLINE)} \u2502 ${t.muted("Tab: Switch Views \u2502 /: Search \u2502 Q: Quit")}`,
1047
- ` ${t.border("\u2500".repeat(74))}`
1048
- ].join("\n");
1114
+ const banner = this.renderFunkyBanner();
1049
1115
  const tabs = ` ${t.highlight("[ 1. ARCADE ]")} ${t.muted("[ 2. STATS (Tab) ]")} ${t.muted("[ 3. SETTINGS (Tab) ]")}
1050
1116
  `;
1051
1117
  const searchBar = this.isSearching ? ` ${t.warning("SEARCH >")} ${this.searchQuery}\u2588
1052
1118
  ` : this.searchQuery ? ` ${t.muted("Filtered by:")} "${this.searchQuery}" (Press / to edit)
1053
1119
  ` : "";
1054
- const listLines = [];
1055
- const maxVisible = 10;
1056
- const startIndex = Math.max(0, Math.min(this.selectedIndex - 4, filtered.length - maxVisible));
1057
- const visibleGames = filtered.slice(startIndex, startIndex + maxVisible);
1058
- for (let i = 0; i < visibleGames.length; i++) {
1059
- const g = visibleGames[i];
1060
- const realIndex = startIndex + i;
1061
- const isSelected = realIndex === this.selectedIndex;
1120
+ const listLines = ["", t.highlight("ARCADE SELECTION:")];
1121
+ for (let i = 0; i < filtered.length; i++) {
1122
+ const g = filtered[i];
1123
+ const isSelected = i === this.selectedIndex;
1062
1124
  const high = profile.highScores[g.id] || 0;
1063
1125
  const highStr = high > 0 ? t.accent(`\u2605 ${high}`) : t.muted("\u2014");
1126
+ const numBadge = `[${i + 1}]`;
1127
+ const label = `${numBadge} ${g.name}`.padEnd(19);
1064
1128
  if (isSelected) {
1065
- listLines.push(t.primary(` \u25B6 ${t.highlight(g.name.padEnd(16))} ${t.secondary(`[${g.category}]`)} ${highStr}`));
1129
+ listLines.push(t.primary(` \u25B6 ${t.highlight(label)} ${highStr}`));
1066
1130
  } else {
1067
- listLines.push(t.muted(` ${g.name.padEnd(16)} [${g.category}] ${highStr}`));
1131
+ listLines.push(t.muted(` ${label} ${highStr}`));
1068
1132
  }
1069
1133
  }
1134
+ listLines.push("");
1135
+ listLines.push(t.border("\u2500\u2500 QUICK CONTROLS \u2500\u2500\u2500\u2500"));
1136
+ listLines.push(` ${t.primary("[1-4]")} ${t.muted("Select / Play")}`);
1137
+ listLines.push(` ${t.secondary("[D]")} ${this.renderDifficultyBadge(this.selectedDifficulty)}`);
1138
+ listLines.push(` ${t.accent("[T]")} ${t.muted("Theme:")} ${t.highlight(profile.settings.theme.toUpperCase())}`);
1139
+ listLines.push(` ${t.muted("[B] Sound:")} ${profile.settings.soundEnabled ? t.success("ON") : t.muted("OFF")}`);
1140
+ listLines.push(` ${t.muted("[Tab] Pilot Dossier")}`);
1141
+ while (listLines.length < 13) {
1142
+ listLines.push("");
1143
+ }
1070
1144
  const detailLines = [];
1071
1145
  if (activeGame) {
1072
1146
  const high = profile.highScores[activeGame.id] || 0;
@@ -1075,15 +1149,19 @@ var ArcadeMenu = class {
1075
1149
  const achs = this.achievements.getAchievementsForGame(activeGame.id);
1076
1150
  const unlockedAchs = achs.filter((a) => a.unlocked).length;
1077
1151
  detailLines.push(t.highlight(activeGame.name.toUpperCase()));
1078
- detailLines.push(t.secondary(activeGame.tagline));
1152
+ for (const line of wordWrap(activeGame.tagline, 40)) {
1153
+ detailLines.push(t.secondary(line));
1154
+ }
1079
1155
  detailLines.push("");
1080
- detailLines.push(activeGame.description);
1156
+ for (const line of wordWrap(activeGame.description, 40)) {
1157
+ detailLines.push(line);
1158
+ }
1081
1159
  detailLines.push("");
1082
- detailLines.push(`${t.muted("Personal Best:")} ${t.accent(high.toString())} ${t.muted("Runs:")} ${plays} ${t.muted("Time:")} ${formatTime(timeSec)}`);
1083
- detailLines.push(`${t.muted("Difficulty:")} ${t.secondary(this.selectedDifficulty.toUpperCase())} ${t.muted("(Press D to cycle)")}`);
1160
+ detailLines.push(`${t.muted("Best:")} ${t.accent(high.toString())} ${t.muted("Runs:")} ${plays} ${t.muted("Time:")} ${formatTime(timeSec)}`);
1161
+ detailLines.push(`${t.muted("Difficulty:")} ${this.renderDifficultyBadge(this.selectedDifficulty)}`);
1084
1162
  detailLines.push(`${t.muted("Achievements:")} ${unlockedAchs}/${achs.length} unlocked`);
1085
1163
  detailLines.push("");
1086
- detailLines.push(t.muted("Primary Controls:"));
1164
+ detailLines.push(t.muted("Controls:"));
1087
1165
  for (const ctrl of activeGame.controls.slice(0, 3)) {
1088
1166
  detailLines.push(` ${t.primary(ctrl.key.padEnd(14))} ${ctrl.action}`);
1089
1167
  }
@@ -1093,13 +1171,13 @@ var ArcadeMenu = class {
1093
1171
  const combinedLines = [];
1094
1172
  const maxRows = Math.max(listLines.length, detailBoxLines.length);
1095
1173
  for (let r = 0; r < maxRows; r++) {
1096
- const left = (listLines[r] || "").padEnd(32);
1174
+ const left = padRightVisible(listLines[r] || "", 30);
1097
1175
  const right = detailBoxLines[r] || "";
1098
1176
  combinedLines.push(` ${left} ${right}`);
1099
1177
  }
1100
1178
  const footer = [
1101
1179
  ` ${t.border("\u2500".repeat(74))}`,
1102
- ` ${t.primary("Enter/Space")}: Launch Game \u2502 ${t.secondary("Up/Down")}: Select \u2502 ${t.accent("D")}: Difficulty \u2502 ${t.muted("Q")}: Exit`
1180
+ ` ${t.primary("Enter/Space")}: Play \u2502 ${t.secondary("1-4")}: Select \u2502 ${t.accent("D")}: Difficulty \u2502 ${t.primary("T")}: Theme \u2502 ${t.muted("Q")}: Exit`
1103
1181
  ].join("\n");
1104
1182
  return `
1105
1183
  ${banner}
@@ -1128,10 +1206,10 @@ ${footer}
1128
1206
  "",
1129
1207
  `${t.muted("Total High Score Cumulative:")} ${t.accent(totalScore.toLocaleString())}`,
1130
1208
  `${t.muted("Total Play Sessions:")} ${t.primary(totalPlays.toString())}`,
1131
- `${t.muted("Total Time Beyond Prompt:")} ${t.secondary(formatTime(totalTime))}`,
1209
+ `${t.muted("Total Time Played:")} ${t.secondary(formatTime(totalTime))}`,
1132
1210
  `${t.muted("Global Achievements:")} ${t.success(`${unlockedCount} / ${totalCount} (${percentage}%)`)}`,
1133
1211
  "",
1134
- t.highlight("PER-GAME ARCHIVE:"),
1212
+ t.highlight("ARCADE HIGH SCORES:"),
1135
1213
  ...Object.values(ALL_GAMES_METADATA).map((g) => {
1136
1214
  const score = profile.highScores[g.id] || 0;
1137
1215
  const plays = profile.playCounts[g.id] || 0;
@@ -1232,32 +1310,64 @@ var DeterministicRNG = class {
1232
1310
  }
1233
1311
  };
1234
1312
 
1235
- // src/games/neon-circuit/index.ts
1236
- var NeonCircuitGame = class {
1237
- id = "neon-circuit";
1238
- metadata = ALL_GAMES_METADATA["neon-circuit"];
1313
+ // src/games/packet-man/index.ts
1314
+ var MAZE_TEMPLATE = [
1315
+ "###########################",
1316
+ "#............#............#",
1317
+ "#.####.#####.#.#####.####.#",
1318
+ "#O####.#####.#.#####.####O#",
1319
+ "#.####.#####.#.#####.####.#",
1320
+ "#.........................#",
1321
+ "#.####.##.#######.##.####.#",
1322
+ "#......##....#....##......#",
1323
+ "######.##### # #####.######",
1324
+ " #.# #.# ",
1325
+ "######.# ###---### #.######",
1326
+ "#......# # # #......#",
1327
+ "#.####.# ######### #.####.#",
1328
+ "#O..##...............##..O#",
1329
+ "###.##.##.#######.##.##.###",
1330
+ "#......##....#....##......#",
1331
+ "#.##########.#.##########.#",
1332
+ "#.........................#",
1333
+ "###########################"
1334
+ ];
1335
+ var MAZE_WIDTH = 27;
1336
+ var MAZE_HEIGHT = 19;
1337
+ var PacketManGame = class {
1338
+ id = "packet-man";
1339
+ metadata = ALL_GAMES_METADATA["packet-man"];
1239
1340
  config = null;
1240
1341
  renderer = defaultRenderer;
1241
1342
  input = new TerminalInputHandler();
1242
1343
  rng = new DeterministicRNG();
1344
+ gameLoopTimer = null;
1345
+ grid = [];
1346
+ daemons = [];
1347
+ daemonsChompedInSurge = 0;
1348
+ pelletsEatenCount = 0;
1243
1349
  state = {
1244
- grid: [],
1245
- width: 5,
1246
- height: 5,
1247
- cursorX: 0,
1248
- cursorY: 0,
1249
- movesRemaining: 25,
1250
- maxMoves: 25,
1350
+ playerX: 13,
1351
+ playerY: 13,
1352
+ playerDx: 0,
1353
+ playerDy: 0,
1354
+ desiredDx: 0,
1355
+ desiredDy: 0,
1356
+ mouthOpen: true,
1357
+ lives: 3,
1251
1358
  score: 0,
1252
1359
  level: 1,
1253
- targetsRemaining: 1,
1254
- totalTargets: 1,
1360
+ pelletsRemaining: 0,
1361
+ totalPellets: 0,
1362
+ frightenedTicksRemaining: 0,
1363
+ frightenedCombo: 0,
1255
1364
  isWon: false,
1256
1365
  isGameOver: false
1257
1366
  };
1258
1367
  isPaused = false;
1259
1368
  pauseMenuIndex = 0;
1260
1369
  showTutorial = true;
1370
+ tickIntervalMs = 150;
1261
1371
  init(config) {
1262
1372
  this.config = config;
1263
1373
  this.renderer.setTheme(config.theme);
@@ -1265,7 +1375,7 @@ var NeonCircuitGame = class {
1265
1375
  if (config.skipTutorial !== void 0) {
1266
1376
  this.showTutorial = !config.skipTutorial;
1267
1377
  }
1268
- this.setupLevel(1, config.difficulty);
1378
+ this.resetGame(1, config.difficulty);
1269
1379
  }
1270
1380
  start() {
1271
1381
  this.isPaused = false;
@@ -1277,236 +1387,357 @@ var NeonCircuitGame = class {
1277
1387
  process.exit(0);
1278
1388
  }
1279
1389
  );
1390
+ this.scheduleNextTick();
1280
1391
  }
1281
1392
  pause() {
1282
1393
  this.isPaused = true;
1394
+ if (this.gameLoopTimer) {
1395
+ clearTimeout(this.gameLoopTimer);
1396
+ this.gameLoopTimer = null;
1397
+ }
1283
1398
  }
1284
1399
  resume() {
1285
1400
  this.isPaused = false;
1401
+ this.scheduleNextTick();
1286
1402
  this.render();
1287
1403
  }
1288
1404
  restart() {
1289
1405
  if (this.config) {
1290
- this.state.score = 0;
1291
- this.setupLevel(1, this.config.difficulty);
1406
+ this.resetGame(1, this.config.difficulty);
1407
+ this.scheduleNextTick();
1292
1408
  this.render();
1293
1409
  }
1294
1410
  }
1295
1411
  saveState() {
1296
1412
  return {
1297
1413
  state: this.state,
1414
+ grid: this.grid,
1415
+ daemons: this.daemons,
1298
1416
  showTutorial: this.showTutorial
1299
1417
  };
1300
1418
  }
1301
1419
  loadState(saved) {
1302
- if (saved["state"]) {
1303
- this.state = saved["state"];
1304
- }
1305
- if (saved["showTutorial"] !== void 0) {
1306
- this.showTutorial = !!saved["showTutorial"];
1307
- }
1308
- this.updatePowerFlow();
1420
+ if (saved["state"]) this.state = saved["state"];
1421
+ if (saved["grid"]) this.grid = saved["grid"];
1422
+ if (saved["daemons"]) this.daemons = saved["daemons"];
1423
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
1309
1424
  }
1310
1425
  destroy() {
1426
+ if (this.gameLoopTimer) {
1427
+ clearTimeout(this.gameLoopTimer);
1428
+ this.gameLoopTimer = null;
1429
+ }
1311
1430
  this.input.stop();
1312
1431
  }
1313
- setupLevel(level, difficulty) {
1314
- let size = 5;
1315
- let moves = 20;
1432
+ resetGame(level, difficulty) {
1316
1433
  switch (difficulty) {
1317
1434
  case "easy":
1318
- size = 4;
1319
- moves = 25;
1435
+ this.tickIntervalMs = 175;
1320
1436
  break;
1321
1437
  case "normal":
1322
- size = 5;
1323
- moves = 22;
1438
+ this.tickIntervalMs = 145;
1324
1439
  break;
1325
1440
  case "hard":
1326
- size = 6;
1327
- moves = 20;
1441
+ this.tickIntervalMs = 120;
1328
1442
  break;
1329
1443
  case "insane":
1330
- size = 7;
1331
- moves = 18;
1444
+ this.tickIntervalMs = 95;
1332
1445
  break;
1333
1446
  }
1334
- this.state.width = size;
1335
- this.state.height = size;
1336
- this.state.level = level;
1337
- this.state.maxMoves = moves;
1338
- this.state.movesRemaining = moves;
1339
- this.state.cursorX = 0;
1340
- this.state.cursorY = 0;
1341
- this.state.isWon = false;
1342
- this.state.isGameOver = false;
1343
- const grid = [];
1344
- for (let y = 0; y < size; y++) {
1345
- const row = [];
1346
- for (let x = 0; x < size; x++) {
1347
- row.push(this.createRandomTile(x, y, size, difficulty));
1348
- }
1349
- row.push();
1350
- grid.push(row);
1351
- }
1352
- grid[0][0] = {
1353
- type: "source",
1354
- rotation: 0,
1355
- baseConnections: [false, true, true, false],
1356
- currentConnections: [false, true, true, false],
1357
- isPowered: true,
1358
- isFixed: true
1359
- };
1360
- grid[size - 1][size - 1] = {
1361
- type: "target",
1362
- rotation: 0,
1363
- baseConnections: [true, false, false, true],
1364
- currentConnections: [true, false, false, true],
1365
- isPowered: false,
1366
- isFixed: true
1367
- };
1368
- if (difficulty === "insane") {
1369
- grid[0][size - 1] = {
1370
- type: "target",
1371
- rotation: 0,
1372
- baseConnections: [false, false, true, true],
1373
- currentConnections: [false, false, true, true],
1374
- isPowered: false,
1375
- isFixed: true
1376
- };
1377
- this.state.totalTargets = 2;
1378
- this.state.targetsRemaining = 2;
1379
- } else {
1380
- this.state.totalTargets = 1;
1381
- this.state.targetsRemaining = 1;
1382
- }
1383
- this.state.grid = grid;
1384
- this.updatePowerFlow();
1385
- }
1386
- createRandomTile(x, y, size, difficulty) {
1387
- if ((difficulty === "hard" || difficulty === "insane") && this.rng.next() < 0.12 && (x > 0 || y > 0)) {
1388
- return {
1389
- type: "blocked",
1390
- rotation: 0,
1391
- baseConnections: [false, false, false, false],
1392
- currentConnections: [false, false, false, false],
1393
- isPowered: false,
1394
- isFixed: true
1395
- };
1396
- }
1397
- const roll = this.rng.next();
1398
- let type = "corner";
1399
- let base = [true, true, false, false];
1400
- if (roll < 0.4) {
1401
- type = "straight";
1402
- base = [true, false, true, false];
1403
- } else if (roll < 0.75) {
1404
- type = "corner";
1405
- base = [true, true, false, false];
1406
- } else if (roll < 0.92) {
1407
- type = "t-shape";
1408
- base = [true, true, false, true];
1409
- } else {
1410
- type = "cross";
1411
- base = [true, true, true, true];
1412
- }
1413
- const rotation = this.rng.nextInt(0, 3);
1414
- const current = this.rotateMask(base, rotation);
1415
- return {
1416
- type,
1417
- rotation,
1418
- baseConnections: base,
1419
- currentConnections: current,
1420
- isPowered: false,
1421
- isFixed: false
1447
+ this.state = {
1448
+ playerX: 13,
1449
+ playerY: 13,
1450
+ playerDx: -1,
1451
+ playerDy: 0,
1452
+ desiredDx: -1,
1453
+ desiredDy: 0,
1454
+ mouthOpen: true,
1455
+ lives: 3,
1456
+ score: this.state.score,
1457
+ level,
1458
+ pelletsRemaining: 0,
1459
+ totalPellets: 0,
1460
+ frightenedTicksRemaining: 0,
1461
+ frightenedCombo: 0,
1462
+ isWon: false,
1463
+ isGameOver: false
1422
1464
  };
1465
+ this.daemonsChompedInSurge = 0;
1466
+ this.loadMaze();
1467
+ this.resetDaemons();
1423
1468
  }
1424
- rotateMask(mask, times) {
1425
- const res = [...mask];
1426
- for (let i = 0; i < times % 4; i++) {
1427
- const [top, right, bottom, left] = res;
1428
- res[0] = left;
1429
- res[1] = top;
1430
- res[2] = right;
1431
- res[3] = bottom;
1469
+ loadMaze() {
1470
+ this.grid = [];
1471
+ let pellets = 0;
1472
+ for (let y = 0; y < MAZE_HEIGHT; y++) {
1473
+ const row = [];
1474
+ const line = MAZE_TEMPLATE[y] || "";
1475
+ for (let x = 0; x < MAZE_WIDTH; x++) {
1476
+ const char = line[x] || " ";
1477
+ if (char === "#") {
1478
+ row.push("wall");
1479
+ } else if (char === ".") {
1480
+ row.push("pellet");
1481
+ pellets++;
1482
+ } else if (char === "O") {
1483
+ row.push("power");
1484
+ pellets++;
1485
+ } else if (char === "-") {
1486
+ row.push("gate");
1487
+ } else {
1488
+ row.push("empty");
1489
+ }
1490
+ }
1491
+ this.grid.push(row);
1432
1492
  }
1433
- return res;
1493
+ this.state.pelletsRemaining = pellets;
1494
+ this.state.totalPellets = pellets;
1434
1495
  }
1435
- rotateTileAt(x, y) {
1436
- const tile = this.state.grid[y]?.[x];
1437
- if (!tile || tile.isFixed || this.state.isWon || this.state.isGameOver) return false;
1438
- tile.rotation = (tile.rotation + 1) % 4;
1439
- tile.currentConnections = this.rotateMask(tile.baseConnections, tile.rotation);
1440
- this.state.movesRemaining--;
1441
- this.updatePowerFlow();
1442
- if (this.config?.soundEnabled) {
1443
- playTerminalBell();
1444
- }
1445
- if (this.state.isWon) {
1446
- const bonus = this.state.movesRemaining * 100;
1447
- this.state.score += 500 + bonus;
1448
- this.config?.onScoreUpdate?.(this.state.score);
1449
- this.config?.onAchievementUnlock?.("first_spark");
1450
- if (this.state.movesRemaining >= 5) {
1451
- this.config?.onAchievementUnlock?.("overclocked");
1496
+ resetDaemons() {
1497
+ this.daemons = [
1498
+ {
1499
+ id: "blinky",
1500
+ name: "Blinky",
1501
+ x: 13,
1502
+ y: 7,
1503
+ dx: 1,
1504
+ dy: 0,
1505
+ baseX: 25,
1506
+ baseY: 1,
1507
+ state: "chase",
1508
+ frightenedTicks: 0,
1509
+ colorName: "red"
1510
+ },
1511
+ {
1512
+ id: "pinky",
1513
+ name: "Pinky",
1514
+ x: 12,
1515
+ y: 11,
1516
+ dx: 0,
1517
+ dy: -1,
1518
+ baseX: 1,
1519
+ baseY: 1,
1520
+ state: "chase",
1521
+ frightenedTicks: 0,
1522
+ colorName: "pink"
1523
+ },
1524
+ {
1525
+ id: "inky",
1526
+ name: "Inky",
1527
+ x: 13,
1528
+ y: 11,
1529
+ dx: 0,
1530
+ dy: -1,
1531
+ baseX: 25,
1532
+ baseY: 17,
1533
+ state: "chase",
1534
+ frightenedTicks: 0,
1535
+ colorName: "cyan"
1536
+ },
1537
+ {
1538
+ id: "clyde",
1539
+ name: "Clyde",
1540
+ x: 14,
1541
+ y: 11,
1542
+ dx: 0,
1543
+ dy: -1,
1544
+ baseX: 1,
1545
+ baseY: 17,
1546
+ state: "chase",
1547
+ frightenedTicks: 0,
1548
+ colorName: "yellow"
1452
1549
  }
1453
- if (this.config?.difficulty === "insane") {
1454
- this.config?.onAchievementUnlock?.("grid_master");
1550
+ ];
1551
+ }
1552
+ scheduleNextTick() {
1553
+ if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
1554
+ if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
1555
+ this.gameLoopTimer = setTimeout(() => {
1556
+ this.tick();
1557
+ this.scheduleNextTick();
1558
+ }, this.tickIntervalMs);
1559
+ }
1560
+ tick() {
1561
+ if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
1562
+ this.state.mouthOpen = !this.state.mouthOpen;
1563
+ if (this.state.frightenedTicksRemaining > 0) {
1564
+ this.state.frightenedTicksRemaining--;
1565
+ if (this.state.frightenedTicksRemaining === 0) {
1566
+ for (const d of this.daemons) {
1567
+ if (d.state === "frightened") d.state = "chase";
1568
+ }
1455
1569
  }
1456
- } else if (this.state.movesRemaining <= 0) {
1457
- this.state.isGameOver = true;
1458
- this.config?.onGameOver?.(this.state.score);
1459
1570
  }
1571
+ if (this.canMove(this.state.playerX, this.state.playerY, this.state.desiredDx, this.state.desiredDy)) {
1572
+ this.state.playerDx = this.state.desiredDx;
1573
+ this.state.playerDy = this.state.desiredDy;
1574
+ }
1575
+ if (this.canMove(this.state.playerX, this.state.playerY, this.state.playerDx, this.state.playerDy)) {
1576
+ this.state.playerX += this.state.playerDx;
1577
+ this.state.playerY += this.state.playerDy;
1578
+ if (this.state.playerX < 0) this.state.playerX = MAZE_WIDTH - 1;
1579
+ else if (this.state.playerX >= MAZE_WIDTH) this.state.playerX = 0;
1580
+ this.chompCurrentTile();
1581
+ }
1582
+ this.moveDaemons();
1583
+ this.checkCollisions();
1584
+ this.render();
1585
+ }
1586
+ canMove(x, y, dx, dy, isDaemon = false) {
1587
+ let nx = x + dx;
1588
+ let ny = y + dy;
1589
+ if (nx < 0) nx = MAZE_WIDTH - 1;
1590
+ else if (nx >= MAZE_WIDTH) nx = 0;
1591
+ if (ny < 0 || ny >= MAZE_HEIGHT) return false;
1592
+ const tile = this.grid[ny]?.[nx];
1593
+ if (!tile || tile === "wall") return false;
1594
+ if (tile === "gate" && !isDaemon) return false;
1460
1595
  return true;
1461
1596
  }
1462
- updatePowerFlow() {
1463
- const { width, height, grid } = this.state;
1464
- for (let y = 0; y < height; y++) {
1465
- for (let x = 0; x < width; x++) {
1466
- if (grid[y][x].type !== "source") {
1467
- grid[y][x].isPowered = false;
1597
+ chompCurrentTile() {
1598
+ const tile = this.grid[this.state.playerY]?.[this.state.playerX];
1599
+ if (tile === "pellet") {
1600
+ this.grid[this.state.playerY][this.state.playerX] = "empty";
1601
+ this.state.score += 10;
1602
+ this.state.pelletsRemaining--;
1603
+ this.pelletsEatenCount++;
1604
+ this.config?.onScoreUpdate?.(this.state.score);
1605
+ if (this.pelletsEatenCount >= 50) {
1606
+ this.config?.onAchievementUnlock?.("first_chomp");
1607
+ }
1608
+ if (this.state.pelletsRemaining === 0) {
1609
+ this.state.isWon = true;
1610
+ this.config?.onAchievementUnlock?.("maze_sweeper");
1611
+ return;
1612
+ }
1613
+ } else if (tile === "power") {
1614
+ this.grid[this.state.playerY][this.state.playerX] = "empty";
1615
+ this.state.score += 50;
1616
+ this.state.pelletsRemaining--;
1617
+ this.daemonsChompedInSurge = 0;
1618
+ let surgeTicks = 45;
1619
+ if (this.config?.difficulty === "easy") surgeTicks = 65;
1620
+ else if (this.config?.difficulty === "hard") surgeTicks = 30;
1621
+ else if (this.config?.difficulty === "insane") surgeTicks = 18;
1622
+ this.state.frightenedTicksRemaining = surgeTicks;
1623
+ this.state.frightenedCombo = 0;
1624
+ for (const d of this.daemons) {
1625
+ if (d.state !== "eaten") {
1626
+ d.state = "frightened";
1627
+ d.dx = -d.dx;
1628
+ d.dy = -d.dy;
1468
1629
  }
1469
1630
  }
1631
+ if (this.config?.soundEnabled) playTerminalBell();
1470
1632
  }
1471
- const queue = [[0, 0]];
1472
- const visited = /* @__PURE__ */ new Set();
1473
- visited.add("0,0");
1474
- let targetsLit = 0;
1475
- const dx = [0, 1, 0, -1];
1476
- const dy = [-1, 0, 1, 0];
1477
- const oppositeDir = [2, 3, 0, 1];
1478
- while (queue.length > 0) {
1479
- const [cx, cy] = queue.shift();
1480
- const curr = grid[cy][cx];
1481
- for (let dir = 0; dir < 4; dir++) {
1482
- if (!curr.currentConnections[dir]) continue;
1483
- const nx = cx + dx[dir];
1484
- const ny = cy + dy[dir];
1485
- if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
1486
- const key = `${nx},${ny}`;
1487
- if (visited.has(key)) continue;
1488
- const neighbor = grid[ny][nx];
1489
- if (neighbor.type === "blocked") continue;
1490
- const opp = oppositeDir[dir];
1491
- if (neighbor.currentConnections[opp]) {
1492
- neighbor.isPowered = true;
1493
- visited.add(key);
1494
- queue.push([nx, ny]);
1495
- if (neighbor.type === "target") {
1496
- targetsLit++;
1633
+ }
1634
+ moveDaemons() {
1635
+ const directions = [
1636
+ [0, -1],
1637
+ // Up
1638
+ [-1, 0],
1639
+ // Left
1640
+ [0, 1],
1641
+ // Down
1642
+ [1, 0]
1643
+ // Right
1644
+ ];
1645
+ for (const d of this.daemons) {
1646
+ if (d.state === "eaten") {
1647
+ if (d.x === 13 && d.y === 9) {
1648
+ d.state = "chase";
1649
+ }
1650
+ }
1651
+ const validDirs = [];
1652
+ for (const [dx, dy] of directions) {
1653
+ if (dx === -d.dx && dy === -d.dy) continue;
1654
+ if (this.canMove(d.x, d.y, dx, dy, true)) {
1655
+ validDirs.push([dx, dy]);
1656
+ }
1657
+ }
1658
+ if (validDirs.length === 0) {
1659
+ if (this.canMove(d.x, d.y, -d.dx, -d.dy, true)) {
1660
+ validDirs.push([-d.dx, -d.dy]);
1661
+ }
1662
+ }
1663
+ if (validDirs.length > 0) {
1664
+ let chosenDir;
1665
+ if (d.state === "frightened") {
1666
+ chosenDir = this.rng.pick(validDirs);
1667
+ } else {
1668
+ let targetX = this.state.playerX;
1669
+ let targetY = this.state.playerY;
1670
+ if (d.id === "pinky") {
1671
+ targetX += this.state.playerDx * 4;
1672
+ targetY += this.state.playerDy * 4;
1673
+ } else if (d.id === "clyde") {
1674
+ const dist = Math.hypot(d.x - this.state.playerX, d.y - this.state.playerY);
1675
+ if (dist < 6) {
1676
+ targetX = d.baseX;
1677
+ targetY = d.baseY;
1678
+ }
1679
+ }
1680
+ chosenDir = validDirs[0];
1681
+ let minDist = Infinity;
1682
+ for (const [vx, vy] of validDirs) {
1683
+ const nx = d.x + vx;
1684
+ const ny = d.y + vy;
1685
+ const dist = Math.hypot(nx - targetX, ny - targetY);
1686
+ if (dist < minDist) {
1687
+ minDist = dist;
1688
+ chosenDir = [vx, vy];
1689
+ }
1497
1690
  }
1498
1691
  }
1692
+ d.dx = chosenDir[0];
1693
+ d.dy = chosenDir[1];
1694
+ d.x += d.dx;
1695
+ d.y += d.dy;
1696
+ if (d.x < 0) d.x = MAZE_WIDTH - 1;
1697
+ else if (d.x >= MAZE_WIDTH) d.x = 0;
1499
1698
  }
1500
1699
  }
1501
- this.state.targetsRemaining = this.state.totalTargets - targetsLit;
1502
- if (this.state.targetsRemaining === 0) {
1503
- this.state.isWon = true;
1700
+ }
1701
+ checkCollisions() {
1702
+ for (const d of this.daemons) {
1703
+ if (d.x === this.state.playerX && d.y === this.state.playerY) {
1704
+ if (d.state === "frightened") {
1705
+ d.state = "eaten";
1706
+ d.x = 13;
1707
+ d.y = 9;
1708
+ this.state.frightenedCombo++;
1709
+ const points = 200 * Math.pow(2, this.state.frightenedCombo - 1);
1710
+ this.state.score += points;
1711
+ this.daemonsChompedInSurge++;
1712
+ if (this.daemonsChompedInSurge >= 4) {
1713
+ this.config?.onAchievementUnlock?.("daemon_slayer");
1714
+ }
1715
+ if (this.config?.soundEnabled) playTerminalBell();
1716
+ } else if (d.state === "chase") {
1717
+ this.state.lives--;
1718
+ if (this.config?.soundEnabled) playTerminalBell();
1719
+ if (this.state.lives <= 0) {
1720
+ this.state.isGameOver = true;
1721
+ this.config?.onGameOver?.(this.state.score);
1722
+ } else {
1723
+ this.state.playerX = 13;
1724
+ this.state.playerY = 13;
1725
+ this.state.playerDx = -1;
1726
+ this.state.playerDy = 0;
1727
+ this.state.desiredDx = -1;
1728
+ this.state.desiredDy = 0;
1729
+ this.resetDaemons();
1730
+ }
1731
+ break;
1732
+ }
1733
+ }
1504
1734
  }
1505
1735
  }
1506
1736
  handleInput(key) {
1507
1737
  if (this.showTutorial) {
1508
1738
  if (key.name === "return" || key.name === "space") {
1509
1739
  this.showTutorial = false;
1740
+ this.scheduleNextTick();
1510
1741
  this.render();
1511
1742
  } else if (key.name === "escape" || key.name === "q") {
1512
1743
  this.destroy();
@@ -1524,10 +1755,12 @@ var NeonCircuitGame = class {
1524
1755
  } else if (key.name === "return" || key.name === "space") {
1525
1756
  if (this.pauseMenuIndex === 0) {
1526
1757
  this.isPaused = false;
1758
+ this.scheduleNextTick();
1527
1759
  this.render();
1528
1760
  } else if (this.pauseMenuIndex === 1) {
1529
1761
  this.isPaused = false;
1530
- this.setupLevel(this.state.level, this.config?.difficulty || "normal");
1762
+ this.resetGame(this.state.level, this.config?.difficulty || "normal");
1763
+ this.scheduleNextTick();
1531
1764
  this.render();
1532
1765
  } else if (this.pauseMenuIndex === 2) {
1533
1766
  this.destroy();
@@ -1535,6 +1768,7 @@ var NeonCircuitGame = class {
1535
1768
  }
1536
1769
  } else if (key.name === "escape" || key.name === "p") {
1537
1770
  this.isPaused = false;
1771
+ this.scheduleNextTick();
1538
1772
  this.render();
1539
1773
  } else if (key.name === "q") {
1540
1774
  this.destroy();
@@ -1545,6 +1779,10 @@ var NeonCircuitGame = class {
1545
1779
  if (key.name === "escape" || key.name === "p") {
1546
1780
  this.isPaused = true;
1547
1781
  this.pauseMenuIndex = 0;
1782
+ if (this.gameLoopTimer) {
1783
+ clearTimeout(this.gameLoopTimer);
1784
+ this.gameLoopTimer = null;
1785
+ }
1548
1786
  this.render();
1549
1787
  return;
1550
1788
  }
@@ -1555,7 +1793,8 @@ var NeonCircuitGame = class {
1555
1793
  }
1556
1794
  if (this.state.isWon) {
1557
1795
  if (key.name === "return" || key.name === "space") {
1558
- this.setupLevel(this.state.level + 1, this.config?.difficulty || "normal");
1796
+ this.resetGame(this.state.level + 1, this.config?.difficulty || "normal");
1797
+ this.scheduleNextTick();
1559
1798
  this.render();
1560
1799
  } else if (key.name === "escape" || key.name === "q") {
1561
1800
  this.destroy();
@@ -1573,42 +1812,36 @@ var NeonCircuitGame = class {
1573
1812
  return;
1574
1813
  }
1575
1814
  if (key.name === "up" || key.name === "w") {
1576
- this.state.cursorY = Math.max(0, this.state.cursorY - 1);
1577
- this.render();
1815
+ this.state.desiredDx = 0;
1816
+ this.state.desiredDy = -1;
1578
1817
  } else if (key.name === "down" || key.name === "s") {
1579
- this.state.cursorY = Math.min(this.state.height - 1, this.state.cursorY + 1);
1580
- this.render();
1818
+ this.state.desiredDx = 0;
1819
+ this.state.desiredDy = 1;
1581
1820
  } else if (key.name === "left" || key.name === "a") {
1582
- this.state.cursorX = Math.max(0, this.state.cursorX - 1);
1583
- this.render();
1821
+ this.state.desiredDx = -1;
1822
+ this.state.desiredDy = 0;
1584
1823
  } else if (key.name === "right" || key.name === "d") {
1585
- this.state.cursorX = Math.min(this.state.width - 1, this.state.cursorX + 1);
1586
- this.render();
1587
- } else if (key.name === "space" || key.name === "return") {
1588
- this.rotateTileAt(this.state.cursorX, this.state.cursorY);
1589
- this.render();
1590
- } else if (key.name === "r") {
1591
- this.setupLevel(this.state.level, this.config?.difficulty || "normal");
1592
- this.render();
1824
+ this.state.desiredDx = 1;
1825
+ this.state.desiredDy = 0;
1593
1826
  }
1594
1827
  }
1595
1828
  render() {
1596
1829
  const t = this.renderer.getTheme();
1597
1830
  if (this.showTutorial) {
1598
- const tutorialLines = [
1831
+ const lines = [
1599
1832
  "",
1600
- t.highlight("OBJECTIVE: ROUTE HIGH-VOLTAGE FLUX"),
1833
+ t.highlight("OBJECTIVE: CHOMP BYTE PELLETS & PURGE DAEMONS"),
1601
1834
  "",
1602
- "\u2022 Navigate cursor using Arrow Keys or WASD.",
1603
- "\u2022 Press Space or Enter to rotate circuit tiles clockwise.",
1604
- "\u2022 Connect the glowing [S] Power Source to the [T] Target nodes.",
1605
- "\u2022 Watch your Capacity (Moves Remaining) meter.",
1606
- "\u2022 Obstacles [\u2593] cannot conduct energy or rotate.",
1835
+ "\u2022 Use Arrow Keys or WASD to navigate memory corridors.",
1836
+ "\u2022 Chomp all data pellets [ \xB7 ] to clear the sector.",
1837
+ "\u2022 Ingest Super Capacitors [ \u25CF ] to trigger Power Surge state.",
1838
+ "\u2022 During Power Surge, hunt vulnerable memory daemons for huge multipliers!",
1839
+ "\u2022 Wrap through the side tunnels to evade ambushes.",
1607
1840
  "",
1608
1841
  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"),
1609
1842
  t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
1610
1843
  ];
1611
- const box = this.renderer.createBox(tutorialLines, 64, "CIRCUIT PROTOCOL MANUAL");
1844
+ const box = this.renderer.createBox(lines, 64, "PACKET MAN PROTOCOL MANUAL");
1612
1845
  this.renderer.clear();
1613
1846
  this.renderer.draw(`
1614
1847
 
@@ -1617,10 +1850,10 @@ ${box}
1617
1850
  return;
1618
1851
  }
1619
1852
  if (this.isPaused) {
1620
- const pauseItems = ["Resume Circuit (Esc / Enter)", "Restart Level (R)", "Quit to Arcade / Terminal (Q)"];
1853
+ const pauseItems = ["Resume Arcade (Esc / Enter)", "Restart Round (R)", "Return to Game List (Q)"];
1621
1854
  const pauseLines = [
1622
1855
  "",
1623
- t.highlight("\u2550\u2550\u2550 CIRCUIT SUBROUTINE PAUSED \u2550\u2550\u2550"),
1856
+ t.highlight("\u2550\u2550\u2550 MEMORY MAZE PAUSED \u2550\u2550\u2550"),
1624
1857
  "",
1625
1858
  ...pauseItems.map((item, idx) => {
1626
1859
  if (idx === this.pauseMenuIndex) {
@@ -1630,7 +1863,7 @@ ${box}
1630
1863
  }),
1631
1864
  "",
1632
1865
  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"),
1633
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
1866
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Return to Game List")
1634
1867
  ];
1635
1868
  const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
1636
1869
  this.renderer.clear();
@@ -1641,106 +1874,127 @@ ${pauseBox}
1641
1874
  return;
1642
1875
  }
1643
1876
  const header = this.renderer.renderHeader({
1644
- title: "NEON CIRCUIT",
1645
- category: "PUZZLE",
1877
+ title: "PACKET MAN",
1878
+ category: "ARCADE",
1646
1879
  difficulty: this.config?.difficulty,
1647
1880
  score: this.state.score,
1648
1881
  level: this.state.level
1649
1882
  });
1650
- const lines = [];
1651
- const { width, height, grid, cursorX, cursorY } = this.state;
1652
- 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}`)}`);
1653
- lines.push("");
1654
- for (let y = 0; y < height; y++) {
1655
- let rowStr = " ";
1656
- for (let x = 0; x < width; x++) {
1657
- const tile = grid[y][x];
1658
- const isCursor = x === cursorX && y === cursorY;
1659
- const glyph = this.getTileGlyph(tile);
1660
- let formatted = glyph;
1661
- if (tile.isPowered) {
1662
- formatted = t.highlight(glyph);
1663
- } else {
1664
- formatted = t.muted(glyph);
1883
+ const hudLines = [];
1884
+ const livesStr = `${t.muted("Buffer Lives:")} ${t.highlight("\u25BA ".repeat(Math.max(0, this.state.lives)))}`;
1885
+ const surgeStr = this.state.frightenedTicksRemaining > 0 ? t.warning(`\u26A1 OVERCLOCK SURGE [${Math.ceil(this.state.frightenedTicksRemaining / 5)}s]`) : t.muted("NORMAL FLUX");
1886
+ hudLines.push(` ${livesStr} ${surgeStr} ${t.muted("Pellets:")} ${t.primary(this.state.pelletsRemaining.toString())}`);
1887
+ const boardLines = [];
1888
+ for (let y = 0; y < MAZE_HEIGHT; y++) {
1889
+ let row = " ";
1890
+ for (let x = 0; x < MAZE_WIDTH; x++) {
1891
+ if (x === this.state.playerX && y === this.state.playerY) {
1892
+ const char = this.getPlayerGlyph();
1893
+ row += t.highlight(char);
1894
+ continue;
1895
+ }
1896
+ const daemon = this.daemons.find((d) => d.x === x && d.y === y);
1897
+ if (daemon) {
1898
+ row += this.getDaemonGlyph(daemon);
1899
+ continue;
1665
1900
  }
1666
- if (isCursor) {
1667
- rowStr += `[${t.accent(glyph)}] `;
1901
+ const tile = this.grid[y][x];
1902
+ if (tile === "wall") {
1903
+ row += t.border("\u2588\u2588");
1904
+ } else if (tile === "pellet") {
1905
+ row += t.primary(" \xB7");
1906
+ } else if (tile === "power") {
1907
+ row += t.accent(" \u25CF");
1908
+ } else if (tile === "gate") {
1909
+ row += t.secondary("\u2550\u2550");
1668
1910
  } else {
1669
- rowStr += ` ${formatted} `;
1911
+ row += " ";
1670
1912
  }
1671
1913
  }
1672
- lines.push(rowStr);
1673
- lines.push("");
1914
+ boardLines.push(row);
1674
1915
  }
1675
1916
  if (this.state.isWon) {
1676
- lines.push(` ${t.success("\u26A1 CIRCUIT SYNCHRONIZED! ALL NODES POWERED!")}`);
1677
- lines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
1917
+ boardLines.push(`
1918
+ ${t.success("\u{1F389} MEMORY SECTOR COMPLETELY PURGED! EXCELLENT OPERATOR.")}`);
1919
+ boardLines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
1678
1920
  } else if (this.state.isGameOver) {
1679
- lines.push(` ${t.error("\u274C CAPACITY EXHAUSTED! POWER COLLAPSE.")}`);
1680
- lines.push(` ${t.muted("Press R to Retry Level, or P for Pause Menu.")}`);
1921
+ boardLines.push(`
1922
+ ${t.error("\u{1F4A5} SYSTEM FAULT: LIVES DEPLETED. KERNEL DUMP.")}`);
1923
+ boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Return to Game List.")}`);
1681
1924
  } else {
1682
- lines.push(` ${t.muted("Controls: Arrows/WASD: Move \u2502 Space: Rotate \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
1925
+ boardLines.push(`
1926
+ ${t.muted("Controls: Arrows/WASD: Move \u2502 Esc/P: Pause \u2502 Q: Return to Game List")}`);
1683
1927
  }
1684
1928
  this.renderer.clear();
1685
1929
  this.renderer.draw(`
1686
1930
  ${header}
1687
- ${lines.join("\n")}
1931
+ ${hudLines.join("\n")}
1932
+ ${boardLines.join("\n")}
1688
1933
  `);
1689
1934
  }
1690
- getTileGlyph(tile) {
1691
- if (tile.type === "source") return "S";
1692
- if (tile.type === "target") return "T";
1693
- if (tile.type === "blocked") return "\u2593";
1694
- const [top, right, bottom, left] = tile.currentConnections;
1695
- if (top && bottom && !right && !left) return "\u2502";
1696
- if (!top && !bottom && right && left) return "\u2500";
1697
- if (bottom && right && !top && !left) return "\u250C";
1698
- if (bottom && left && !top && !right) return "\u2510";
1699
- if (top && right && !bottom && !left) return "\u2514";
1700
- if (top && left && !bottom && !right) return "\u2518";
1701
- if (top && bottom && right && !left) return "\u251C";
1702
- if (top && bottom && !right && left) return "\u2524";
1703
- if (!top && bottom && right && left) return "\u252C";
1704
- if (top && !bottom && right && left) return "\u2534";
1705
- if (top && bottom && right && left) return "\u253C";
1706
- return "\u2022";
1935
+ getPlayerGlyph() {
1936
+ if (!this.state.mouthOpen) return "\u25CB ";
1937
+ if (this.state.playerDx === 1) return "\u25BA ";
1938
+ if (this.state.playerDx === -1) return "\u25C4 ";
1939
+ if (this.state.playerDy === -1) return "\u25B2 ";
1940
+ if (this.state.playerDy === 1) return "\u25BC ";
1941
+ return "\u25BA ";
1942
+ }
1943
+ getDaemonGlyph(d) {
1944
+ const t = this.renderer.getTheme();
1945
+ if (d.state === "frightened") {
1946
+ if (this.state.frightenedTicksRemaining < 10 && this.state.frightenedTicksRemaining % 2 === 0) {
1947
+ return t.accent("\xA7 ");
1948
+ }
1949
+ return t.secondary("\xA7 ");
1950
+ }
1951
+ if (d.state === "eaten") {
1952
+ return t.muted('""');
1953
+ }
1954
+ if (d.colorName === "red") return t.error("M ");
1955
+ if (d.colorName === "pink") return t.secondary("M ");
1956
+ if (d.colorName === "cyan") return t.primary("M ");
1957
+ return t.accent("M ");
1707
1958
  }
1708
1959
  getState() {
1709
1960
  return this.state;
1710
1961
  }
1711
1962
  };
1712
1963
 
1713
- // src/games/byte-runner/index.ts
1714
- var HIGHWAY_HEIGHT = 16;
1715
- var LANE_COUNT = 3;
1716
- var ByteRunnerGame = class {
1717
- id = "byte-runner";
1718
- metadata = ALL_GAMES_METADATA["byte-runner"];
1964
+ // src/games/cyber-viper/index.ts
1965
+ var GRID_WIDTH = 30;
1966
+ var GRID_HEIGHT = 16;
1967
+ var CyberViperGame = class {
1968
+ id = "cyber-viper";
1969
+ metadata = ALL_GAMES_METADATA["cyber-viper"];
1719
1970
  config = null;
1720
1971
  renderer = defaultRenderer;
1721
1972
  input = new TerminalInputHandler();
1722
1973
  rng = new DeterministicRNG();
1723
1974
  gameLoopTimer = null;
1724
- entityIdCounter = 0;
1725
- entities = [];
1726
1975
  state = {
1727
- playerLane: 1,
1728
- isJumping: false,
1729
- jumpTicksRemaining: 0,
1976
+ snake: [
1977
+ { x: 15, y: 8 },
1978
+ { x: 14, y: 8 },
1979
+ { x: 13, y: 8 }
1980
+ ],
1981
+ dx: 1,
1982
+ dy: 0,
1983
+ desiredDx: 1,
1984
+ desiredDy: 0,
1985
+ food: { x: 22, y: 8 },
1986
+ goldenFood: null,
1987
+ goldenFoodTicks: 0,
1730
1988
  score: 0,
1731
- distance: 0,
1732
- cleanBytesCollected: 0,
1733
- activeShield: false,
1734
- slowMotionTicks: 0,
1735
- magnetTicks: 0,
1736
- doubleScoreTicks: 0,
1737
- speedMs: 110,
1989
+ highScore: 0,
1990
+ applesEaten: 0,
1738
1991
  isGameOver: false,
1739
- multiplier: 1
1992
+ isWon: false
1740
1993
  };
1741
1994
  isPaused = false;
1742
1995
  pauseMenuIndex = 0;
1743
1996
  showTutorial = true;
1997
+ tickIntervalMs = 120;
1744
1998
  init(config) {
1745
1999
  this.config = config;
1746
2000
  this.renderer.setTheme(config.theme);
@@ -1784,20 +2038,12 @@ var ByteRunnerGame = class {
1784
2038
  saveState() {
1785
2039
  return {
1786
2040
  state: this.state,
1787
- entities: this.entities,
1788
2041
  showTutorial: this.showTutorial
1789
2042
  };
1790
2043
  }
1791
2044
  loadState(saved) {
1792
- if (saved["state"]) {
1793
- this.state = saved["state"];
1794
- }
1795
- if (saved["entities"]) {
1796
- this.entities = saved["entities"];
1797
- }
1798
- if (saved["showTutorial"] !== void 0) {
1799
- this.showTutorial = !!saved["showTutorial"];
1800
- }
2045
+ if (saved["state"]) this.state = saved["state"];
2046
+ if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
1801
2047
  }
1802
2048
  destroy() {
1803
2049
  if (this.gameLoopTimer) {
@@ -1807,176 +2053,140 @@ var ByteRunnerGame = class {
1807
2053
  this.input.stop();
1808
2054
  }
1809
2055
  resetState(difficulty) {
1810
- let baseSpeed = 110;
1811
2056
  switch (difficulty) {
1812
2057
  case "easy":
1813
- baseSpeed = 140;
2058
+ this.tickIntervalMs = 160;
1814
2059
  break;
1815
2060
  case "normal":
1816
- baseSpeed = 110;
2061
+ this.tickIntervalMs = 120;
1817
2062
  break;
1818
2063
  case "hard":
1819
- baseSpeed = 85;
2064
+ this.tickIntervalMs = 85;
1820
2065
  break;
1821
2066
  case "insane":
1822
- baseSpeed = 65;
2067
+ this.tickIntervalMs = 55;
1823
2068
  break;
1824
2069
  }
1825
2070
  this.state = {
1826
- playerLane: 1,
1827
- isJumping: false,
1828
- jumpTicksRemaining: 0,
2071
+ snake: [
2072
+ { x: 15, y: 8 },
2073
+ { x: 14, y: 8 },
2074
+ { x: 13, y: 8 }
2075
+ ],
2076
+ dx: 1,
2077
+ dy: 0,
2078
+ desiredDx: 1,
2079
+ desiredDy: 0,
2080
+ food: { x: 22, y: 8 },
2081
+ goldenFood: null,
2082
+ goldenFoodTicks: 0,
1829
2083
  score: 0,
1830
- distance: 0,
1831
- cleanBytesCollected: 0,
1832
- activeShield: false,
1833
- slowMotionTicks: 0,
1834
- magnetTicks: 0,
1835
- doubleScoreTicks: 0,
1836
- speedMs: baseSpeed,
2084
+ highScore: this.state.highScore,
2085
+ applesEaten: 0,
1837
2086
  isGameOver: false,
1838
- multiplier: 1
2087
+ isWon: false
1839
2088
  };
1840
- this.entities = [];
2089
+ this.spawnFood();
1841
2090
  }
1842
2091
  scheduleNextTick() {
1843
- if (this.gameLoopTimer) {
1844
- clearTimeout(this.gameLoopTimer);
1845
- }
1846
- if (this.isPaused || this.state.isGameOver || this.showTutorial) return;
1847
- let delay = this.state.speedMs;
1848
- if (this.state.slowMotionTicks > 0) {
1849
- delay = Math.round(delay * 1.6);
1850
- }
2092
+ if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2093
+ if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
1851
2094
  this.gameLoopTimer = setTimeout(() => {
1852
2095
  this.tick();
1853
2096
  this.scheduleNextTick();
1854
- }, delay);
2097
+ }, this.tickIntervalMs);
1855
2098
  }
1856
2099
  tick() {
1857
- if (this.state.isGameOver || this.isPaused || this.showTutorial) return;
1858
- this.state.distance += 1;
1859
- const pointGain = 1 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
1860
- this.state.score += pointGain;
1861
- if (this.state.jumpTicksRemaining > 0) {
1862
- this.state.jumpTicksRemaining--;
1863
- if (this.state.jumpTicksRemaining === 0) {
1864
- this.state.isJumping = false;
1865
- }
1866
- }
1867
- if (this.state.slowMotionTicks > 0) this.state.slowMotionTicks--;
1868
- if (this.state.magnetTicks > 0) this.state.magnetTicks--;
1869
- if (this.state.doubleScoreTicks > 0) this.state.doubleScoreTicks--;
1870
- for (const ent of this.entities) {
1871
- ent.y += 1;
1872
- if (this.state.magnetTicks > 0 && ent.type === "clean" && ent.y >= HIGHWAY_HEIGHT - 6) {
1873
- ent.lane = this.state.playerLane;
1874
- }
1875
- }
1876
- const playerY = HIGHWAY_HEIGHT - 2;
1877
- const remainingEntities = [];
1878
- for (const ent of this.entities) {
1879
- if (ent.y === playerY && ent.lane === this.state.playerLane) {
1880
- if (ent.type === "corrupt") {
1881
- if (this.state.isJumping) {
1882
- remainingEntities.push(ent);
1883
- continue;
1884
- }
1885
- if (this.state.activeShield) {
1886
- this.state.activeShield = false;
1887
- this.config?.onAchievementUnlock?.("shield_matrix");
1888
- if (this.config?.soundEnabled) playTerminalBell();
1889
- continue;
1890
- }
1891
- this.state.isGameOver = true;
1892
- this.config?.onGameOver?.(this.state.score);
1893
- if (this.config?.soundEnabled) playTerminalBell();
1894
- break;
1895
- } else if (ent.type === "clean") {
1896
- this.state.cleanBytesCollected++;
1897
- this.state.score += 100 * (this.state.doubleScoreTicks > 0 ? 2 : 1);
1898
- this.config?.onScoreUpdate?.(this.state.score);
1899
- if (this.state.cleanBytesCollected >= 50) {
1900
- this.config?.onAchievementUnlock?.("packet_chaser");
1901
- }
1902
- if (this.config?.soundEnabled) playTerminalBell();
1903
- continue;
1904
- } else if (ent.type === "powerup") {
1905
- this.activatePowerUp(ent.subType);
1906
- if (this.config?.soundEnabled) playTerminalBell();
1907
- continue;
1908
- }
1909
- }
1910
- if (ent.y < HIGHWAY_HEIGHT) {
1911
- remainingEntities.push(ent);
2100
+ if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2101
+ if (this.state.desiredDx !== -this.state.dx || this.state.desiredDy !== -this.state.dy) {
2102
+ this.state.dx = this.state.desiredDx;
2103
+ this.state.dy = this.state.desiredDy;
2104
+ }
2105
+ const head = this.state.snake[0];
2106
+ const newHead = {
2107
+ x: head.x + this.state.dx,
2108
+ y: head.y + this.state.dy
2109
+ };
2110
+ if (newHead.x < 0 || newHead.x >= GRID_WIDTH || newHead.y < 0 || newHead.y >= GRID_HEIGHT) {
2111
+ this.state.isGameOver = true;
2112
+ this.config?.onGameOver?.(this.state.score);
2113
+ if (this.config?.soundEnabled) playTerminalBell();
2114
+ this.render();
2115
+ return;
2116
+ }
2117
+ for (let i = 0; i < this.state.snake.length - 1; i++) {
2118
+ const seg = this.state.snake[i];
2119
+ if (seg.x === newHead.x && seg.y === newHead.y) {
2120
+ this.state.isGameOver = true;
2121
+ this.config?.onGameOver?.(this.state.score);
2122
+ if (this.config?.soundEnabled) playTerminalBell();
2123
+ this.render();
2124
+ return;
1912
2125
  }
1913
2126
  }
1914
- this.entities = remainingEntities;
1915
- if (this.state.distance >= 5e3) {
1916
- this.config?.onAchievementUnlock?.("hyperspeed");
2127
+ this.state.snake.unshift(newHead);
2128
+ if (this.state.goldenFoodTicks > 0) {
2129
+ this.state.goldenFoodTicks--;
2130
+ if (this.state.goldenFoodTicks === 0) {
2131
+ this.state.goldenFood = null;
2132
+ }
1917
2133
  }
1918
- if (this.state.distance % 2 === 0) {
1919
- this.spawnHighwayWave();
2134
+ let grew = false;
2135
+ if (newHead.x === this.state.food.x && newHead.y === this.state.food.y) {
2136
+ grew = true;
2137
+ this.state.score += 100;
2138
+ this.state.applesEaten++;
2139
+ this.config?.onScoreUpdate?.(this.state.score);
2140
+ this.config?.onAchievementUnlock?.("first_bite");
2141
+ if (this.state.snake.length >= 25) {
2142
+ this.config?.onAchievementUnlock?.("long_viper");
2143
+ }
2144
+ if (this.config?.soundEnabled) playTerminalBell();
2145
+ this.spawnFood();
2146
+ if (this.rng.next() < 0.25 && !this.state.goldenFood) {
2147
+ this.spawnGoldenFood();
2148
+ }
2149
+ } else if (this.state.goldenFood && newHead.x === this.state.goldenFood.x && newHead.y === this.state.goldenFood.y) {
2150
+ grew = true;
2151
+ this.state.score += 500;
2152
+ this.state.goldenFood = null;
2153
+ this.state.goldenFoodTicks = 0;
2154
+ this.config?.onScoreUpdate?.(this.state.score);
2155
+ this.config?.onAchievementUnlock?.("golden_feast");
2156
+ if (this.config?.soundEnabled) playTerminalBell();
1920
2157
  }
1921
- if (this.state.distance % 200 === 0 && this.state.speedMs > 45) {
1922
- this.state.speedMs -= 2;
2158
+ if (!grew) {
2159
+ this.state.snake.pop();
1923
2160
  }
1924
2161
  this.render();
1925
2162
  }
1926
- activatePowerUp(type) {
1927
- switch (type) {
1928
- case "shield":
1929
- this.state.activeShield = true;
1930
- break;
1931
- case "slow":
1932
- this.state.slowMotionTicks = 60;
1933
- break;
1934
- case "magnet":
1935
- this.state.magnetTicks = 70;
1936
- break;
1937
- case "double":
1938
- this.state.doubleScoreTicks = 80;
1939
- break;
2163
+ spawnFood() {
2164
+ const emptyCells = [];
2165
+ for (let y = 0; y < GRID_HEIGHT; y++) {
2166
+ for (let x = 0; x < GRID_WIDTH; x++) {
2167
+ if (!this.state.snake.some((s) => s.x === x && s.y === y)) {
2168
+ emptyCells.push({ x, y });
2169
+ }
2170
+ }
2171
+ }
2172
+ if (emptyCells.length > 0) {
2173
+ this.state.food = this.rng.pick(emptyCells);
2174
+ } else {
2175
+ this.state.isWon = true;
1940
2176
  }
1941
2177
  }
1942
- spawnHighwayWave() {
1943
- const roll = this.rng.next();
1944
- const lane = this.rng.nextInt(0, LANE_COUNT - 1);
1945
- if (roll < 0.45) {
1946
- const labels = ["[CORRUPT]", "[BAD_MEM]", "[NULL_PTR]", "[SEG_FLT]"];
1947
- this.entities.push({
1948
- id: ++this.entityIdCounter,
1949
- lane,
1950
- y: 0,
1951
- type: "corrupt",
1952
- label: this.rng.pick(labels)
1953
- });
1954
- } else if (roll < 0.8) {
1955
- const labels = ["0x7F", "0xFF", "[CLEAN]", "[PACKET]"];
1956
- this.entities.push({
1957
- id: ++this.entityIdCounter,
1958
- lane,
1959
- y: 0,
1960
- type: "clean",
1961
- label: this.rng.pick(labels)
1962
- });
1963
- } else if (roll < 0.95) {
1964
- const powerups = ["shield", "slow", "magnet", "double"];
1965
- const chosen = this.rng.pick(powerups);
1966
- const labels = {
1967
- shield: "\u{1F6E1}\uFE0F [SHLD]",
1968
- slow: "\u23F1\uFE0F [SLOW]",
1969
- magnet: "\u{1F9F2} [MAG]",
1970
- double: "\u26A1 [2X]"
1971
- };
1972
- this.entities.push({
1973
- id: ++this.entityIdCounter,
1974
- lane,
1975
- y: 0,
1976
- type: "powerup",
1977
- subType: chosen,
1978
- label: labels[chosen]
1979
- });
2178
+ spawnGoldenFood() {
2179
+ const emptyCells = [];
2180
+ for (let y = 0; y < GRID_HEIGHT; y++) {
2181
+ for (let x = 0; x < GRID_WIDTH; x++) {
2182
+ if (!this.state.snake.some((s) => s.x === x && s.y === y) && (x !== this.state.food.x || y !== this.state.food.y)) {
2183
+ emptyCells.push({ x, y });
2184
+ }
2185
+ }
2186
+ }
2187
+ if (emptyCells.length > 0) {
2188
+ this.state.goldenFood = this.rng.pick(emptyCells);
2189
+ this.state.goldenFoodTicks = 70;
1980
2190
  }
1981
2191
  }
1982
2192
  handleInput(key) {
@@ -2005,7 +2215,9 @@ var ByteRunnerGame = class {
2005
2215
  this.render();
2006
2216
  } else if (this.pauseMenuIndex === 1) {
2007
2217
  this.isPaused = false;
2008
- this.restart();
2218
+ this.resetState(this.config?.difficulty || "normal");
2219
+ this.scheduleNextTick();
2220
+ this.render();
2009
2221
  } else if (this.pauseMenuIndex === 2) {
2010
2222
  this.destroy();
2011
2223
  this.config?.onExit?.();
@@ -2023,657 +2235,16 @@ var ByteRunnerGame = class {
2023
2235
  if (key.name === "escape" || key.name === "p") {
2024
2236
  this.isPaused = true;
2025
2237
  this.pauseMenuIndex = 0;
2026
- if (this.gameLoopTimer) {
2027
- clearTimeout(this.gameLoopTimer);
2028
- this.gameLoopTimer = null;
2029
- }
2030
- this.render();
2031
- return;
2032
- }
2033
- if (key.name === "q") {
2034
- this.destroy();
2035
- this.config?.onExit?.();
2036
- return;
2037
- }
2038
- if (this.state.isGameOver) {
2039
- if (key.name === "r") {
2040
- this.restart();
2041
- } else if (key.name === "escape" || key.name === "q") {
2042
- this.destroy();
2043
- this.config?.onExit?.();
2044
- }
2045
- return;
2046
- }
2047
- if (key.name === "left" || key.name === "a") {
2048
- if (this.state.playerLane > 0) {
2049
- this.state.playerLane--;
2050
- this.render();
2051
- }
2052
- } else if (key.name === "right" || key.name === "d") {
2053
- if (this.state.playerLane < LANE_COUNT - 1) {
2054
- this.state.playerLane++;
2055
- this.render();
2056
- }
2057
- } else if (key.name === "up" || key.name === "w" || key.name === "space") {
2058
- if (!this.state.isJumping) {
2059
- this.state.isJumping = true;
2060
- this.state.jumpTicksRemaining = 3;
2061
- this.render();
2062
- }
2063
- } else if (key.name === "down" || key.name === "s") {
2064
- this.state.isJumping = false;
2065
- this.state.jumpTicksRemaining = 0;
2066
- this.render();
2067
- }
2068
- }
2069
- render() {
2070
- const t = this.renderer.getTheme();
2071
- if (this.showTutorial) {
2072
- const lines = [
2073
- "",
2074
- t.highlight("OBJECTIVE: SPRINT THE FIBER HIGHWAY"),
2075
- "",
2076
- "\u2022 Use Left/Right (or A/D) to switch between 3 data lanes.",
2077
- "\u2022 Press Up / Space to Phase Jump over low corrupted blocks.",
2078
- "\u2022 Collect Clean Byte packets to boost your score.",
2079
- "\u2022 Grab Power-ups: [SHLD] Shield, [SLOW] Buffer, [MAG] Magnet, [2X] Double.",
2080
- "\u2022 Speed escalates continuously with distance.",
2081
- "",
2082
- 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"),
2083
- t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
2084
- ];
2085
- const box = this.renderer.createBox(lines, 64, "BYTE RUNNER MANUAL");
2086
- this.renderer.clear();
2087
- this.renderer.draw(`
2088
-
2089
- ${box}
2090
- `);
2091
- return;
2092
- }
2093
- if (this.isPaused) {
2094
- const pauseItems = ["Resume Runner (Esc / Enter)", "Restart Run (R)", "Quit to Arcade / Terminal (Q)"];
2095
- const pauseLines = [
2096
- "",
2097
- t.highlight("\u2550\u2550\u2550 HIGHWAY PACKET STREAM PAUSED \u2550\u2550\u2550"),
2098
- "",
2099
- ...pauseItems.map((item, idx) => {
2100
- if (idx === this.pauseMenuIndex) {
2101
- return t.primary(` \u25B6 ${t.highlight(item)}`);
2102
- }
2103
- return t.muted(` ${item}`);
2104
- }),
2105
- "",
2106
- 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"),
2107
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
2108
- ];
2109
- const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
2110
- this.renderer.clear();
2111
- this.renderer.draw(`
2112
-
2113
- ${pauseBox}
2114
- `);
2115
- return;
2116
- }
2117
- const header = this.renderer.renderHeader({
2118
- title: "BYTE RUNNER",
2119
- category: "ARCADE",
2120
- difficulty: this.config?.difficulty,
2121
- score: this.state.score
2122
- });
2123
- const hudLines = [];
2124
- const distStr = `${t.muted("Distance:")} ${t.primary(`${this.state.distance}m`)}`;
2125
- const bytesStr = `${t.muted("Clean Bytes:")} ${t.accent(this.state.cleanBytesCollected.toString())}`;
2126
- const buffs = [];
2127
- if (this.state.activeShield) buffs.push(t.success("[SHIELD ACTIVE]"));
2128
- if (this.state.slowMotionTicks > 0) buffs.push(t.warning(`[SLOW-MO ${Math.ceil(this.state.slowMotionTicks / 10)}s]`));
2129
- if (this.state.magnetTicks > 0) buffs.push(t.secondary(`[MAGNET ${Math.ceil(this.state.magnetTicks / 10)}s]`));
2130
- if (this.state.doubleScoreTicks > 0) buffs.push(t.highlight(`[2X SCORE ${Math.ceil(this.state.doubleScoreTicks / 10)}s]`));
2131
- hudLines.push(` ${distStr} ${bytesStr} ${buffs.join(" ")}`);
2132
- hudLines.push("");
2133
- const trackWidth = 54;
2134
- const laneWidth = 18;
2135
- const trackLines = [];
2136
- trackLines.push(` ${t.border("\u250C" + "\u2500".repeat(trackWidth) + "\u2510")}`);
2137
- for (let y = 0; y < HIGHWAY_HEIGHT; y++) {
2138
- let rowContent = "";
2139
- for (let lane = 0; lane < LANE_COUNT; lane++) {
2140
- const ent = this.entities.find((e) => e.lane === lane && e.y === y);
2141
- let cellText = " ".repeat(laneWidth);
2142
- if (ent) {
2143
- let formattedLabel = ent.label;
2144
- if (ent.type === "corrupt") {
2145
- formattedLabel = t.error(ent.label);
2146
- } else if (ent.type === "clean") {
2147
- formattedLabel = t.success(ent.label);
2148
- } else if (ent.type === "powerup") {
2149
- formattedLabel = t.highlight(ent.label);
2150
- }
2151
- const cleanLen = ent.label.length;
2152
- const leftPad = Math.floor((laneWidth - cleanLen) / 2);
2153
- const rightPad = laneWidth - cleanLen - leftPad;
2154
- cellText = " ".repeat(Math.max(0, leftPad)) + formattedLabel + " ".repeat(Math.max(0, rightPad));
2155
- }
2156
- if (y === HIGHWAY_HEIGHT - 2 && lane === this.state.playerLane) {
2157
- const avatar = this.state.isJumping ? "\u25B2 [AIRBORNE] \u25B2" : "\u25B2\u2550\u2550[RUNNER]\u2550\u2550\u25B2";
2158
- const colored = this.state.activeShield ? t.highlight(avatar) : t.primary(avatar);
2159
- const pad = Math.max(0, Math.floor((laneWidth - 14) / 2));
2160
- cellText = " ".repeat(pad) + colored + " ".repeat(Math.max(0, laneWidth - 14 - pad));
2161
- }
2162
- rowContent += cellText + (lane < LANE_COUNT - 1 ? t.border("\u2506") : "");
2163
- }
2164
- trackLines.push(` ${t.border("\u2502")}${rowContent}${t.border("\u2502")}`);
2165
- }
2166
- trackLines.push(` ${t.border("\u2514" + "\u2500".repeat(trackWidth) + "\u2518")}`);
2167
- if (this.state.isGameOver) {
2168
- trackLines.push(`
2169
- ${t.error("\u{1F4A5} SYSTEM FAULT: PACKET CORRUPTED!")}`);
2170
- trackLines.push(` ${t.accent(`Final Distance: ${this.state.distance}m \u2502 Final Score: ${this.state.score}`)}`);
2171
- trackLines.push(` ${t.muted("Press R to Re-engage Runner, or Esc / Q to Exit.")}`);
2172
- } else {
2173
- trackLines.push(` ${t.muted("Controls: Left/Right: Lane \u2502 Up/Space: Jump \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
2174
- }
2175
- this.renderer.clear();
2176
- this.renderer.draw(`
2177
- ${header}
2178
- ${hudLines.join("\n")}
2179
- ${trackLines.join("\n")}
2180
- `);
2181
- }
2182
- getState() {
2183
- return this.state;
2184
- }
2185
- };
2186
-
2187
- // src/games/packet-man/index.ts
2188
- var MAZE_TEMPLATE = [
2189
- "###########################",
2190
- "#............#............#",
2191
- "#.####.#####.#.#####.####.#",
2192
- "#O####.#####.#.#####.####O#",
2193
- "#.####.#####.#.#####.####.#",
2194
- "#.........................#",
2195
- "#.####.##.#######.##.####.#",
2196
- "#......##....#....##......#",
2197
- "######.##### # #####.######",
2198
- " #.# #.# ",
2199
- "######.# ###---### #.######",
2200
- "#......# # # #......#",
2201
- "#.####.# ######### #.####.#",
2202
- "#O..##...............##..O#",
2203
- "###.##.##.#######.##.##.###",
2204
- "#......##....#....##......#",
2205
- "#.##########.#.##########.#",
2206
- "#.........................#",
2207
- "###########################"
2208
- ];
2209
- var MAZE_WIDTH = 27;
2210
- var MAZE_HEIGHT = 19;
2211
- var PacketManGame = class {
2212
- id = "packet-man";
2213
- metadata = ALL_GAMES_METADATA["packet-man"];
2214
- config = null;
2215
- renderer = defaultRenderer;
2216
- input = new TerminalInputHandler();
2217
- rng = new DeterministicRNG();
2218
- gameLoopTimer = null;
2219
- grid = [];
2220
- daemons = [];
2221
- daemonsChompedInSurge = 0;
2222
- pelletsEatenCount = 0;
2223
- state = {
2224
- playerX: 13,
2225
- playerY: 13,
2226
- playerDx: 0,
2227
- playerDy: 0,
2228
- desiredDx: 0,
2229
- desiredDy: 0,
2230
- mouthOpen: true,
2231
- lives: 3,
2232
- score: 0,
2233
- level: 1,
2234
- pelletsRemaining: 0,
2235
- totalPellets: 0,
2236
- frightenedTicksRemaining: 0,
2237
- frightenedCombo: 0,
2238
- isWon: false,
2239
- isGameOver: false
2240
- };
2241
- isPaused = false;
2242
- pauseMenuIndex = 0;
2243
- showTutorial = true;
2244
- tickIntervalMs = 150;
2245
- init(config) {
2246
- this.config = config;
2247
- this.renderer.setTheme(config.theme);
2248
- this.rng = new DeterministicRNG(config.seed || Date.now());
2249
- if (config.skipTutorial !== void 0) {
2250
- this.showTutorial = !config.skipTutorial;
2251
- }
2252
- this.resetGame(1, config.difficulty);
2253
- }
2254
- start() {
2255
- this.isPaused = false;
2256
- this.render();
2257
- this.input.start(
2258
- (key) => this.handleInput(key),
2259
- () => {
2260
- this.destroy();
2261
- process.exit(0);
2262
- }
2263
- );
2264
- this.scheduleNextTick();
2265
- }
2266
- pause() {
2267
- this.isPaused = true;
2268
- if (this.gameLoopTimer) {
2269
- clearTimeout(this.gameLoopTimer);
2270
- this.gameLoopTimer = null;
2271
- }
2272
- }
2273
- resume() {
2274
- this.isPaused = false;
2275
- this.scheduleNextTick();
2276
- this.render();
2277
- }
2278
- restart() {
2279
- if (this.config) {
2280
- this.resetGame(1, this.config.difficulty);
2281
- this.scheduleNextTick();
2282
- this.render();
2283
- }
2284
- }
2285
- saveState() {
2286
- return {
2287
- state: this.state,
2288
- grid: this.grid,
2289
- daemons: this.daemons,
2290
- showTutorial: this.showTutorial
2291
- };
2292
- }
2293
- loadState(saved) {
2294
- if (saved["state"]) this.state = saved["state"];
2295
- if (saved["grid"]) this.grid = saved["grid"];
2296
- if (saved["daemons"]) this.daemons = saved["daemons"];
2297
- if (saved["showTutorial"] !== void 0) this.showTutorial = !!saved["showTutorial"];
2298
- }
2299
- destroy() {
2300
- if (this.gameLoopTimer) {
2301
- clearTimeout(this.gameLoopTimer);
2302
- this.gameLoopTimer = null;
2303
- }
2304
- this.input.stop();
2305
- }
2306
- resetGame(level, difficulty) {
2307
- switch (difficulty) {
2308
- case "easy":
2309
- this.tickIntervalMs = 175;
2310
- break;
2311
- case "normal":
2312
- this.tickIntervalMs = 145;
2313
- break;
2314
- case "hard":
2315
- this.tickIntervalMs = 120;
2316
- break;
2317
- case "insane":
2318
- this.tickIntervalMs = 95;
2319
- break;
2320
- }
2321
- this.state = {
2322
- playerX: 13,
2323
- playerY: 13,
2324
- playerDx: -1,
2325
- playerDy: 0,
2326
- desiredDx: -1,
2327
- desiredDy: 0,
2328
- mouthOpen: true,
2329
- lives: 3,
2330
- score: this.state.score,
2331
- level,
2332
- pelletsRemaining: 0,
2333
- totalPellets: 0,
2334
- frightenedTicksRemaining: 0,
2335
- frightenedCombo: 0,
2336
- isWon: false,
2337
- isGameOver: false
2338
- };
2339
- this.daemonsChompedInSurge = 0;
2340
- this.loadMaze();
2341
- this.resetDaemons();
2342
- }
2343
- loadMaze() {
2344
- this.grid = [];
2345
- let pellets = 0;
2346
- for (let y = 0; y < MAZE_HEIGHT; y++) {
2347
- const row = [];
2348
- const line = MAZE_TEMPLATE[y] || "";
2349
- for (let x = 0; x < MAZE_WIDTH; x++) {
2350
- const char = line[x] || " ";
2351
- if (char === "#") {
2352
- row.push("wall");
2353
- } else if (char === ".") {
2354
- row.push("pellet");
2355
- pellets++;
2356
- } else if (char === "O") {
2357
- row.push("power");
2358
- pellets++;
2359
- } else if (char === "-") {
2360
- row.push("gate");
2361
- } else {
2362
- row.push("empty");
2363
- }
2364
- }
2365
- this.grid.push(row);
2366
- }
2367
- this.state.pelletsRemaining = pellets;
2368
- this.state.totalPellets = pellets;
2369
- }
2370
- resetDaemons() {
2371
- this.daemons = [
2372
- {
2373
- id: "blinky",
2374
- name: "Blinky",
2375
- x: 13,
2376
- y: 7,
2377
- dx: 1,
2378
- dy: 0,
2379
- baseX: 25,
2380
- baseY: 1,
2381
- state: "chase",
2382
- frightenedTicks: 0,
2383
- colorName: "red"
2384
- },
2385
- {
2386
- id: "pinky",
2387
- name: "Pinky",
2388
- x: 12,
2389
- y: 11,
2390
- dx: 0,
2391
- dy: -1,
2392
- baseX: 1,
2393
- baseY: 1,
2394
- state: "chase",
2395
- frightenedTicks: 0,
2396
- colorName: "pink"
2397
- },
2398
- {
2399
- id: "inky",
2400
- name: "Inky",
2401
- x: 13,
2402
- y: 11,
2403
- dx: 0,
2404
- dy: -1,
2405
- baseX: 25,
2406
- baseY: 17,
2407
- state: "chase",
2408
- frightenedTicks: 0,
2409
- colorName: "cyan"
2410
- },
2411
- {
2412
- id: "clyde",
2413
- name: "Clyde",
2414
- x: 14,
2415
- y: 11,
2416
- dx: 0,
2417
- dy: -1,
2418
- baseX: 1,
2419
- baseY: 17,
2420
- state: "chase",
2421
- frightenedTicks: 0,
2422
- colorName: "yellow"
2423
- }
2424
- ];
2425
- }
2426
- scheduleNextTick() {
2427
- if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2428
- if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
2429
- this.gameLoopTimer = setTimeout(() => {
2430
- this.tick();
2431
- this.scheduleNextTick();
2432
- }, this.tickIntervalMs);
2433
- }
2434
- tick() {
2435
- if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2436
- this.state.mouthOpen = !this.state.mouthOpen;
2437
- if (this.state.frightenedTicksRemaining > 0) {
2438
- this.state.frightenedTicksRemaining--;
2439
- if (this.state.frightenedTicksRemaining === 0) {
2440
- for (const d of this.daemons) {
2441
- if (d.state === "frightened") d.state = "chase";
2442
- }
2443
- }
2444
- }
2445
- if (this.canMove(this.state.playerX, this.state.playerY, this.state.desiredDx, this.state.desiredDy)) {
2446
- this.state.playerDx = this.state.desiredDx;
2447
- this.state.playerDy = this.state.desiredDy;
2448
- }
2449
- if (this.canMove(this.state.playerX, this.state.playerY, this.state.playerDx, this.state.playerDy)) {
2450
- this.state.playerX += this.state.playerDx;
2451
- this.state.playerY += this.state.playerDy;
2452
- if (this.state.playerX < 0) this.state.playerX = MAZE_WIDTH - 1;
2453
- else if (this.state.playerX >= MAZE_WIDTH) this.state.playerX = 0;
2454
- this.chompCurrentTile();
2455
- }
2456
- this.moveDaemons();
2457
- this.checkCollisions();
2458
- this.render();
2459
- }
2460
- canMove(x, y, dx, dy, isDaemon = false) {
2461
- let nx = x + dx;
2462
- let ny = y + dy;
2463
- if (nx < 0) nx = MAZE_WIDTH - 1;
2464
- else if (nx >= MAZE_WIDTH) nx = 0;
2465
- if (ny < 0 || ny >= MAZE_HEIGHT) return false;
2466
- const tile = this.grid[ny]?.[nx];
2467
- if (!tile || tile === "wall") return false;
2468
- if (tile === "gate" && !isDaemon) return false;
2469
- return true;
2470
- }
2471
- chompCurrentTile() {
2472
- const tile = this.grid[this.state.playerY]?.[this.state.playerX];
2473
- if (tile === "pellet") {
2474
- this.grid[this.state.playerY][this.state.playerX] = "empty";
2475
- this.state.score += 10;
2476
- this.state.pelletsRemaining--;
2477
- this.pelletsEatenCount++;
2478
- this.config?.onScoreUpdate?.(this.state.score);
2479
- if (this.pelletsEatenCount >= 50) {
2480
- this.config?.onAchievementUnlock?.("first_chomp");
2481
- }
2482
- if (this.state.pelletsRemaining === 0) {
2483
- this.state.isWon = true;
2484
- this.config?.onAchievementUnlock?.("maze_sweeper");
2485
- return;
2486
- }
2487
- } else if (tile === "power") {
2488
- this.grid[this.state.playerY][this.state.playerX] = "empty";
2489
- this.state.score += 50;
2490
- this.state.pelletsRemaining--;
2491
- this.daemonsChompedInSurge = 0;
2492
- let surgeTicks = 45;
2493
- if (this.config?.difficulty === "easy") surgeTicks = 65;
2494
- else if (this.config?.difficulty === "hard") surgeTicks = 30;
2495
- else if (this.config?.difficulty === "insane") surgeTicks = 18;
2496
- this.state.frightenedTicksRemaining = surgeTicks;
2497
- this.state.frightenedCombo = 0;
2498
- for (const d of this.daemons) {
2499
- if (d.state !== "eaten") {
2500
- d.state = "frightened";
2501
- d.dx = -d.dx;
2502
- d.dy = -d.dy;
2503
- }
2504
- }
2505
- if (this.config?.soundEnabled) playTerminalBell();
2506
- }
2507
- }
2508
- moveDaemons() {
2509
- const directions = [
2510
- [0, -1],
2511
- // Up
2512
- [-1, 0],
2513
- // Left
2514
- [0, 1],
2515
- // Down
2516
- [1, 0]
2517
- // Right
2518
- ];
2519
- for (const d of this.daemons) {
2520
- if (d.state === "eaten") {
2521
- if (d.x === 13 && d.y === 9) {
2522
- d.state = "chase";
2523
- }
2524
- }
2525
- const validDirs = [];
2526
- for (const [dx, dy] of directions) {
2527
- if (dx === -d.dx && dy === -d.dy) continue;
2528
- if (this.canMove(d.x, d.y, dx, dy, true)) {
2529
- validDirs.push([dx, dy]);
2530
- }
2531
- }
2532
- if (validDirs.length === 0) {
2533
- if (this.canMove(d.x, d.y, -d.dx, -d.dy, true)) {
2534
- validDirs.push([-d.dx, -d.dy]);
2535
- }
2536
- }
2537
- if (validDirs.length > 0) {
2538
- let chosenDir;
2539
- if (d.state === "frightened") {
2540
- chosenDir = this.rng.pick(validDirs);
2541
- } else {
2542
- let targetX = this.state.playerX;
2543
- let targetY = this.state.playerY;
2544
- if (d.id === "pinky") {
2545
- targetX += this.state.playerDx * 4;
2546
- targetY += this.state.playerDy * 4;
2547
- } else if (d.id === "clyde") {
2548
- const dist = Math.hypot(d.x - this.state.playerX, d.y - this.state.playerY);
2549
- if (dist < 6) {
2550
- targetX = d.baseX;
2551
- targetY = d.baseY;
2552
- }
2553
- }
2554
- chosenDir = validDirs[0];
2555
- let minDist = Infinity;
2556
- for (const [vx, vy] of validDirs) {
2557
- const nx = d.x + vx;
2558
- const ny = d.y + vy;
2559
- const dist = Math.hypot(nx - targetX, ny - targetY);
2560
- if (dist < minDist) {
2561
- minDist = dist;
2562
- chosenDir = [vx, vy];
2563
- }
2564
- }
2565
- }
2566
- d.dx = chosenDir[0];
2567
- d.dy = chosenDir[1];
2568
- d.x += d.dx;
2569
- d.y += d.dy;
2570
- if (d.x < 0) d.x = MAZE_WIDTH - 1;
2571
- else if (d.x >= MAZE_WIDTH) d.x = 0;
2572
- }
2573
- }
2574
- }
2575
- checkCollisions() {
2576
- for (const d of this.daemons) {
2577
- if (d.x === this.state.playerX && d.y === this.state.playerY) {
2578
- if (d.state === "frightened") {
2579
- d.state = "eaten";
2580
- d.x = 13;
2581
- d.y = 9;
2582
- this.state.frightenedCombo++;
2583
- const points = 200 * Math.pow(2, this.state.frightenedCombo - 1);
2584
- this.state.score += points;
2585
- this.daemonsChompedInSurge++;
2586
- if (this.daemonsChompedInSurge >= 4) {
2587
- this.config?.onAchievementUnlock?.("daemon_slayer");
2588
- }
2589
- if (this.config?.soundEnabled) playTerminalBell();
2590
- } else if (d.state === "chase") {
2591
- this.state.lives--;
2592
- if (this.config?.soundEnabled) playTerminalBell();
2593
- if (this.state.lives <= 0) {
2594
- this.state.isGameOver = true;
2595
- this.config?.onGameOver?.(this.state.score);
2596
- } else {
2597
- this.state.playerX = 13;
2598
- this.state.playerY = 13;
2599
- this.state.playerDx = -1;
2600
- this.state.playerDy = 0;
2601
- this.state.desiredDx = -1;
2602
- this.state.desiredDy = 0;
2603
- this.resetDaemons();
2604
- }
2605
- break;
2606
- }
2607
- }
2608
- }
2609
- }
2610
- handleInput(key) {
2611
- if (this.showTutorial) {
2612
- if (key.name === "return" || key.name === "space") {
2613
- this.showTutorial = false;
2614
- this.scheduleNextTick();
2615
- this.render();
2616
- } else if (key.name === "escape" || key.name === "q") {
2617
- this.destroy();
2618
- this.config?.onExit?.();
2619
- }
2620
- return;
2621
- }
2622
- if (this.isPaused) {
2623
- if (key.name === "up" || key.name === "w") {
2624
- this.pauseMenuIndex = (this.pauseMenuIndex - 1 + 3) % 3;
2625
- this.render();
2626
- } else if (key.name === "down" || key.name === "s") {
2627
- this.pauseMenuIndex = (this.pauseMenuIndex + 1) % 3;
2628
- this.render();
2629
- } else if (key.name === "return" || key.name === "space") {
2630
- if (this.pauseMenuIndex === 0) {
2631
- this.isPaused = false;
2632
- this.scheduleNextTick();
2633
- this.render();
2634
- } else if (this.pauseMenuIndex === 1) {
2635
- this.isPaused = false;
2636
- this.resetGame(this.state.level, this.config?.difficulty || "normal");
2637
- this.scheduleNextTick();
2638
- this.render();
2639
- } else if (this.pauseMenuIndex === 2) {
2640
- this.destroy();
2641
- this.config?.onExit?.();
2642
- }
2643
- } else if (key.name === "escape" || key.name === "p") {
2644
- this.isPaused = false;
2645
- this.scheduleNextTick();
2646
- this.render();
2647
- } else if (key.name === "q") {
2648
- this.destroy();
2649
- this.config?.onExit?.();
2650
- }
2651
- return;
2652
- }
2653
- if (key.name === "escape" || key.name === "p") {
2654
- this.isPaused = true;
2655
- this.pauseMenuIndex = 0;
2656
- if (this.gameLoopTimer) {
2657
- clearTimeout(this.gameLoopTimer);
2658
- this.gameLoopTimer = null;
2659
- }
2660
- this.render();
2661
- return;
2662
- }
2663
- if (key.name === "q") {
2664
- this.destroy();
2665
- this.config?.onExit?.();
2666
- return;
2667
- }
2668
- if (this.state.isWon) {
2669
- if (key.name === "return" || key.name === "space") {
2670
- this.resetGame(this.state.level + 1, this.config?.difficulty || "normal");
2671
- this.scheduleNextTick();
2672
- this.render();
2673
- } else if (key.name === "escape" || key.name === "q") {
2674
- this.destroy();
2675
- this.config?.onExit?.();
2238
+ if (this.gameLoopTimer) {
2239
+ clearTimeout(this.gameLoopTimer);
2240
+ this.gameLoopTimer = null;
2676
2241
  }
2242
+ this.render();
2243
+ return;
2244
+ }
2245
+ if (key.name === "q") {
2246
+ this.destroy();
2247
+ this.config?.onExit?.();
2677
2248
  return;
2678
2249
  }
2679
2250
  if (this.state.isGameOver) {
@@ -2686,17 +2257,25 @@ var PacketManGame = class {
2686
2257
  return;
2687
2258
  }
2688
2259
  if (key.name === "up" || key.name === "w") {
2689
- this.state.desiredDx = 0;
2690
- this.state.desiredDy = -1;
2260
+ if (this.state.dy !== 1) {
2261
+ this.state.desiredDx = 0;
2262
+ this.state.desiredDy = -1;
2263
+ }
2691
2264
  } else if (key.name === "down" || key.name === "s") {
2692
- this.state.desiredDx = 0;
2693
- this.state.desiredDy = 1;
2265
+ if (this.state.dy !== -1) {
2266
+ this.state.desiredDx = 0;
2267
+ this.state.desiredDy = 1;
2268
+ }
2694
2269
  } else if (key.name === "left" || key.name === "a") {
2695
- this.state.desiredDx = -1;
2696
- this.state.desiredDy = 0;
2270
+ if (this.state.dx !== 1) {
2271
+ this.state.desiredDx = -1;
2272
+ this.state.desiredDy = 0;
2273
+ }
2697
2274
  } else if (key.name === "right" || key.name === "d") {
2698
- this.state.desiredDx = 1;
2699
- this.state.desiredDy = 0;
2275
+ if (this.state.dx !== -1) {
2276
+ this.state.desiredDx = 1;
2277
+ this.state.desiredDy = 0;
2278
+ }
2700
2279
  }
2701
2280
  }
2702
2281
  render() {
@@ -2704,18 +2283,17 @@ var PacketManGame = class {
2704
2283
  if (this.showTutorial) {
2705
2284
  const lines = [
2706
2285
  "",
2707
- t.highlight("OBJECTIVE: CHOMP BYTE PELLETS & PURGE DAEMONS"),
2286
+ t.highlight("OBJECTIVE: FEAST AND GROW THE CYBER VIPER"),
2708
2287
  "",
2709
- "\u2022 Use Arrow Keys or WASD to navigate memory corridors.",
2710
- "\u2022 Chomp all data pellets [ \xB7 ] to clear the sector.",
2711
- "\u2022 Ingest Super Capacitors [ \u25CF ] to trigger Power Surge state.",
2712
- "\u2022 During Power Surge, hunt vulnerable memory daemons for huge multipliers!",
2713
- "\u2022 Wrap through the side tunnels to evade ambushes.",
2288
+ "\u2022 Use Arrow Keys or WASD to steer the viper.",
2289
+ "\u2022 Eat glowing Energy Apples [ \u25C6 ] to grow longer and gain +100 score.",
2290
+ "\u2022 Snag rare Golden Orbs [ \u2605 ] before they vanish for +500 points!",
2291
+ "\u2022 Do NOT crash into the grid borders or your own tail.",
2714
2292
  "",
2715
2293
  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"),
2716
- t.primary("Press Space or Enter to start \u2502 Esc / Q to Exit")
2294
+ t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
2717
2295
  ];
2718
- const box = this.renderer.createBox(lines, 64, "PACKET MAN PROTOCOL MANUAL");
2296
+ const box = this.renderer.createBox(lines, 64, "CYBER VIPER MANUAL");
2719
2297
  this.renderer.clear();
2720
2298
  this.renderer.draw(`
2721
2299
 
@@ -2724,10 +2302,10 @@ ${box}
2724
2302
  return;
2725
2303
  }
2726
2304
  if (this.isPaused) {
2727
- const pauseItems = ["Resume Arcade (Esc / Enter)", "Restart Round (R)", "Quit to Arcade / Terminal (Q)"];
2305
+ const pauseItems = ["Resume Viper (Esc / Enter)", "Restart Round (R)", "Return to Game List (Q)"];
2728
2306
  const pauseLines = [
2729
2307
  "",
2730
- t.highlight("\u2550\u2550\u2550 MEMORY MAZE PAUSED \u2550\u2550\u2550"),
2308
+ t.highlight("\u2550\u2550\u2550 VIPER RUN PAUSED \u2550\u2550\u2550"),
2731
2309
  "",
2732
2310
  ...pauseItems.map((item, idx) => {
2733
2311
  if (idx === this.pauseMenuIndex) {
@@ -2737,7 +2315,7 @@ ${box}
2737
2315
  }),
2738
2316
  "",
2739
2317
  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"),
2740
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
2318
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Return to Game List")
2741
2319
  ];
2742
2320
  const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
2743
2321
  this.renderer.clear();
@@ -2748,56 +2326,52 @@ ${pauseBox}
2748
2326
  return;
2749
2327
  }
2750
2328
  const header = this.renderer.renderHeader({
2751
- title: "PACKET MAN",
2329
+ title: "CYBER VIPER",
2752
2330
  category: "ARCADE",
2753
2331
  difficulty: this.config?.difficulty,
2754
- score: this.state.score,
2755
- level: this.state.level
2332
+ score: this.state.score
2756
2333
  });
2757
2334
  const hudLines = [];
2758
- const livesStr = `${t.muted("Buffer Lives:")} ${t.highlight("\u25BA ".repeat(Math.max(0, this.state.lives)))}`;
2759
- const surgeStr = this.state.frightenedTicksRemaining > 0 ? t.warning(`\u26A1 OVERCLOCK SURGE [${Math.ceil(this.state.frightenedTicksRemaining / 5)}s]`) : t.muted("NORMAL FLUX");
2760
- hudLines.push(` ${livesStr} ${surgeStr} ${t.muted("Pellets:")} ${t.primary(this.state.pelletsRemaining.toString())}`);
2335
+ const lenStr = `${t.muted("Length:")} ${t.primary(this.state.snake.length.toString())}`;
2336
+ const applesStr = `${t.muted("Apples:")} ${t.accent(this.state.applesEaten.toString())}`;
2337
+ const goldStr = this.state.goldenFoodTicks > 0 ? t.warning(`\u2605 GOLDEN ORB ACTIVE [${Math.ceil(this.state.goldenFoodTicks / 10)}s]`) : "";
2338
+ hudLines.push(` ${lenStr} ${applesStr} ${goldStr}`);
2761
2339
  const boardLines = [];
2762
- for (let y = 0; y < MAZE_HEIGHT; y++) {
2763
- let row = " ";
2764
- for (let x = 0; x < MAZE_WIDTH; x++) {
2765
- if (x === this.state.playerX && y === this.state.playerY) {
2766
- const char = this.getPlayerGlyph();
2767
- row += t.highlight(char);
2340
+ boardLines.push(` ${t.border("\u2554" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u2557")}`);
2341
+ for (let y = 0; y < GRID_HEIGHT; y++) {
2342
+ let row = ` ${t.border("\u2551")}`;
2343
+ for (let x = 0; x < GRID_WIDTH; x++) {
2344
+ if (x === this.state.snake[0].x && y === this.state.snake[0].y) {
2345
+ row += t.highlight("\u25C6 ");
2768
2346
  continue;
2769
2347
  }
2770
- const daemon = this.daemons.find((d) => d.x === x && d.y === y);
2771
- if (daemon) {
2772
- row += this.getDaemonGlyph(daemon);
2348
+ const isBody = this.state.snake.some((s, idx) => idx > 0 && s.x === x && s.y === y);
2349
+ if (isBody) {
2350
+ row += t.success("\u25A0 ");
2773
2351
  continue;
2774
2352
  }
2775
- const tile = this.grid[y][x];
2776
- if (tile === "wall") {
2777
- row += t.border("\u2588\u2588");
2778
- } else if (tile === "pellet") {
2779
- row += t.primary(" \xB7");
2780
- } else if (tile === "power") {
2781
- row += t.accent(" \u25CF");
2782
- } else if (tile === "gate") {
2783
- row += t.secondary("\u2550\u2550");
2784
- } else {
2785
- row += " ";
2353
+ if (x === this.state.food.x && y === this.state.food.y) {
2354
+ row += t.error("\u25C6 ");
2355
+ continue;
2356
+ }
2357
+ if (this.state.goldenFood && x === this.state.goldenFood.x && y === this.state.goldenFood.y) {
2358
+ row += t.accent("\u2605 ");
2359
+ continue;
2786
2360
  }
2361
+ row += " ";
2787
2362
  }
2363
+ row += t.border("\u2551");
2788
2364
  boardLines.push(row);
2789
2365
  }
2790
- if (this.state.isWon) {
2791
- boardLines.push(`
2792
- ${t.success("\u{1F389} MEMORY SECTOR COMPLETELY PURGED! EXCELLENT OPERATOR.")}`);
2793
- boardLines.push(` ${t.primary("Press Space or Enter for Next Level...")}`);
2794
- } else if (this.state.isGameOver) {
2366
+ boardLines.push(` ${t.border("\u255A" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u255D")}`);
2367
+ if (this.state.isGameOver) {
2795
2368
  boardLines.push(`
2796
- ${t.error("\u{1F4A5} SYSTEM FAULT: LIVES DEPLETED. KERNEL DUMP.")}`);
2797
- boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Exit.")}`);
2369
+ ${t.error("\u{1F4A5} COLLISION! VIPER TERMINATED.")}`);
2370
+ boardLines.push(` ${t.accent(`Final Length: ${this.state.snake.length} segments \u2502 Final Score: ${this.state.score}`)}`);
2371
+ boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Return to Game List.")}`);
2798
2372
  } else {
2799
2373
  boardLines.push(`
2800
- ${t.muted("Controls: Arrows/WASD: Move \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
2374
+ ${t.muted("Controls: Arrows/WASD: Steer \u2502 Esc/P: Pause \u2502 Q: Return to Game List")}`);
2801
2375
  }
2802
2376
  this.renderer.clear();
2803
2377
  this.renderer.draw(`
@@ -2806,69 +2380,44 @@ ${hudLines.join("\n")}
2806
2380
  ${boardLines.join("\n")}
2807
2381
  `);
2808
2382
  }
2809
- getPlayerGlyph() {
2810
- if (!this.state.mouthOpen) return "\u25CB ";
2811
- if (this.state.playerDx === 1) return "\u25BA ";
2812
- if (this.state.playerDx === -1) return "\u25C4 ";
2813
- if (this.state.playerDy === -1) return "\u25B2 ";
2814
- if (this.state.playerDy === 1) return "\u25BC ";
2815
- return "\u25BA ";
2816
- }
2817
- getDaemonGlyph(d) {
2818
- const t = this.renderer.getTheme();
2819
- if (d.state === "frightened") {
2820
- if (this.state.frightenedTicksRemaining < 10 && this.state.frightenedTicksRemaining % 2 === 0) {
2821
- return t.accent("\xA7 ");
2822
- }
2823
- return t.secondary("\xA7 ");
2824
- }
2825
- if (d.state === "eaten") {
2826
- return t.muted('""');
2827
- }
2828
- if (d.colorName === "red") return t.error("M ");
2829
- if (d.colorName === "pink") return t.secondary("M ");
2830
- if (d.colorName === "cyan") return t.primary("M ");
2831
- return t.accent("M ");
2832
- }
2833
2383
  getState() {
2834
2384
  return this.state;
2835
2385
  }
2836
2386
  };
2837
2387
 
2838
- // src/games/cyber-viper/index.ts
2839
- var GRID_WIDTH = 30;
2840
- var GRID_HEIGHT = 16;
2841
- var CyberViperGame = class {
2842
- id = "cyber-viper";
2843
- metadata = ALL_GAMES_METADATA["cyber-viper"];
2388
+ // src/games/void-invaders/index.ts
2389
+ var ARENA_WIDTH = 52;
2390
+ var ARENA_HEIGHT = 16;
2391
+ var PLAYER_Y = 15;
2392
+ var VoidInvadersGame = class {
2393
+ id = "void-invaders";
2394
+ metadata = ALL_GAMES_METADATA["void-invaders"];
2844
2395
  config = null;
2845
2396
  renderer = defaultRenderer;
2846
2397
  input = new TerminalInputHandler();
2847
2398
  rng = new DeterministicRNG();
2848
2399
  gameLoopTimer = null;
2400
+ invaderIdCounter = 0;
2401
+ baseSpeedTicks = 12;
2849
2402
  state = {
2850
- snake: [
2851
- { x: 15, y: 8 },
2852
- { x: 14, y: 8 },
2853
- { x: 13, y: 8 }
2854
- ],
2855
- dx: 1,
2856
- dy: 0,
2857
- desiredDx: 1,
2858
- desiredDy: 0,
2859
- food: { x: 22, y: 8 },
2860
- goldenFood: null,
2861
- goldenFoodTicks: 0,
2403
+ playerX: 24,
2404
+ playerY: PLAYER_Y,
2405
+ lives: 3,
2862
2406
  score: 0,
2863
- highScore: 0,
2864
- applesEaten: 0,
2407
+ invadersDestroyed: 0,
2408
+ wave: 1,
2409
+ descentSpeedTicks: 12,
2410
+ descentTickCounter: 0,
2411
+ currentInvader: null,
2412
+ bullets: [],
2865
2413
  isGameOver: false,
2866
2414
  isWon: false
2867
2415
  };
2868
2416
  isPaused = false;
2869
2417
  pauseMenuIndex = 0;
2870
2418
  showTutorial = true;
2871
- tickIntervalMs = 120;
2419
+ tickIntervalMs = 45;
2420
+ // Smooth 22 FPS loop
2872
2421
  init(config) {
2873
2422
  this.config = config;
2874
2423
  this.renderer.setTheme(config.theme);
@@ -2876,7 +2425,7 @@ var CyberViperGame = class {
2876
2425
  if (config.skipTutorial !== void 0) {
2877
2426
  this.showTutorial = !config.skipTutorial;
2878
2427
  }
2879
- this.resetState(config.difficulty);
2428
+ this.resetGame(config.difficulty);
2880
2429
  }
2881
2430
  start() {
2882
2431
  this.isPaused = false;
@@ -2904,7 +2453,7 @@ var CyberViperGame = class {
2904
2453
  }
2905
2454
  restart() {
2906
2455
  if (this.config) {
2907
- this.resetState(this.config.difficulty);
2456
+ this.resetGame(this.config.difficulty);
2908
2457
  this.scheduleNextTick();
2909
2458
  this.render();
2910
2459
  }
@@ -2926,141 +2475,148 @@ var CyberViperGame = class {
2926
2475
  }
2927
2476
  this.input.stop();
2928
2477
  }
2929
- resetState(difficulty) {
2478
+ resetGame(difficulty) {
2930
2479
  switch (difficulty) {
2931
2480
  case "easy":
2932
- this.tickIntervalMs = 160;
2481
+ this.baseSpeedTicks = 14;
2933
2482
  break;
2934
2483
  case "normal":
2935
- this.tickIntervalMs = 120;
2936
- break;
2937
- case "hard":
2938
- this.tickIntervalMs = 85;
2939
- break;
2940
- case "insane":
2941
- this.tickIntervalMs = 55;
2942
- break;
2943
- }
2944
- this.state = {
2945
- snake: [
2946
- { x: 15, y: 8 },
2947
- { x: 14, y: 8 },
2948
- { x: 13, y: 8 }
2949
- ],
2950
- dx: 1,
2951
- dy: 0,
2952
- desiredDx: 1,
2953
- desiredDy: 0,
2954
- food: { x: 22, y: 8 },
2955
- goldenFood: null,
2956
- goldenFoodTicks: 0,
2957
- score: 0,
2958
- highScore: this.state.highScore,
2959
- applesEaten: 0,
2960
- isGameOver: false,
2961
- isWon: false
2962
- };
2963
- this.spawnFood();
2964
- }
2965
- scheduleNextTick() {
2966
- if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2967
- if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
2968
- this.gameLoopTimer = setTimeout(() => {
2969
- this.tick();
2970
- this.scheduleNextTick();
2971
- }, this.tickIntervalMs);
2972
- }
2973
- tick() {
2974
- if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2975
- if (this.state.desiredDx !== -this.state.dx || this.state.desiredDy !== -this.state.dy) {
2976
- this.state.dx = this.state.desiredDx;
2977
- this.state.dy = this.state.desiredDy;
2978
- }
2979
- const head = this.state.snake[0];
2980
- const newHead = {
2981
- x: head.x + this.state.dx,
2982
- y: head.y + this.state.dy
2983
- };
2984
- if (newHead.x < 0 || newHead.x >= GRID_WIDTH || newHead.y < 0 || newHead.y >= GRID_HEIGHT) {
2985
- this.state.isGameOver = true;
2986
- this.config?.onGameOver?.(this.state.score);
2987
- if (this.config?.soundEnabled) playTerminalBell();
2988
- this.render();
2989
- return;
2990
- }
2991
- for (let i = 0; i < this.state.snake.length - 1; i++) {
2992
- const seg = this.state.snake[i];
2993
- if (seg.x === newHead.x && seg.y === newHead.y) {
2994
- this.state.isGameOver = true;
2995
- this.config?.onGameOver?.(this.state.score);
2996
- if (this.config?.soundEnabled) playTerminalBell();
2997
- this.render();
2998
- return;
2999
- }
3000
- }
3001
- this.state.snake.unshift(newHead);
3002
- if (this.state.goldenFoodTicks > 0) {
3003
- this.state.goldenFoodTicks--;
3004
- if (this.state.goldenFoodTicks === 0) {
3005
- this.state.goldenFood = null;
3006
- }
3007
- }
3008
- let grew = false;
3009
- if (newHead.x === this.state.food.x && newHead.y === this.state.food.y) {
3010
- grew = true;
3011
- this.state.score += 100;
3012
- this.state.applesEaten++;
3013
- this.config?.onScoreUpdate?.(this.state.score);
3014
- this.config?.onAchievementUnlock?.("first_bite");
3015
- if (this.state.snake.length >= 25) {
3016
- this.config?.onAchievementUnlock?.("long_viper");
3017
- }
3018
- if (this.config?.soundEnabled) playTerminalBell();
3019
- this.spawnFood();
3020
- if (this.rng.next() < 0.25 && !this.state.goldenFood) {
3021
- this.spawnGoldenFood();
3022
- }
3023
- } else if (this.state.goldenFood && newHead.x === this.state.goldenFood.x && newHead.y === this.state.goldenFood.y) {
3024
- grew = true;
3025
- this.state.score += 500;
3026
- this.state.goldenFood = null;
3027
- this.state.goldenFoodTicks = 0;
3028
- this.config?.onScoreUpdate?.(this.state.score);
3029
- this.config?.onAchievementUnlock?.("golden_feast");
3030
- if (this.config?.soundEnabled) playTerminalBell();
2484
+ this.baseSpeedTicks = 11;
2485
+ break;
2486
+ case "hard":
2487
+ this.baseSpeedTicks = 8;
2488
+ break;
2489
+ case "insane":
2490
+ this.baseSpeedTicks = 6;
2491
+ break;
3031
2492
  }
3032
- if (!grew) {
3033
- this.state.snake.pop();
2493
+ this.state = {
2494
+ playerX: 24,
2495
+ playerY: PLAYER_Y,
2496
+ lives: 3,
2497
+ score: 0,
2498
+ invadersDestroyed: 0,
2499
+ wave: 1,
2500
+ descentSpeedTicks: this.baseSpeedTicks,
2501
+ descentTickCounter: 0,
2502
+ currentInvader: null,
2503
+ bullets: [],
2504
+ isGameOver: false,
2505
+ isWon: false
2506
+ };
2507
+ this.spawnNextInvader();
2508
+ }
2509
+ spawnNextInvader() {
2510
+ const x = this.rng.nextInt(2, ARENA_WIDTH - 6);
2511
+ const roll = this.rng.next();
2512
+ let type = "scout";
2513
+ let glyph = "\u203B ";
2514
+ let points = 100;
2515
+ if (roll < 0.45) {
2516
+ type = "scout";
2517
+ glyph = "\u203B ";
2518
+ points = 100;
2519
+ } else if (roll < 0.75) {
2520
+ type = "fighter";
2521
+ glyph = "\u{1F47E}";
2522
+ points = 150;
2523
+ } else if (roll < 0.92) {
2524
+ type = "bomber";
2525
+ glyph = "W ";
2526
+ points = 200;
2527
+ } else {
2528
+ type = "mothership";
2529
+ glyph = "\u{1F6F8}";
2530
+ points = 400;
2531
+ }
2532
+ this.state.currentInvader = {
2533
+ id: ++this.invaderIdCounter,
2534
+ type,
2535
+ x,
2536
+ y: 1,
2537
+ glyph,
2538
+ points,
2539
+ alive: true
2540
+ };
2541
+ }
2542
+ scheduleNextTick() {
2543
+ if (this.gameLoopTimer) clearTimeout(this.gameLoopTimer);
2544
+ if (this.isPaused || this.state.isGameOver || this.state.isWon || this.showTutorial) return;
2545
+ this.gameLoopTimer = setTimeout(() => {
2546
+ this.tick();
2547
+ this.scheduleNextTick();
2548
+ }, this.tickIntervalMs);
2549
+ }
2550
+ tick() {
2551
+ if (this.state.isGameOver || this.state.isWon || this.isPaused || this.showTutorial) return;
2552
+ this.updateBullets();
2553
+ this.checkCollisions();
2554
+ this.state.descentTickCounter++;
2555
+ if (this.state.descentTickCounter >= this.state.descentSpeedTicks) {
2556
+ this.state.descentTickCounter = 0;
2557
+ this.advanceInvaderDescent();
3034
2558
  }
3035
2559
  this.render();
3036
2560
  }
3037
- spawnFood() {
3038
- const emptyCells = [];
3039
- for (let y = 0; y < GRID_HEIGHT; y++) {
3040
- for (let x = 0; x < GRID_WIDTH; x++) {
3041
- if (!this.state.snake.some((s) => s.x === x && s.y === y)) {
3042
- emptyCells.push({ x, y });
3043
- }
2561
+ updateBullets() {
2562
+ const nextBullets = [];
2563
+ for (const b of this.state.bullets) {
2564
+ b.y -= 1;
2565
+ if (b.y >= 0) {
2566
+ nextBullets.push(b);
3044
2567
  }
3045
2568
  }
3046
- if (emptyCells.length > 0) {
3047
- this.state.food = this.rng.pick(emptyCells);
3048
- } else {
3049
- this.state.isWon = true;
2569
+ this.state.bullets = nextBullets;
2570
+ }
2571
+ advanceInvaderDescent() {
2572
+ const inv = this.state.currentInvader;
2573
+ if (!inv || !inv.alive) {
2574
+ this.spawnNextInvader();
2575
+ return;
2576
+ }
2577
+ inv.y += 1;
2578
+ if (inv.y >= PLAYER_Y) {
2579
+ inv.alive = false;
2580
+ this.state.lives -= 1;
2581
+ if (this.config?.soundEnabled) playTerminalBell();
2582
+ if (this.state.lives <= 0) {
2583
+ this.state.isGameOver = true;
2584
+ this.config?.onGameOver?.(this.state.score);
2585
+ } else {
2586
+ this.spawnNextInvader();
2587
+ }
3050
2588
  }
3051
2589
  }
3052
- spawnGoldenFood() {
3053
- const emptyCells = [];
3054
- for (let y = 0; y < GRID_HEIGHT; y++) {
3055
- for (let x = 0; x < GRID_WIDTH; x++) {
3056
- if (!this.state.snake.some((s) => s.x === x && s.y === y) && (x !== this.state.food.x || y !== this.state.food.y)) {
3057
- emptyCells.push({ x, y });
2590
+ checkCollisions() {
2591
+ const inv = this.state.currentInvader;
2592
+ if (!inv || !inv.alive) return;
2593
+ const remainingBullets = [];
2594
+ let invaderHit = false;
2595
+ for (const b of this.state.bullets) {
2596
+ if ((b.y === inv.y || b.y === inv.y - 1) && b.x >= inv.x - 1 && b.x <= inv.x + 2) {
2597
+ invaderHit = true;
2598
+ inv.alive = false;
2599
+ this.state.score += inv.points;
2600
+ this.state.invadersDestroyed++;
2601
+ this.state.descentSpeedTicks = Math.max(2, this.baseSpeedTicks - Math.floor(this.state.invadersDestroyed / 4));
2602
+ this.state.wave = 1 + Math.floor(this.state.invadersDestroyed / 10);
2603
+ this.config?.onScoreUpdate?.(this.state.score);
2604
+ this.config?.onAchievementUnlock?.("alien_down");
2605
+ if (inv.type === "mothership") {
2606
+ this.config?.onAchievementUnlock?.("mothership_shot");
3058
2607
  }
2608
+ if (this.state.invadersDestroyed >= 20) {
2609
+ this.config?.onAchievementUnlock?.("wave_cleared");
2610
+ }
2611
+ if (this.config?.soundEnabled) playTerminalBell();
2612
+ break;
2613
+ } else {
2614
+ remainingBullets.push(b);
3059
2615
  }
3060
2616
  }
3061
- if (emptyCells.length > 0) {
3062
- this.state.goldenFood = this.rng.pick(emptyCells);
3063
- this.state.goldenFoodTicks = 70;
2617
+ if (invaderHit) {
2618
+ this.state.bullets = remainingBullets;
2619
+ this.spawnNextInvader();
3064
2620
  }
3065
2621
  }
3066
2622
  handleInput(key) {
@@ -3089,7 +2645,7 @@ var CyberViperGame = class {
3089
2645
  this.render();
3090
2646
  } else if (this.pauseMenuIndex === 1) {
3091
2647
  this.isPaused = false;
3092
- this.resetState(this.config?.difficulty || "normal");
2648
+ this.resetGame(this.config?.difficulty || "normal");
3093
2649
  this.scheduleNextTick();
3094
2650
  this.render();
3095
2651
  } else if (this.pauseMenuIndex === 2) {
@@ -3130,25 +2686,24 @@ var CyberViperGame = class {
3130
2686
  }
3131
2687
  return;
3132
2688
  }
3133
- if (key.name === "up" || key.name === "w") {
3134
- if (this.state.dy !== 1) {
3135
- this.state.desiredDx = 0;
3136
- this.state.desiredDy = -1;
3137
- }
3138
- } else if (key.name === "down" || key.name === "s") {
3139
- if (this.state.dy !== -1) {
3140
- this.state.desiredDx = 0;
3141
- this.state.desiredDy = 1;
3142
- }
3143
- } else if (key.name === "left" || key.name === "a") {
3144
- if (this.state.dx !== 1) {
3145
- this.state.desiredDx = -1;
3146
- this.state.desiredDy = 0;
2689
+ if (key.name === "left" || key.name === "a") {
2690
+ if (this.state.playerX > 1) {
2691
+ this.state.playerX -= 2;
2692
+ this.render();
3147
2693
  }
3148
2694
  } else if (key.name === "right" || key.name === "d") {
3149
- if (this.state.dx !== -1) {
3150
- this.state.desiredDx = 1;
3151
- this.state.desiredDy = 0;
2695
+ if (this.state.playerX < ARENA_WIDTH - 4) {
2696
+ this.state.playerX += 2;
2697
+ this.render();
2698
+ }
2699
+ } else if (key.name === "space" || key.name === "up" || key.name === "w") {
2700
+ if (this.state.bullets.length < 3) {
2701
+ this.state.bullets.push({
2702
+ x: this.state.playerX + 1,
2703
+ y: PLAYER_Y - 1
2704
+ });
2705
+ if (this.config?.soundEnabled) playTerminalBell();
2706
+ this.render();
3152
2707
  }
3153
2708
  }
3154
2709
  }
@@ -3157,17 +2712,18 @@ var CyberViperGame = class {
3157
2712
  if (this.showTutorial) {
3158
2713
  const lines = [
3159
2714
  "",
3160
- t.highlight("OBJECTIVE: FEAST AND GROW THE CYBER VIPER"),
2715
+ t.highlight("MISSION BRIEFING: INTERCEPT DESCENDING INVADERS"),
3161
2716
  "",
3162
- "\u2022 Use Arrow Keys or WASD to steer the viper.",
3163
- "\u2022 Eat glowing Energy Apples [ \u25C6 ] to grow longer and gain +100 score.",
3164
- "\u2022 Snag rare Golden Orbs [ \u2605 ] before they vanish for +500 points!",
3165
- "\u2022 Do NOT crash into the grid borders or your own tail.",
2717
+ "\u2022 Invaders drop from the top of the screen one at a time at random spots.",
2718
+ "\u2022 Slide your Laser Cannon Left & Right to line up your shot.",
2719
+ "\u2022 Press Spacebar to shoot them down BEFORE they reach the ground!",
2720
+ "\u2022 If an invader touches the ground, you lose 1 Cannon Life.",
2721
+ "\u2022 You have 3 Lives. Speed increases gradually as you score higher!",
3166
2722
  "",
3167
2723
  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"),
3168
- t.primary("Press Space or Enter to launch \u2502 Esc / Q to Exit")
2724
+ t.primary("Press Space or Enter to engage armada \u2502 Esc / Q to Exit")
3169
2725
  ];
3170
- const box = this.renderer.createBox(lines, 64, "CYBER VIPER MANUAL");
2726
+ const box = this.renderer.createBox(lines, 64, "SPACE INVADERS MANUAL");
3171
2727
  this.renderer.clear();
3172
2728
  this.renderer.draw(`
3173
2729
 
@@ -3176,10 +2732,10 @@ ${box}
3176
2732
  return;
3177
2733
  }
3178
2734
  if (this.isPaused) {
3179
- const pauseItems = ["Resume Viper (Esc / Enter)", "Restart Round (R)", "Quit to Arcade / Terminal (Q)"];
2735
+ const pauseItems = ["Resume Battle (Esc / Enter)", "Restart Round (R)", "Return to Game List (Q)"];
3180
2736
  const pauseLines = [
3181
2737
  "",
3182
- t.highlight("\u2550\u2550\u2550 VIPER RUN PAUSED \u2550\u2550\u2550"),
2738
+ t.highlight("\u2550\u2550\u2550 SPACE INVADERS PAUSED \u2550\u2550\u2550"),
3183
2739
  "",
3184
2740
  ...pauseItems.map((item, idx) => {
3185
2741
  if (idx === this.pauseMenuIndex) {
@@ -3189,7 +2745,7 @@ ${box}
3189
2745
  }),
3190
2746
  "",
3191
2747
  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"),
3192
- t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Quit")
2748
+ t.muted("Use Up/Down to navigate \u2502 Enter: Select \u2502 Esc: Resume \u2502 Q: Return to Game List")
3193
2749
  ];
3194
2750
  const pauseBox = this.renderer.createBox(pauseLines, 64, "SYSTEM PAUSE");
3195
2751
  this.renderer.clear();
@@ -3200,52 +2756,70 @@ ${pauseBox}
3200
2756
  return;
3201
2757
  }
3202
2758
  const header = this.renderer.renderHeader({
3203
- title: "CYBER VIPER",
2759
+ title: "SPACE INVADERS",
3204
2760
  category: "ARCADE",
3205
2761
  difficulty: this.config?.difficulty,
3206
2762
  score: this.state.score
3207
2763
  });
3208
2764
  const hudLines = [];
3209
- const lenStr = `${t.muted("Length:")} ${t.primary(this.state.snake.length.toString())}`;
3210
- const applesStr = `${t.muted("Apples:")} ${t.accent(this.state.applesEaten.toString())}`;
3211
- const goldStr = this.state.goldenFoodTicks > 0 ? t.warning(`\u2605 GOLDEN ORB ACTIVE [${Math.ceil(this.state.goldenFoodTicks / 10)}s]`) : "";
3212
- hudLines.push(` ${lenStr} ${applesStr} ${goldStr}`);
2765
+ const livesStr = `${t.muted("Cannons:")} ${t.highlight("\u25B2\u2550\u25B2 ".repeat(Math.max(0, this.state.lives)))}`;
2766
+ const defeatedStr = `${t.muted("Destroyed:")} ${t.primary(this.state.invadersDestroyed.toString())}`;
2767
+ const levelStr = `${t.muted("Level:")} ${t.secondary(this.state.wave.toString())}`;
2768
+ hudLines.push(` ${livesStr} ${defeatedStr} ${levelStr}`);
2769
+ const grid = [];
2770
+ for (let y = 0; y < ARENA_HEIGHT; y++) {
2771
+ grid.push(new Array(ARENA_WIDTH).fill(" "));
2772
+ }
2773
+ const inv = this.state.currentInvader;
2774
+ if (inv && inv.alive && inv.y >= 0 && inv.y < ARENA_HEIGHT) {
2775
+ const glyph = inv.glyph;
2776
+ if (inv.x >= 0 && inv.x < ARENA_WIDTH) grid[inv.y][inv.x] = glyph[0];
2777
+ if (inv.x + 1 >= 0 && inv.x + 1 < ARENA_WIDTH) grid[inv.y][inv.x + 1] = glyph[1];
2778
+ }
2779
+ for (const b of this.state.bullets) {
2780
+ if (b.y >= 0 && b.y < ARENA_HEIGHT && b.x >= 0 && b.x < ARENA_WIDTH) {
2781
+ grid[b.y][b.x] = "\u2502";
2782
+ }
2783
+ }
2784
+ const px = this.state.playerX;
2785
+ if (px >= 0 && px + 2 < ARENA_WIDTH) {
2786
+ grid[PLAYER_Y][px] = "\u25B2";
2787
+ grid[PLAYER_Y][px + 1] = "\u2550";
2788
+ grid[PLAYER_Y][px + 2] = "\u25B2";
2789
+ }
3213
2790
  const boardLines = [];
3214
- boardLines.push(` ${t.border("\u2554" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u2557")}`);
3215
- for (let y = 0; y < GRID_HEIGHT; y++) {
3216
- let row = ` ${t.border("\u2551")}`;
3217
- for (let x = 0; x < GRID_WIDTH; x++) {
3218
- if (x === this.state.snake[0].x && y === this.state.snake[0].y) {
3219
- row += t.highlight("\u25C6 ");
3220
- continue;
3221
- }
3222
- const isBody = this.state.snake.some((s, idx) => idx > 0 && s.x === x && s.y === y);
3223
- if (isBody) {
3224
- row += t.success("\u25A0 ");
3225
- continue;
3226
- }
3227
- if (x === this.state.food.x && y === this.state.food.y) {
3228
- row += t.error("\u25C6 ");
3229
- continue;
3230
- }
3231
- if (this.state.goldenFood && x === this.state.goldenFood.x && y === this.state.goldenFood.y) {
3232
- row += t.accent("\u2605 ");
3233
- continue;
2791
+ boardLines.push(` ${t.border("\u250C" + "\u2500".repeat(ARENA_WIDTH) + "\u2510")}`);
2792
+ for (let y = 0; y < ARENA_HEIGHT; y++) {
2793
+ let row = "";
2794
+ for (let x = 0; x < ARENA_WIDTH; x++) {
2795
+ const ch = grid[y][x];
2796
+ if (ch === "\u25B2" || ch === "\u2550") {
2797
+ row += t.highlight(ch);
2798
+ } else if (ch === "\u2502") {
2799
+ row += t.primary(ch);
2800
+ } else if (ch === "\u203B") {
2801
+ row += t.accent(ch);
2802
+ } else if (ch === "\u{1F47E}") {
2803
+ row += t.secondary(ch);
2804
+ } else if (ch === "W") {
2805
+ row += t.error(ch);
2806
+ } else if (ch === "\u{1F6F8}") {
2807
+ row += t.warning(ch);
2808
+ } else {
2809
+ row += ch;
3234
2810
  }
3235
- row += " ";
3236
2811
  }
3237
- row += t.border("\u2551");
3238
- boardLines.push(row);
2812
+ boardLines.push(` ${t.border("\u2502")}${row}${t.border("\u2502")}`);
3239
2813
  }
3240
- boardLines.push(` ${t.border("\u255A" + "\u2550\u2550".repeat(GRID_WIDTH) + "\u255D")}`);
2814
+ boardLines.push(` ${t.border("\u2514" + "\u2500".repeat(ARENA_WIDTH) + "\u2518")}`);
3241
2815
  if (this.state.isGameOver) {
3242
2816
  boardLines.push(`
3243
- ${t.error("\u{1F4A5} COLLISION! VIPER TERMINATED.")}`);
3244
- boardLines.push(` ${t.accent(`Final Length: ${this.state.snake.length} segments \u2502 Final Score: ${this.state.score}`)}`);
3245
- boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Exit.")}`);
2817
+ ${t.error("\u{1F4A5} DEFENSES BREACHED! EARTH OVERRUN.")}`);
2818
+ boardLines.push(` ${t.accent(`Invaders Destroyed: ${this.state.invadersDestroyed} \u2502 Final Score: ${this.state.score}`)}`);
2819
+ boardLines.push(` ${t.muted("Press R to Re-engage, or Esc / Q to Return to Game List.")}`);
3246
2820
  } else {
3247
2821
  boardLines.push(`
3248
- ${t.muted("Controls: Arrows/WASD: Steer \u2502 Esc/P: Pause \u2502 Q: Quit")}`);
2822
+ ${t.muted("Controls: Left/Right / A/D: Move \u2502 Space: Fire \u2502 Esc/P: Pause \u2502 Q: Return to Game List")}`);
3249
2823
  }
3250
2824
  this.renderer.clear();
3251
2825
  this.renderer.draw(`
@@ -3259,6 +2833,390 @@ ${boardLines.join("\n")}
3259
2833
  }
3260
2834
  };
3261
2835
 
2836
+ // src/games/hash-matrix/index.ts
2837
+ import chalk3 from "chalk";
2838
+ var MATRIX_CHARS = "0123456789ABCDEFabcdef!@#$%&*?+-=<>:;~^\xA7\xB1\xB5\xB6\xB7\xBB\xAB";
2839
+ var HashMatrixGame = class {
2840
+ id = "hash-matrix";
2841
+ metadata = ALL_GAMES_METADATA["hash-matrix"];
2842
+ config = null;
2843
+ renderer = defaultRenderer;
2844
+ input = new TerminalInputHandler();
2845
+ rng = new DeterministicRNG();
2846
+ loopTimer = null;
2847
+ resizeHandler = null;
2848
+ rainDrops = [];
2849
+ memoryAddress = 2147434496;
2850
+ state = {
2851
+ mode: "hash-cascade",
2852
+ colorScheme: "matrix-green",
2853
+ hashesGenerated: 0,
2854
+ isPaused: false,
2855
+ speedMs: 40,
2856
+ modesVisited: /* @__PURE__ */ new Set(["hash-cascade"]),
2857
+ sessionStartMs: 0,
2858
+ showBriefing: true
2859
+ };
2860
+ getDimensions() {
2861
+ return {
2862
+ cols: Math.max(40, process.stdout.columns || 80),
2863
+ rows: Math.max(16, process.stdout.rows || 24)
2864
+ };
2865
+ }
2866
+ init(config) {
2867
+ this.config = config;
2868
+ this.renderer.setTheme(config.theme);
2869
+ this.rng = new DeterministicRNG(config.seed || Date.now());
2870
+ const speedMap = {
2871
+ easy: 75,
2872
+ normal: 40,
2873
+ hard: 25,
2874
+ insane: 15
2875
+ };
2876
+ this.state.speedMs = speedMap[config.difficulty] || 40;
2877
+ if (config.theme === "neon") this.state.colorScheme = "cyber-neon";
2878
+ else if (config.theme === "retro-green") this.state.colorScheme = "matrix-green";
2879
+ else if (config.theme === "minimal") this.state.colorScheme = "ghost-white";
2880
+ if (config.skipTutorial !== void 0) {
2881
+ this.state.showBriefing = !config.skipTutorial;
2882
+ }
2883
+ this.initRain();
2884
+ if (process.stdout.on) {
2885
+ this.resizeHandler = () => {
2886
+ this.initRain();
2887
+ this.render();
2888
+ };
2889
+ process.stdout.on("resize", this.resizeHandler);
2890
+ }
2891
+ }
2892
+ initRain() {
2893
+ const { cols, rows } = this.getDimensions();
2894
+ this.rainDrops = [];
2895
+ for (let x = 0; x < cols; x += 2) {
2896
+ this.rainDrops.push({
2897
+ x,
2898
+ y: this.rng.nextInt(0, rows),
2899
+ speed: this.rng.nextInt(1, 3),
2900
+ length: this.rng.nextInt(6, Math.max(10, Math.floor(rows / 2))),
2901
+ chars: Array.from({ length: 25 }, () => MATRIX_CHARS[this.rng.nextInt(0, MATRIX_CHARS.length - 1)])
2902
+ });
2903
+ }
2904
+ }
2905
+ start() {
2906
+ this.state.sessionStartMs = Date.now();
2907
+ this.state.isPaused = false;
2908
+ this.render();
2909
+ this.input.start(
2910
+ (key) => this.handleInput(key),
2911
+ () => {
2912
+ this.stopAndExit();
2913
+ }
2914
+ );
2915
+ if (!this.state.showBriefing) {
2916
+ this.scheduleTick();
2917
+ }
2918
+ }
2919
+ pause() {
2920
+ this.state.isPaused = true;
2921
+ if (this.loopTimer) {
2922
+ clearTimeout(this.loopTimer);
2923
+ this.loopTimer = null;
2924
+ }
2925
+ }
2926
+ resume() {
2927
+ this.state.isPaused = false;
2928
+ this.scheduleTick();
2929
+ }
2930
+ restart() {
2931
+ this.state.hashesGenerated = 0;
2932
+ this.state.sessionStartMs = Date.now();
2933
+ this.initRain();
2934
+ this.render();
2935
+ }
2936
+ saveState() {
2937
+ return {
2938
+ mode: this.state.mode,
2939
+ colorScheme: this.state.colorScheme,
2940
+ hashesGenerated: this.state.hashesGenerated,
2941
+ speedMs: this.state.speedMs,
2942
+ showBriefing: this.state.showBriefing
2943
+ };
2944
+ }
2945
+ loadState(saved) {
2946
+ if (saved["mode"]) this.state.mode = saved["mode"];
2947
+ if (saved["colorScheme"]) this.state.colorScheme = saved["colorScheme"];
2948
+ if (saved["hashesGenerated"]) this.state.hashesGenerated = Number(saved["hashesGenerated"]);
2949
+ if (saved["speedMs"]) this.state.speedMs = Number(saved["speedMs"]);
2950
+ if (saved["showBriefing"] !== void 0) this.state.showBriefing = !!saved["showBriefing"];
2951
+ }
2952
+ destroy() {
2953
+ if (this.loopTimer) {
2954
+ clearTimeout(this.loopTimer);
2955
+ this.loopTimer = null;
2956
+ }
2957
+ if (this.resizeHandler && process.stdout.removeListener) {
2958
+ process.stdout.removeListener("resize", this.resizeHandler);
2959
+ this.resizeHandler = null;
2960
+ }
2961
+ this.input.stop();
2962
+ }
2963
+ stopAndExit() {
2964
+ this.destroy();
2965
+ if (this.config?.onGameOver) {
2966
+ this.config.onGameOver(this.state.hashesGenerated, {
2967
+ hashes: this.state.hashesGenerated,
2968
+ mode: this.state.mode
2969
+ });
2970
+ }
2971
+ if (this.config?.onExit) {
2972
+ this.config.onExit();
2973
+ }
2974
+ }
2975
+ handleInput(key) {
2976
+ if (this.state.showBriefing) {
2977
+ if (key.name === "space" || key.name === "return") {
2978
+ this.state.showBriefing = false;
2979
+ this.scheduleTick();
2980
+ this.render();
2981
+ } else if (key.sequence === "" || key.ctrl && key.name === "c" || key.name === "q" || key.name === "escape") {
2982
+ this.stopAndExit();
2983
+ }
2984
+ return;
2985
+ }
2986
+ if (key.sequence === "" || key.ctrl && key.name === "c" || key.name === "q" || key.name === "escape") {
2987
+ this.stopAndExit();
2988
+ return;
2989
+ }
2990
+ if (key.name === "space") {
2991
+ this.state.isPaused = !this.state.isPaused;
2992
+ if (!this.state.isPaused) this.scheduleTick();
2993
+ this.render();
2994
+ return;
2995
+ }
2996
+ if (key.name === "m" || key.sequence === "m") {
2997
+ const modes = ["hash-cascade", "matrix-rain", "hex-dump", "cipher-breach"];
2998
+ const curr = modes.indexOf(this.state.mode);
2999
+ this.state.mode = modes[(curr + 1) % modes.length];
3000
+ this.state.modesVisited.add(this.state.mode);
3001
+ if (this.state.modesVisited.size >= 4 && this.config?.onAchievementUnlock) {
3002
+ this.config.onAchievementUnlock("matrix_unlocked");
3003
+ }
3004
+ this.render();
3005
+ return;
3006
+ }
3007
+ if (key.name === "c" || key.name === "t" || key.sequence === "c") {
3008
+ const colors = ["matrix-green", "cyber-neon", "amber-crt", "crimson-glitch", "ghost-white"];
3009
+ const curr = colors.indexOf(this.state.colorScheme);
3010
+ this.state.colorScheme = colors[(curr + 1) % colors.length];
3011
+ this.render();
3012
+ return;
3013
+ }
3014
+ if (key.name === "up" || key.name === "1") {
3015
+ this.state.speedMs = Math.max(10, this.state.speedMs - 10);
3016
+ return;
3017
+ }
3018
+ if (key.name === "down" || key.name === "2") {
3019
+ this.state.speedMs = Math.min(150, this.state.speedMs + 10);
3020
+ return;
3021
+ }
3022
+ }
3023
+ scheduleTick() {
3024
+ if (this.state.isPaused || this.state.showBriefing) return;
3025
+ this.loopTimer = setTimeout(() => {
3026
+ this.tick();
3027
+ this.scheduleTick();
3028
+ }, this.state.speedMs);
3029
+ }
3030
+ tick() {
3031
+ const { cols } = this.getDimensions();
3032
+ this.state.hashesGenerated += Math.max(8, Math.floor(cols / 10));
3033
+ if (this.config?.onAchievementUnlock) {
3034
+ const elapsedSec = (Date.now() - this.state.sessionStartMs) / 1e3;
3035
+ if (elapsedSec >= 10) {
3036
+ this.config.onAchievementUnlock("first_breach");
3037
+ }
3038
+ if (this.state.hashesGenerated >= 5e3) {
3039
+ this.config.onAchievementUnlock("hash_miner");
3040
+ }
3041
+ }
3042
+ if (this.config?.onScoreUpdate) {
3043
+ this.config.onScoreUpdate(this.state.hashesGenerated);
3044
+ }
3045
+ this.render();
3046
+ }
3047
+ colorize(str, level) {
3048
+ const s = this.state.colorScheme;
3049
+ if (s === "matrix-green") {
3050
+ if (level === "head") return chalk3.whiteBright.bold(str);
3051
+ if (level === "body") return chalk3.greenBright(str);
3052
+ if (level === "dim") return chalk3.green(str);
3053
+ return chalk3.hex("#106010")(str);
3054
+ }
3055
+ if (s === "cyber-neon") {
3056
+ if (level === "head") return chalk3.whiteBright.bold(str);
3057
+ if (level === "body") return chalk3.cyanBright(str);
3058
+ if (level === "dim") return chalk3.magentaBright(str);
3059
+ return chalk3.hex("#336699")(str);
3060
+ }
3061
+ if (s === "amber-crt") {
3062
+ if (level === "head") return chalk3.whiteBright.bold(str);
3063
+ if (level === "body") return chalk3.yellowBright(str);
3064
+ if (level === "dim") return chalk3.hex("#FFB000")(str);
3065
+ return chalk3.hex("#885500")(str);
3066
+ }
3067
+ if (s === "crimson-glitch") {
3068
+ if (level === "head") return chalk3.whiteBright.bold(str);
3069
+ if (level === "body") return chalk3.redBright(str);
3070
+ if (level === "dim") return chalk3.hex("#FF3366")(str);
3071
+ return chalk3.hex("#771122")(str);
3072
+ }
3073
+ if (level === "head") return chalk3.whiteBright.bold(str);
3074
+ if (level === "body") return chalk3.white(str);
3075
+ if (level === "dim") return chalk3.gray(str);
3076
+ return chalk3.hex("#333333")(str);
3077
+ }
3078
+ generateRandomHash(length) {
3079
+ const hex = "0123456789abcdef";
3080
+ let res = "";
3081
+ for (let i = 0; i < length; i++) {
3082
+ res += hex[this.rng.nextInt(0, 15)];
3083
+ }
3084
+ return res;
3085
+ }
3086
+ renderHashCascade(rows, cols) {
3087
+ const lines = [];
3088
+ const hashTypes = ["SHA-256", "KECCAK ", "BLAKE2b", "ECDSA ", "MD5-RAW", "RSA-SIG"];
3089
+ for (let r = 0; r < rows; r++) {
3090
+ const type = hashTypes[this.rng.nextInt(0, hashTypes.length - 1)];
3091
+ const nonce = "0x" + this.rng.nextInt(4096, 65535).toString(16).toUpperCase();
3092
+ const status = this.rng.next() > 0.3 ? "[OK]" : "[SYNC]";
3093
+ const prefix = ` ${this.colorize(type, "dim")} [${this.colorize(nonce, "accent")}] `;
3094
+ const suffix = ` ${this.colorize(status, "head")}`;
3095
+ const overheadLen = 22;
3096
+ const hashLen = Math.max(16, cols - overheadLen - 2);
3097
+ const hash = this.generateRandomHash(hashLen);
3098
+ lines.push(`${prefix}${this.colorize(hash, "body")}${suffix}`);
3099
+ }
3100
+ return lines;
3101
+ }
3102
+ renderHexDump(rows, cols) {
3103
+ const lines = [];
3104
+ const hexChars = "0123456789ABCDEF";
3105
+ const bytesPerLine = cols > 110 ? 32 : 16;
3106
+ for (let r = 0; r < rows; r++) {
3107
+ this.memoryAddress += bytesPerLine;
3108
+ const addr = "0x" + this.memoryAddress.toString(16).toUpperCase().padStart(8, "0");
3109
+ let hexBytes = "";
3110
+ let ascii = "";
3111
+ for (let b = 0; b < bytesPerLine; b++) {
3112
+ const val = this.rng.nextInt(0, 255);
3113
+ hexBytes += hexChars[val >> 4 & 15] + hexChars[val & 15] + " ";
3114
+ ascii += val >= 32 && val <= 126 ? String.fromCharCode(val) : ".";
3115
+ }
3116
+ const line = ` ${this.colorize(addr, "accent")}: ${this.colorize(hexBytes, "body")} ${this.colorize(`|${ascii}|`, "dim")}`;
3117
+ lines.push(line.slice(0, cols + 20));
3118
+ }
3119
+ return lines;
3120
+ }
3121
+ renderMatrixRain(rows, cols) {
3122
+ const grid = Array.from({ length: rows }, () => Array.from({ length: cols }, () => " "));
3123
+ for (const drop of this.rainDrops) {
3124
+ drop.y = (drop.y + drop.speed) % (rows + drop.length);
3125
+ if (this.rng.next() > 0.6) {
3126
+ drop.chars[0] = MATRIX_CHARS[this.rng.nextInt(0, MATRIX_CHARS.length - 1)];
3127
+ }
3128
+ for (let i = 0; i < drop.length; i++) {
3129
+ const py = Math.floor(drop.y) - i;
3130
+ if (py >= 0 && py < rows && drop.x < cols) {
3131
+ const char = drop.chars[i % drop.chars.length] || "X";
3132
+ if (i === 0) {
3133
+ grid[py][drop.x] = this.colorize(char, "head");
3134
+ } else if (i < 3) {
3135
+ grid[py][drop.x] = this.colorize(char, "body");
3136
+ } else if (i < 7) {
3137
+ grid[py][drop.x] = this.colorize(char, "dim");
3138
+ } else {
3139
+ grid[py][drop.x] = this.colorize(char, "accent");
3140
+ }
3141
+ }
3142
+ }
3143
+ }
3144
+ return grid.map((row) => row.join(""));
3145
+ }
3146
+ renderCipherBreach(rows, cols) {
3147
+ const lines = [];
3148
+ const keywords = [
3149
+ "ACCESS GRANTED // BYPASS PROTOCOL INITIALIZED",
3150
+ "AUTHENTICATING TERMINULL KERNEL CORE... [SUCCESS]",
3151
+ "DECRYPTING RSA-4096 ROOT CERTIFICATE: 0x88F02C41",
3152
+ "MEMORY OVERCLOCK: BUS BANDWIDTH 100% SATURATED",
3153
+ "QUANTUM HASH RESISTANCE MATRIX ENGAGED",
3154
+ "ZERO-DAY ENTROPY VECTOR NULLIFIED ACROSS ALL NODES"
3155
+ ];
3156
+ for (let r = 0; r < rows; r++) {
3157
+ if (r % 3 === 0) {
3158
+ const kw = keywords[Math.floor(r / 3) % keywords.length];
3159
+ lines.push(` ${this.colorize(">>>", "accent")} ${this.colorize(kw, "head")}`);
3160
+ } else {
3161
+ let gibberish = "";
3162
+ while (gibberish.length < cols - 8) {
3163
+ gibberish += MATRIX_CHARS[this.rng.nextInt(0, MATRIX_CHARS.length - 1)];
3164
+ }
3165
+ lines.push(` ${this.colorize(gibberish, "dim")}`);
3166
+ }
3167
+ }
3168
+ return lines;
3169
+ }
3170
+ render() {
3171
+ const { cols, rows } = this.getDimensions();
3172
+ const t = this.renderer.getTheme();
3173
+ if (this.state.showBriefing) {
3174
+ const boxWidth = Math.min(cols - 4, 72);
3175
+ const lines = [
3176
+ "",
3177
+ t.highlight("TERMINULL HACKER STREAM // PROTOCOL INITIALIZATION"),
3178
+ "",
3179
+ t.secondary("IMMERSION MODE:"),
3180
+ "All controls and UI borders are hidden during stream for 100% movie realism.",
3181
+ "The stream dynamically expands across your entire monitor resolution.",
3182
+ "",
3183
+ t.highlight("KEYBOARD CONTROLS (Memorize before starting):"),
3184
+ ` ${t.primary("[Ctrl+C]")} or ${t.primary("[Q]")} or ${t.primary("[Esc]")} Return to Game List`,
3185
+ ` ${t.primary("[Space]")} Freeze / Resume Stream`,
3186
+ ` ${t.primary("[M]")} Switch Mode (Rain, Hashes, Hex, Cipher)`,
3187
+ ` ${t.primary("[C]")} or ${t.primary("[T]")} Switch Color Palette`,
3188
+ ` ${t.primary("[\u2191]")} / ${t.primary("[\u2193]")} Adjust Speed (10ms - 150ms)`,
3189
+ "",
3190
+ 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\u2500\u2500\u2500\u2500\u2500\u2500"),
3191
+ ` ${t.success("Press [SPACE] or [ENTER] to begin full-screen immersion...")}`,
3192
+ ` ${t.muted("Press [Q] or [ESC] to return to Arcade Game List")}`
3193
+ ];
3194
+ const box = this.renderer.createBox(lines, boxWidth, "HACKER STREAM");
3195
+ const padTop = Math.max(1, Math.floor((rows - 20) / 2));
3196
+ this.renderer.clear();
3197
+ this.renderer.draw("\n".repeat(padTop) + box + "\n");
3198
+ return;
3199
+ }
3200
+ let bodyLines = [];
3201
+ if (this.state.mode === "hash-cascade") {
3202
+ bodyLines = this.renderHashCascade(rows, cols);
3203
+ } else if (this.state.mode === "matrix-rain") {
3204
+ bodyLines = this.renderMatrixRain(rows, cols);
3205
+ } else if (this.state.mode === "hex-dump") {
3206
+ bodyLines = this.renderHexDump(rows, cols);
3207
+ } else if (this.state.mode === "cipher-breach") {
3208
+ bodyLines = this.renderCipherBreach(rows, cols);
3209
+ }
3210
+ if (this.state.isPaused) {
3211
+ const pauseHud = ` [ STREAM PAUSED // SPACE: Resume \u2502 M: Mode \u2502 C: Color \u2502 Q: Return to Game List ] `;
3212
+ const midRow = Math.floor(rows / 2);
3213
+ const padLeft = Math.max(0, Math.floor((cols - pauseHud.length) / 2));
3214
+ bodyLines[midRow] = " ".repeat(padLeft) + chalk3.bgBlack.yellowBright.bold(pauseHud);
3215
+ }
3216
+ this.renderer.draw(bodyLines.join("\n"));
3217
+ }
3218
+ };
3219
+
3262
3220
  export {
3263
3221
  APP_NAME,
3264
3222
  APP_TAGLINE,
@@ -3283,12 +3241,16 @@ export {
3283
3241
  playTerminalBell,
3284
3242
  formatTime,
3285
3243
  clamp,
3286
- padCenter,
3244
+ stripAnsi,
3245
+ visibleLength,
3246
+ padRightVisible,
3247
+ wordWrap,
3248
+ playArcadeLoadingScreen,
3287
3249
  ArcadeMenu,
3288
3250
  DeterministicRNG,
3289
- NeonCircuitGame,
3290
- ByteRunnerGame,
3291
3251
  PacketManGame,
3292
- CyberViperGame
3252
+ CyberViperGame,
3253
+ VoidInvadersGame,
3254
+ HashMatrixGame
3293
3255
  };
3294
- //# sourceMappingURL=chunk-WCZVPTEK.js.map
3256
+ //# sourceMappingURL=chunk-BIOTUQT7.js.map