-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBLACKWALL.html
More file actions
2018 lines (1771 loc) · 62.5 KB
/
Copy pathBLACKWALL.html
File metadata and controls
2018 lines (1771 loc) · 62.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BLACKWALL PROTOCOL</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');
:root {
--cyan: #00f3ff;
--magenta: #ff00aa;
--green: #00ff9d;
--purple: #aa66ff;
--void: #ff3366;
--dark: #050508;
--panel: #0a0a12;
--text: #c8d0ff;
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
background: #050508;
color: var(--text);
font-family: 'Share Tech Mono', 'Courier New', monospace;
overflow: hidden;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
}
.header {
width: 100%;
max-width: 1400px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 6px 16px;
background: linear-gradient(#0a0a12, #050508);
border: 1px solid var(--cyan);
border-bottom: none;
box-shadow: 0 0 15px rgba(0, 243, 255, 0.2);
flex-shrink: 0;
}
.title-group { display: flex; align-items: center; gap: 12px; }
.title {
font-size: 20px;
font-weight: 700;
letter-spacing: 2.5px;
color: var(--cyan);
text-shadow: 0 0 10px var(--cyan);
}
.subtitle {
font-size: 10px;
color: #667788;
letter-spacing: 1px;
}
.stats {
display: flex;
gap: 12px;
font-size: 12px;
align-items: center;
flex-wrap: wrap;
}
.stat {
display: flex;
align-items: center;
gap: 5px;
background: #0a0a12;
padding: 2px 7px;
border: 1px solid #223344;
white-space: nowrap;
}
.stat-label {
color: #667788;
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.stat-value {
font-weight: 700;
min-width: 42px;
text-align: right;
}
.income {
font-size: 9px;
color: #00ff9d;
margin-left: 4px;
}
.core-bar {
width: 100px;
height: 6px;
background: #1a1a22;
border: 1px solid #334455;
position: relative;
overflow: hidden;
}
.core-fill {
height: 100%;
background: linear-gradient(to right, #ff3366, var(--magenta));
transition: width 0.2s ease;
box-shadow: 0 0 6px #ff3366;
}
.cycle-bar {
width: 82px;
height: 4px;
background: #112233;
border: 1px solid #334455;
position: relative;
overflow: hidden;
margin-top: 1px;
}
.cycle-fill {
height: 100%;
background: #00ff9d;
transition: width 0.1s linear;
}
.cycle-fill.night {
background: linear-gradient(to right, #ff3366, #aa0000);
box-shadow: 0 0 5px #ff3366;
}
.game-container {
position: relative;
border: 2px solid var(--cyan);
box-shadow: 0 0 25px rgba(0, 243, 255, 0.3),
inset 0 0 40px rgba(0, 0, 0, 0.8);
flex: 1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
max-width: 1400px;
overflow: hidden;
}
canvas {
display: block;
background: #050508;
image-rendering: crisp-edges;
cursor: crosshair;
max-width: 100%;
max-height: 100%;
}
.toolbar {
width: 100%;
max-width: 1400px;
background: #0a0a12;
border: 1px solid var(--cyan);
border-top: none;
padding: 6px 10px;
display: flex;
gap: 5px;
flex-wrap: wrap;
justify-content: center;
flex-shrink: 0;
}
.build-btn {
background: #111118;
border: 1px solid #334455;
color: var(--text);
padding: 5px 8px;
font-family: inherit;
font-size: 10px;
cursor: pointer;
transition: all 0.1s ease;
min-width: 70px;
text-align: center;
position: relative;
}
.build-btn:hover {
border-color: var(--cyan);
box-shadow: 0 0 7px rgba(0, 243, 255, 0.4);
background: #1a1a24;
}
.build-btn.active {
border-color: var(--magenta);
box-shadow: 0 0 9px var(--magenta);
background: #1f1122;
}
.build-btn .name { display: block; font-weight: 700; letter-spacing: 0.5px; font-size: 10px; }
.build-btn .cost { display: block; font-size: 8px; color: #8899aa; margin-top: 1px; }
.build-btn .hotkey { position: absolute; top: 1px; right: 4px; font-size: 7px; color: #445566; }
.fs-btn {
position: absolute;
top: 8px;
right: 8px;
background: rgba(10,10,18,0.9);
border: 1px solid var(--cyan);
color: var(--cyan);
padding: 3px 8px;
font-size: 10px;
cursor: pointer;
z-index: 50;
letter-spacing: 1px;
}
.fs-btn:hover { background: var(--cyan); color: #050508; }
.instructions {
width: 100%;
max-width: 1400px;
font-size: 9px;
color: #556677;
text-align: center;
padding: 4px 0;
background: #050508;
border: 1px solid #223344;
border-top: none;
flex-shrink: 0;
}
.overlay {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(5,5,8,0.94);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 100;
font-family: 'Share Tech Mono', monospace;
}
.overlay.hidden { display: none; }
.overlay-title {
font-size: 40px;
color: var(--cyan);
text-shadow: 0 0 18px var(--cyan), 0 0 36px var(--magenta);
letter-spacing: 5px;
margin-bottom: 4px;
}
.overlay-subtitle {
font-size: 14px;
color: #8899aa;
margin-bottom: 20px;
letter-spacing: 2px;
}
.overlay-btn {
background: transparent;
border: 2px solid var(--cyan);
color: var(--cyan);
padding: 11px 32px;
font-family: inherit;
font-size: 13px;
letter-spacing: 2px;
cursor: pointer;
margin: 5px;
transition: all 0.2s ease;
}
.overlay-btn:hover { background: var(--cyan); color: #050508; box-shadow: 0 0 16px var(--cyan); }
.breach-warning {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 26px;
color: #ff3366;
text-shadow: 0 0 18px #ff0000, 0 0 36px #aa0000;
letter-spacing: 3px;
z-index: 200;
pointer-events: none;
text-align: center;
animation: breachPulse 0.55s infinite alternate;
}
@keyframes breachPulse {
from { opacity: 0.65; transform: translate(-50%, -50%) scale(0.97); }
to { opacity: 1; transform: translate(-50%, -50%) scale(1.03); }
}
.scanline {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
background: repeating-linear-gradient(
transparent, transparent 3px,
rgba(0, 243, 255, 0.025) 3px, rgba(0, 243, 255, 0.025) 4px
);
pointer-events: none;
z-index: 10;
mix-blend-mode: screen;
}
</style>
</head>
<body>
<div class="header">
<div class="title-group">
<div>
<div class="title">BLACKWALL PROTOCOL</div>
<div class="subtitle">v3.2 • ROGUE AI CONTAINMENT • EXPANDED NET</div>
</div>
</div>
<div class="stats">
<div class="stat">
<span class="stat-label" style="color:#00f3ff">ICE</span>
<span id="ice-value" class="stat-value" style="color:#00f3ff">420</span>
<span id="ice-income" class="income">+0/s</span>
</div>
<div class="stat">
<span class="stat-label" style="color:#aa66ff">NEURO</span>
<span id="neuro-value" class="stat-value" style="color:#aa66ff">85</span>
<span id="neuro-income" class="income">+0/s</span>
</div>
<div class="stat">
<span class="stat-label" style="color:#ff3366">VOID</span>
<span id="void-value" class="stat-value" style="color:#ff3366">12</span>
</div>
<div style="width:1px; height:26px; background:#223344; margin:0 3px;"></div>
<div class="stat">
<span class="stat-label">WAVE</span>
<span id="wave-value" class="stat-value">01</span>
</div>
<div class="stat" style="flex-direction:column; align-items:flex-start; gap:0;">
<div style="display:flex; align-items:center; gap:5px;">
<span class="stat-label" id="phase-label">DAY CYCLE</span>
<span id="phase-timer" class="stat-value" style="min-width:48px;">01:48</span>
</div>
<div class="cycle-bar">
<div id="cycle-fill" class="cycle-fill" style="width:100%"></div>
</div>
</div>
<div class="stat">
<span class="stat-label">CORE</span>
<div class="core-bar">
<div id="core-fill" class="core-fill" style="width:100%"></div>
</div>
<span id="core-value" class="stat-value">1000</span>
</div>
</div>
</div>
<div class="game-container">
<canvas id="game" width="1100" height="900"></canvas>
<div class="scanline"></div>
<button class="fs-btn" onclick="toggleFullscreen()">FULLSCREEN</button>
<!-- Start Screen -->
<div id="start-overlay" class="overlay">
<div class="overlay-title">BLACKWALL</div>
<div class="overlay-subtitle">THE BLACKWALL IS FRAGILE • THE NET IS VAST</div>
<div style="max-width:480px; text-align:center; line-height:1.5; margin-bottom:18px; color:#778899; font-size:12px;">
Long days for expansion and harvesting.<br>
Short, violent nights when the rogue AIs breach.<br>
Connect your network • Upgrade your defenses • Push into the fog.
</div>
<button class="overlay-btn" onclick="startGame()">BOOT CONTAINMENT PROTOCOL</button>
<div style="margin-top:26px; font-size:9px; color:#445566; line-height:1.35;">
MOUSE WHEEL • ZOOM | RIGHT-DRAG • PAN | 1-6 HOTKEYS<br>
LEFT-CLICK • PLACE / UPGRADE | RIGHT-CLICK • SELL
</div>
</div>
<!-- Game Over -->
<div id="gameover-overlay" class="overlay hidden">
<div class="overlay-title" style="color:#ff3366; text-shadow:0 0 18px #ff3366;">BLACKWALL BREACHED</div>
<div class="overlay-subtitle" style="color:#ff3366;">CONTAINMENT FAILURE — CYCLE COLLAPSE</div>
<div style="margin:14px 0; font-size:13px; color:#aabbcc;">
<div>WAVES SURVIVED: <span id="final-wave" style="color:#ff3366; font-weight:700;">14</span></div>
<div style="margin-top:2px;">BEST RUN: <span id="best-wave" style="color:var(--cyan); font-weight:700;">--</span></div>
</div>
<button class="overlay-btn" onclick="restartGame()" style="border-color:#ff3366; color:#ff3366;">REINITIALIZE PROTOCOL</button>
</div>
<!-- Breach Warning -->
<div id="breach-warning" class="breach-warning" style="display:none;">
BLACKWALL BREACH EVENT<br>
<span id="breach-countdown" style="font-size:38px; letter-spacing:5px;">08</span>
</div>
</div>
<div class="toolbar">
<button class="build-btn" data-type="wall" onclick="selectBuild('wall')">
<span class="hotkey">1</span>
<span class="name" style="color:#00aaff">BARRIER</span>
<span class="cost">35 ICE</span>
</button>
<button class="build-btn" data-type="sentry" onclick="selectBuild('sentry')">
<span class="hotkey">2</span>
<span class="name" style="color:#ffaa00">SENTRY</span>
<span class="cost">95 ICE</span>
</button>
<button class="build-btn" data-type="laser" onclick="selectBuild('laser')">
<span class="hotkey">3</span>
<span class="name" style="color:#ff00aa">LASER ARRAY</span>
<span class="cost">140 ICE + 8 NEURO</span>
</button>
<button class="build-btn" data-type="rocket" onclick="selectBuild('rocket')">
<span class="hotkey">4</span>
<span class="name" style="color:#ff8800">ROCKET POD</span>
<span class="cost">260 ICE + 3 VOID</span>
</button>
<button class="build-btn" data-type="icetap" onclick="selectBuild('icetap')">
<span class="hotkey">5</span>
<span class="name" style="color:#00ff9d">ICE TAP</span>
<span class="cost">210 ICE</span>
</button>
<button class="build-btn" data-type="neurotap" onclick="selectBuild('neurotap')">
<span class="hotkey">6</span>
<span class="name" style="color:#aa66ff">NEURO TAP</span>
<span class="cost">280 ICE + 12 NEURO</span>
</button>
<button class="build-btn" onclick="upgradeAll()" style="min-width:78px; border-color:#00ff9d; color:#00ff9d; margin-left:6px;">
<span class="name">UPGRADE ALL</span>
<span class="cost" style="color:#00ff9d">LEVEL +1</span>
</button>
<button class="build-btn" onclick="sellModeToggle()" style="min-width:58px; border-color:#ff3366; color:#ff3366;">
<span class="name">SELL</span>
<span class="cost" style="color:#ff3366">55%</span>
</button>
</div>
<div class="instructions">
LEFT-CLICK BUILDING TO UPGRADE • CONNECTED NETWORK • LONG DAYS • SHORT VIOLENT NIGHTS • PUSH INTO THE FOG
</div>
<script>
// ==================== BLACKWALL PROTOCOL v3.2 — UPGRADE + NETWORK LINES ====================
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d', { alpha: true });
const COLS = 64;
const ROWS = 64;
const CELL_SIZE = 32;
const WORLD_W = COLS * CELL_SIZE;
const WORLD_H = ROWS * CELL_SIZE;
// Camera
let camX = WORLD_W / 2;
let camY = WORLD_H / 2;
let zoom = 0.78;
let isPanning = false;
let panStartX = 0, panStartY = 0;
// Game state
let ice = 420;
let neuro = 85;
let voidRes = 12;
let coreHp = 1000;
const maxCoreHp = 1000;
let wave = 1;
let gameRunning = false;
let currentBuildType = null;
let sellMode = false;
let lastTime = performance.now();
let globalTime = 0;
let shakeAmount = 0;
let dirtyFlow = true;
// Income tracking (for UI)
let icePerSec = 0;
let neuroPerSec = 0;
let lastIncomeUpdate = 0;
// Day/Night
let phase = 'day';
let phaseTime = 0;
const DAY_LENGTH = 108;
const NIGHT_LENGTH = 26;
const WARNING_LENGTH = 9;
let breachWarningActive = false;
let breachCountdown = 0;
// Data
let buildingsGrid = Array.from({length: COLS}, () => Array(ROWS).fill(null));
let distMap = Array.from({length: COLS}, () => Array(ROWS).fill(Infinity));
let revealed = Array.from({length: COLS}, () => Array(ROWS).fill(false));
let buildings = [];
let enemies = [];
let projectiles = [];
let particles = [];
let activeBeams = [];
let breachPortals = [];
let floatingTexts = []; // For clear income feedback
let dataNodes = [];
// Core
const core = {
gx: Math.floor(COLS/2), gy: Math.floor(ROWS/2),
x: Math.floor(COLS/2) * CELL_SIZE + CELL_SIZE/2,
y: Math.floor(ROWS/2) * CELL_SIZE + CELL_SIZE/2
};
let audioCtx;
function initAudio() {
try { audioCtx = new (window.AudioContext || window.webkitAudioContext)(); } catch(e){}
}
function playSound(type, vol = 0.6) {
if (!audioCtx) return;
const now = audioCtx.currentTime;
if (type === 'shoot') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain(), f = audioCtx.createBiquadFilter();
o.type = 'sawtooth'; o.frequency.value = 720 + Math.random()*80;
f.type = 'lowpass'; f.frequency.value = 1350;
g.gain.value = vol*0.65; g.gain.linearRampToValueAtTime(0.001, now+0.16);
o.connect(f); f.connect(g); g.connect(audioCtx.destination);
o.start(); o.stop(now+0.2);
}
else if (type === 'laser') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain(), f = audioCtx.createBiquadFilter();
o.type = 'sine'; o.frequency.value = 1280;
f.type = 'bandpass'; f.frequency.value = 1320; f.Q.value = 3.5;
g.gain.value = vol*0.45; g.gain.linearRampToValueAtTime(0.001, now+0.26);
o.frequency.linearRampToValueAtTime(920, now+0.24);
o.connect(f); f.connect(g); g.connect(audioCtx.destination);
o.start(); o.stop(now+0.3);
}
else if (type === 'rocket') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain(), f = audioCtx.createBiquadFilter();
o.type='sawtooth'; o.frequency.value=165; f.type='lowpass'; f.frequency.value=520;
g.gain.value=vol*0.75; g.gain.linearRampToValueAtTime(0.001, now+0.55);
o.connect(f); f.connect(g); g.connect(audioCtx.destination);
o.start(); o.stop(now+0.6);
setTimeout(() => {
if(!audioCtx) return;
const bo = audioCtx.createOscillator(), bg = audioCtx.createGain(), bf = audioCtx.createBiquadFilter();
bo.type='sine'; bo.frequency.value=58; bf.type='lowpass'; bf.frequency.value=240;
bg.gain.value=0.85; bg.gain.linearRampToValueAtTime(0.001, audioCtx.currentTime+0.85);
bo.connect(bf); bf.connect(bg); bg.connect(audioCtx.destination);
bo.start(); bo.stop(audioCtx.currentTime + 0.95);
}, 160);
}
else if (type === 'explosion') {
const noise = createNoise(0.75);
const src = audioCtx.createBufferSource(); src.buffer = noise;
const f = audioCtx.createBiquadFilter(); f.type='lowpass'; f.frequency.value=580;
const g = audioCtx.createGain(); g.gain.value = vol*1.05; g.gain.linearRampToValueAtTime(0.001, now+0.8);
src.connect(f); f.connect(g); g.connect(audioCtx.destination); src.start();
}
else if (type === 'place') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain();
o.type='square'; o.frequency.value=880;
g.gain.value=vol*0.32; g.gain.linearRampToValueAtTime(0.001, now+0.11);
o.connect(g); g.connect(audioCtx.destination); o.start(); o.stop(now+0.14);
}
else if (type === 'error') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain();
o.type='sawtooth'; o.frequency.value=125;
g.gain.value=vol*0.45; g.gain.linearRampToValueAtTime(0.001, now+0.22);
o.connect(g); g.connect(audioCtx.destination); o.start(); o.stop(now+0.25);
}
else if (type === 'hit') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain(), f = audioCtx.createBiquadFilter();
o.type='square'; o.frequency.value=380; f.type='lowpass'; f.frequency.value=780;
g.gain.value=vol*0.35; g.gain.linearRampToValueAtTime(0.001, now+0.09);
o.connect(f); f.connect(g); g.connect(audioCtx.destination); o.start(); o.stop(now+0.11);
}
else if (type === 'death') {
const noise = createNoise(0.32);
const src = audioCtx.createBufferSource(); src.buffer = noise;
const f = audioCtx.createBiquadFilter(); f.type='bandpass'; f.frequency.value=780; f.Q.value=2.8;
const g = audioCtx.createGain(); g.gain.value=vol*0.6; g.gain.linearRampToValueAtTime(0.001, now+0.42);
src.connect(f); f.connect(g); g.connect(audioCtx.destination); src.start();
}
else if (type === 'wave') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain();
o.type='sine'; o.frequency.value=380;
g.gain.value=vol*0.28; g.gain.linearRampToValueAtTime(0.001, now+0.55);
o.frequency.linearRampToValueAtTime(720, now+0.5);
o.connect(g); g.connect(audioCtx.destination); o.start(); o.stop(now+0.6);
}
else if (type === 'breach_alarm') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain(), f = audioCtx.createBiquadFilter();
o.type = 'sawtooth'; o.frequency.value = 180;
f.type = 'lowpass'; f.frequency.value = 420;
g.gain.value = vol * 0.9;
g.gain.linearRampToValueAtTime(vol * 0.2, now + 1.8);
o.frequency.linearRampToValueAtTime(620, now + 1.6);
o.connect(f); f.connect(g); g.connect(audioCtx.destination);
o.start(now); o.stop(now + 2.0);
setTimeout(() => {
if (!audioCtx) return;
const o2 = audioCtx.createOscillator(), g2 = audioCtx.createGain();
o2.type = 'square'; o2.frequency.value = 95;
g2.gain.value = vol * 0.5;
g2.gain.linearRampToValueAtTime(0.001, audioCtx.currentTime + 1.4);
o2.connect(g2); g2.connect(audioCtx.destination);
o2.start(); o2.stop(audioCtx.currentTime + 1.5);
}, 300);
}
else if (type === 'upgrade') {
const o = audioCtx.createOscillator(), g = audioCtx.createGain();
o.type = 'sine'; o.frequency.value = 620;
g.gain.value = vol * 0.4;
g.gain.linearRampToValueAtTime(0.001, now + 0.35);
o.frequency.linearRampToValueAtTime(920, now + 0.3);
o.connect(g); g.connect(audioCtx.destination);
o.start(); o.stop(now + 0.4);
}
}
function createNoise(duration) {
const size = Math.floor(audioCtx.sampleRate * duration);
const buf = audioCtx.createBuffer(1, size, audioCtx.sampleRate);
const data = buf.getChannelData(0);
for (let i = 0; i < size; i++) data[i] = Math.random() * 2 - 1;
return buf;
}
// ==================== FOG + REVEAL ====================
function initFog() {
for (let x = 0; x < COLS; x++) for (let y = 0; y < ROWS; y++) revealed[x][y] = false;
revealCircle(core.gx, core.gy, 13);
}
function revealCircle(gx, gy, radius) {
for (let x = Math.max(0, gx - radius); x <= Math.min(COLS-1, gx + radius); x++) {
for (let y = Math.max(0, gy - radius); y <= Math.min(ROWS-1, gy + radius); y++) {
if (Math.hypot(x - gx, y - gy) <= radius + 0.6) revealed[x][y] = true;
}
}
}
function revealAroundBuilding(b) {
const r = (b.type.includes('tap')) ? 9 : 5.5;
revealCircle(b.gx, b.gy, r);
}
// ==================== FLOW FIELD ====================
function isPassable(x, y) {
if (x < 0 || x >= COLS || y < 0 || y >= ROWS) return false;
if (x === core.gx && y === core.gy) return false;
return buildingsGrid[x][y] === null;
}
function computeFlowField() {
for (let x = 0; x < COLS; x++) for (let y = 0; y < ROWS; y++) distMap[x][y] = Infinity;
const q = [];
distMap[core.gx][core.gy] = 0;
q.push({x: core.gx, y: core.gy});
const dirs = [[0,1],[1,0],[0,-1],[-1,0]];
while (q.length) {
const cur = q.shift();
const cd = distMap[cur.x][cur.y];
for (let [dx,dy] of dirs) {
const nx = cur.x + dx, ny = cur.y + dy;
if (nx>=0 && nx<COLS && ny>=0 && ny<ROWS && isPassable(nx,ny) && distMap[nx][ny] > cd + 1) {
distMap[nx][ny] = cd + 1;
q.push({x:nx, y:ny});
}
}
}
dirtyFlow = false;
}
// ==================== BUILDINGS + UPGRADE SYSTEM ====================
const BUILD_DATA = {
wall: { costIce: 35, costNeuro:0, costVoid:0, hp: 240, name:'BARRIER', color:'#00aaff' },
sentry: { costIce: 95, costNeuro:0, costVoid:0, hp: 70, name:'SENTRY', color:'#ffaa00', range:5.8, fireRate:620, damage:12 },
laser: { costIce:140, costNeuro:8, costVoid:0, hp: 55, name:'LASER', color:'#ff00aa', range:6.8, fireRate:380, damage:19 },
rocket: { costIce:260, costNeuro:0, costVoid:3, hp: 85, name:'ROCKET', color:'#ff8800', range:7.8, fireRate:1320, damage:42 },
icetap: { costIce:210, costNeuro:0, costVoid:0, hp: 95, name:'ICE TAP', color:'#00ff9d', incomeIce: 7 },
neurotap: { costIce:280, costNeuro:12,costVoid:0, hp: 80, name:'NEURO TAP', color:'#aa66ff', incomeNeuro: 4 }
};
function getUpgradeCost(b) {
const base = BUILD_DATA[b.type];
const level = b.level || 1;
const mult = Math.pow(1.65, level - 1);
return {
ice: Math.floor(base.costIce * mult),
neuro: Math.floor(base.costNeuro * mult),
void: Math.floor(base.costVoid * mult)
};
}
function applyUpgrade(b) {
const level = (b.level || 1) + 1;
b.level = level;
const base = BUILD_DATA[b.type];
// Scale stats
if (b.type === 'sentry' || b.type === 'laser' || b.type === 'rocket') {
b.damage = Math.floor(base.damage * (1 + (level-1) * 0.28));
if (b.range) b.range = base.range * (1 + (level-1) * 0.12);
if (b.fireRate) b.fireRate = Math.max(220, Math.floor(base.fireRate * (1 - (level-1) * 0.09)));
}
if (b.type.includes('tap')) {
if (b.incomeIce) b.incomeIce = Math.floor(base.incomeIce * (1 + (level-1) * 0.35));
if (b.incomeNeuro) b.incomeNeuro = Math.floor(base.incomeNeuro * (1 + (level-1) * 0.35));
}
b.maxHp = Math.floor(base.hp * (1 + (level-1) * 0.22));
b.hp = Math.min(b.maxHp, b.hp + Math.floor(b.maxHp * 0.3));
createParticles(b.gx * CELL_SIZE + CELL_SIZE/2, b.gy * CELL_SIZE + CELL_SIZE/2, 18, '#ffffff', 1.8);
playSound('upgrade', 0.6);
dirtyFlow = true;
}
function upgradeBuildingAt(gx, gy) {
const b = buildingsGrid[gx][gy];
if (!b) return false;
const cost = getUpgradeCost(b);
if (ice < cost.ice || neuro < cost.neuro || voidRes < cost.void) {
playSound('error', 0.4);
return false;
}
ice -= cost.ice;
neuro -= cost.neuro;
voidRes -= cost.void;
updateUI();
applyUpgrade(b);
return true;
}
function upgradeAll() {
let upgraded = 0;
for (let b of buildings) {
if ((b.level || 1) >= 5) continue; // max level 5
const cost = getUpgradeCost(b);
if (ice >= cost.ice && neuro >= cost.neuro && voidRes >= cost.void) {
ice -= cost.ice;
neuro -= cost.neuro;
voidRes -= cost.void;
applyUpgrade(b);
upgraded++;
}
}
if (upgraded > 0) {
updateUI();
playSound('upgrade', 0.5);
} else {
playSound('error', 0.3);
}
}
function canPlaceAt(gx, gy, type) {
if (gx < 0 || gx >= COLS || gy < 0 || gy >= ROWS) return false;
if (gx === core.gx && gy === core.gy) return false;
if (buildingsGrid[gx][gy]) return false;
if (type === 'icetap' || type === 'neurotap') {
const node = dataNodes.find(n => n.gx === gx && n.gy === gy);
if (!node) return false;
if (type === 'icetap' && node.type !== 'ice') return false;
if (type === 'neurotap' && node.type !== 'neuro') return false;
}
return true;
}
function placeBuilding(gx, gy, type) {
if (!canPlaceAt(gx, gy, type)) { playSound('error', 0.5); return false; }
const d = BUILD_DATA[type];
if (ice < d.costIce || neuro < d.costNeuro || voidRes < d.costVoid) {
playSound('error', 0.5); return false;
}
ice -= d.costIce;
neuro -= d.costNeuro;
voidRes -= d.costVoid;
updateUI();
const b = {
gx, gy,
type,
hp: d.hp,
maxHp: d.hp,
lastShot: 0,
color: d.color,
incomeTimer: (type.includes('tap')) ? 0 : null,
level: 1,
damage: d.damage,
range: d.range,
fireRate: d.fireRate,
incomeIce: d.incomeIce,
incomeNeuro: d.incomeNeuro
};
buildings.push(b);
buildingsGrid[gx][gy] = b;
revealAroundBuilding(b);
createParticles(gx * CELL_SIZE + CELL_SIZE/2, gy * CELL_SIZE + CELL_SIZE/2, 14, '#ffffff', 1.6);
playSound('place', 0.5);
dirtyFlow = true;
return true;
}
function destroyBuilding(b) {
const idx = buildings.indexOf(b);
if (idx === -1) return;
buildings.splice(idx, 1);
buildingsGrid[b.gx][b.gy] = null;
createParticles(b.gx * CELL_SIZE + CELL_SIZE/2, b.gy * CELL_SIZE + CELL_SIZE/2, 20, b.color, 2.1);
playSound('explosion', 0.32);
dirtyFlow = true;
}
function sellBuildingAt(gx, gy) {
const b = buildingsGrid[gx][gy];
if (!b) return;
const d = BUILD_DATA[b.type];
const level = b.level || 1;
const refundMult = 0.55 * (1 + (level-1) * 0.08);
const refundIce = Math.floor(d.costIce * refundMult);
const refundNeuro = Math.floor(d.costNeuro * refundMult);
const refundVoid = Math.floor(d.costVoid * refundMult);
ice += refundIce;
neuro += refundNeuro;
voidRes += refundVoid;
updateUI();
destroyBuilding(b);
playSound('hit', 0.4);
}
// ==================== NODES ====================
function generateNodes() {
dataNodes = [];
for (let i = 0; i < 38; i++) {
let gx, gy;
do {
gx = Math.floor(Math.random() * COLS);
gy = Math.floor(Math.random() * ROWS);
} while (Math.hypot(gx - core.gx, gy - core.gy) < 9 || dataNodes.some(n => Math.hypot(n.gx-gx, n.gy-gy) < 3.5));
dataNodes.push({gx, gy, type: 'ice'});
}
for (let i = 0; i < 14; i++) {
let gx, gy;
do {
gx = Math.floor(Math.random() * COLS);
gy = Math.floor(Math.random() * ROWS);
} while (Math.hypot(gx - core.gx, gy - core.gy) < 11 || dataNodes.some(n => Math.hypot(n.gx-gx, n.gy-gy) < 4));
dataNodes.push({gx, gy, type: 'neuro'});
}
const voidPos = [
{gx: 8, gy: 11}, {gx: 53, gy: 9}, {gx: 7, gy: 51},
{gx: 55, gy: 52}, {gx: 31, gy: 6}, {gx: 12, gy: 48}
];
for (let pos of voidPos) {
if (Math.hypot(pos.gx - core.gx, pos.gy - core.gy) > 14) {
dataNodes.push({gx: pos.gx, gy: pos.gy, type: 'void'});
}
}
}
// ==================== ENEMIES + FLOATING TEXT ====================
let enemyStats = { baseHp: 26, baseSpeed: 1.4, baseDamage: 6 };
function addFloatingText(x, y, text, color) {
floatingTexts.push({ x, y, text, color, life: 1.2, vy: -28 });
}
function spawnEnemy(fromEdge = true) {
let gx, gy, x, y;
const margin = 2.2;
if (fromEdge) {
const side = Math.floor(Math.random() * 4);
if (side === 0) { gx = Math.floor(Math.random()*COLS); gy = 0; x = (gx+0.5)*CELL_SIZE; y = -CELL_SIZE*margin; }
else if (side === 1) { gx = COLS-1; gy = Math.floor(Math.random()*ROWS); x = WORLD_W + CELL_SIZE*margin; y = (gy+0.5)*CELL_SIZE; }
else if (side === 2) { gx = Math.floor(Math.random()*COLS); gy = ROWS-1; x = (gx+0.5)*CELL_SIZE; y = WORLD_H + CELL_SIZE*margin; }
else { gx = 0; gy = Math.floor(Math.random()*ROWS); x = -CELL_SIZE*margin; y = (gy+0.5)*CELL_SIZE; }
} else {
gx = Math.floor(Math.random() * COLS);
gy = Math.floor(Math.random() * ROWS);
x = (gx + 0.5) * CELL_SIZE;
y = (gy + 0.5) * CELL_SIZE;
}
let type = 'drone';
let hpMod = 1, speedMod = 1, color = '#ff3366', valueIce = 13, size = 9, dmg = enemyStats.baseDamage;
const r = Math.random();
if (wave >= 5 && r > 0.78) {
type = 'wraith'; speedMod = 1.7; hpMod = 0.6; color = '#aa66ff'; valueIce = 18; size = 7; dmg = Math.floor(enemyStats.baseDamage * 0.65);
} else if (wave >= 3 && r > 0.48) {
type = 'brute'; speedMod = 0.52; hpMod = 2.9; color = '#ff8800'; valueIce = 36; size = 13; dmg = Math.floor(enemyStats.baseDamage * 1.7);
}
enemies.push({
x, y, hp: Math.floor(enemyStats.baseHp * hpMod), maxHp: Math.floor(enemyStats.baseHp * hpMod),
speed: enemyStats.baseSpeed * speedMod, valueIce, damage: dmg, size, color, type, stuckTimer: 0
});
}
function updateEnemies(dt) {
const corePx = core.x, corePy = core.y;
for (let i = enemies.length - 1; i >= 0; i--) {
const e = enemies[i];
let gx = Math.max(0, Math.min(COLS-1, Math.floor(e.x / CELL_SIZE)));
let gy = Math.max(0, Math.min(ROWS-1, Math.floor(e.y / CELL_SIZE)));
let moved = false;
if (distMap[gx] && distMap[gx][gy] < Infinity) {
let bestDist = distMap[gx][gy];
let bestDx = 0, bestDy = 0;
const dirs = [[0,1],[1,0],[0,-1],[-1,0]];
for (let [dx,dy] of dirs) {
const nx = gx + dx, ny = gy + dy;
if (nx>=0&&nx<COLS&&ny>=0&&ny<ROWS && distMap[nx] && distMap[nx][ny] < bestDist && isPassable(nx,ny)) {
bestDist = distMap[nx][ny]; bestDx = dx; bestDy = dy;
}
}
if (bestDx || bestDy) {
const tx = (gx + bestDx + 0.5) * CELL_SIZE;
const ty = (gy + bestDy + 0.5) * CELL_SIZE;
const dx = tx - e.x, dy = ty - e.y;
const d = Math.hypot(dx, dy) || 1;
e.x += (dx/d) * e.speed * dt * 60;
e.y += (dy/d) * e.speed * dt * 60;
moved = true;
}
}
if (!moved) {
const dx = corePx - e.x, dy = corePy - e.y;
const d = Math.hypot(dx, dy) || 1;
e.x += (dx/d) * e.speed * 0.55 * dt * 60;
e.y += (dy/d) * e.speed * 0.55 * dt * 60;
}
// Separation
for (let j = 0; j < enemies.length; j++) {
if (i === j) continue;
const o = enemies[j];
const dx = e.x - o.x, dy = e.y - o.y;
const d = Math.hypot(dx, dy);
if (d > 0.1 && d < 17) {
e.x += (dx/d) * 0.7; e.y += (dy/d) * 0.7;
}
}
// Attack buildings
const ex = Math.floor(e.x / CELL_SIZE), ey = Math.floor(e.y / CELL_SIZE);
for (let dx=-1; dx<=1; dx++) for (let dy=-1; dy<=1; dy++) {
const bx = ex+dx, by = ey+dy;
if (bx>=0&&bx<COLS&&by>=0&&by<ROWS) {
const b = buildingsGrid[bx][by];
if (b && b.hp > 0) {
b.hp -= e.damage * 0.32 * dt;
if (b.hp <= 0) destroyBuilding(b);
if (Math.random() < 0.12) createParticles(bx*CELL_SIZE+CELL_SIZE/2, by*CELL_SIZE+CELL_SIZE/2, 3, '#ffaa66', 1);
}
}
}
if (Math.hypot(e.x - corePx, e.y - corePy) < 26) {
coreHp -= e.damage * 1.9;
shakeAmount = Math.max(shakeAmount, 8);
playSound('hit', 0.5);
createParticles(corePx, corePy, 20, '#ff3366', 2.3);
enemies.splice(i, 1);
updateUI();
if (coreHp <= 0) endGame();
continue;
}
if (e.hp <= 0) {
ice += e.valueIce;
addFloatingText(e.x, e.y - 18, `+${e.valueIce} ICE`, '#00f3ff');
updateUI();
createParticles(e.x, e.y, 15, e.color, 1.9);
playSound('death', 0.55);