-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
4481 lines (3724 loc) · 126 KB
/
Copy pathscript.js
File metadata and controls
4481 lines (3724 loc) · 126 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
// Game state management
let gameState = "mainMenu"; // 'mainMenu', 'instructions', 'playing', 'paused', 'gameOver'
let gameInitialized = false;
// Scene setup
let scene, camera, renderer;
let ground, sky;
let controls;
let moveForward = false;
let moveBackward = false;
let moveLeft = false;
let moveRight = false;
let velocity = new THREE.Vector3();
let direction = new THREE.Vector3();
let prevTime = performance.now();
// Zombie system
let zombies = [];
let zombieModel = null;
let loader = new THREE.GLTFLoader();
const ZOMBIE_COUNT = 10;
// Zombie types with different stats
const ZOMBIE_TYPES = {
NORMAL: {
name: "Normal",
emoji: "🧟",
health: 1,
speed: 1.0,
scale: 1.0,
color: 0x4a5c3a, // Green
headColor: 0x8b7355, // Brown
eyeColor: 0xff0000, // Red
detectRange: 60,
attackRange: 3.5,
chaseRange: 8,
attackDamage: 10,
spawnWeight: 100, // Higher = more common
},
FAST: {
name: "Runner",
emoji: "🏃♂️",
health: 1,
speed: 1.8,
scale: 0.9,
color: 0x6b4226, // Dark brown
headColor: 0x8b7355, // Brown
eyeColor: 0xff4400, // Orange-red
detectRange: 70,
attackRange: 4.0,
chaseRange: 10,
attackDamage: 8,
spawnWeight: 60,
},
TANK: {
name: "Tank",
emoji: "🦾",
health: 3,
speed: 0.6,
scale: 1.4,
color: 0x2c3e2a, // Dark green
headColor: 0x654321, // Dark brown
eyeColor: 0xff0000, // Red
detectRange: 50,
attackRange: 4.5,
chaseRange: 8,
attackDamage: 20,
spawnWeight: 30,
},
BOSS: {
name: "Brute",
emoji: "👹",
health: 8,
speed: 0.8,
scale: 2.0,
color: 0x1a1a1a, // Almost black
headColor: 0x4a0e0e, // Dark red
eyeColor: 0xff6600, // Bright orange
detectRange: 80,
attackRange: 6.0,
chaseRange: 12,
attackDamage: 30,
spawnWeight: 5,
},
};
// Track zombie type counts for UI
let zombieTypeCounts = {
NORMAL: 0,
FAST: 0,
TANK: 0,
BOSS: 0,
};
// Health pack system
let healthPacks = [];
let lastHealthPackSpawn = 0;
const HEALTH_PACK_SPAWN_INTERVAL = 15000; // 15 seconds between spawns
const HEALTH_PACK_HEAL_AMOUNT = 25; // How much health each pack restores
const MAX_HEALTH_PACKS = 3; // Maximum health packs on map at once
let healthPacksCollected = 0;
// Ammo pack system
let ammoPacks = [];
let lastAmmoPackSpawn = 0;
const AMMO_PACK_SPAWN_INTERVAL = 20000; // 20 seconds between spawns
const AMMO_PACK_REFILL_AMOUNT = 60; // How much ammo each pack restores
const MAX_AMMO_PACKS = 2; // Maximum ammo packs on map at once
let ammoPacksCollected = 0;
// Gun and shooting system
let gun = null;
let machineGun = null;
let currentWeapon = "rifle"; // 'rifle' or 'machinegun'
let bullets = [];
const BULLET_SPEED = 50;
const BULLET_LIFETIME = 3000; // 3 seconds in milliseconds
// Weapon-specific properties
const WEAPONS = {
rifle: {
name: "Assault Rifle",
fireRate: 0, // Single shot
damage: 1,
recoil: 0.4,
emoji: "🔫",
maxAmmo: 999, // Effectively unlimited
currentAmmo: 999,
},
machinegun: {
name: "Machine Gun",
fireRate: 400, // Rounds per minute
damage: 1,
recoil: 0.25,
emoji: "⚡",
maxAmmo: 150, // Limited ammo
currentAmmo: 150,
},
};
// Rapid fire system
let isAutoFiring = false;
let lastShotTime = 0;
let mouseHeld = false;
// Gun animation and effects
let gunRecoilOffset = 0;
let gunRecoilVelocity = 0;
let muzzleFlashLight = null;
let gunBasePosition = { x: 0, y: -3, z: -5 }; // Base gun position
// Crosshair and targeting system
let raycaster = new THREE.Raycaster();
let isAimingAtZombie = false;
// Mini radar system
let radarCanvas = null;
let radarContext = null;
const RADAR_RANGE = 50; // Range in game units
const RADAR_SIZE = 120; // Canvas size in pixels
// Score system
let zombieKills = 0;
// Wave system
let currentWave = 1;
let zombiesThisWave = 0;
let zombiesSpawnedThisWave = 0;
let waveInProgress = false;
let timeBetweenWaves = 5000; // 5 seconds between waves
let nextWaveTimer = null;
let zombieSpawnTimer = null;
// Player health system
let playerHealth = 100;
let maxHealth = 100;
let isGameOver = false;
let lastDamageTime = 0;
let damageInvulnerabilityTime = 1000; // 1 second invulnerability after damage
// Audio system
let audioListener;
let audioLoader;
let backgroundMusic;
let gunfireSound;
let zombieGrowlSound;
let zombieAttackSound;
let sounds = {
backgroundMusic: null,
gunfire: null,
machinegun: null,
zombieGrowl: null,
zombieAttack: null,
};
let musicVolume = 0.3;
let effectsVolume = 0.7;
let lastGrowlTime = 0;
let growlCooldownTime = 2000; // 2 seconds between growls
// Initialize audio system
function initAudio() {
console.log("Initializing audio system...");
// Create audio listener
audioListener = new THREE.AudioListener();
camera.add(audioListener);
// Create audio loader
audioLoader = new THREE.AudioLoader();
// Initialize sounds
initBackgroundMusic();
initSoundEffects();
console.log("Audio system initialized");
}
// Initialize background music
function initBackgroundMusic() {
backgroundMusic = new THREE.Audio(audioListener);
// For now we'll use ambient background without loading music
// You can add music file loading here if needed
console.log("Background music system ready");
}
// Initialize sound effects
function initSoundEffects() {
// Create sound objects
gunfireSound = new THREE.Audio(audioListener);
zombieGrowlSound = new THREE.Audio(audioListener);
zombieAttackSound = new THREE.Audio(audioListener);
// Load actual sound files
console.log("Loading sound effects...");
// Load single shot gunfire sound
audioLoader.load(
"assets/single gun shot.mp3",
function (buffer) {
console.log("Single gun shot loaded successfully");
gunfireSound.setBuffer(buffer);
gunfireSound.setVolume(effectsVolume);
sounds.gunfire = gunfireSound;
},
undefined,
function (error) {
console.error("Error loading single gun shot:", error);
sounds.gunfire = null;
}
);
// Load machine gun sound for rapid fire
const machineGunSound = new THREE.Audio(audioListener);
audioLoader.load(
"assets/machine gun (rapid fire).mp3",
function (buffer) {
console.log("Machine gun sound loaded successfully");
machineGunSound.setBuffer(buffer);
machineGunSound.setVolume(effectsVolume);
sounds.machinegun = machineGunSound;
},
undefined,
function (error) {
console.error("Error loading machine gun sound:", error);
sounds.machinegun = null;
}
);
// Load zombie sound
audioLoader.load(
"assets/zombie.mp3",
function (buffer) {
console.log("Zombie sound loaded successfully");
zombieGrowlSound.setBuffer(buffer);
zombieGrowlSound.setVolume(effectsVolume);
zombieAttackSound.setBuffer(buffer); // Use same sound for attack
zombieAttackSound.setVolume(effectsVolume);
sounds.zombieGrowl = zombieGrowlSound;
sounds.zombieAttack = zombieAttackSound;
},
undefined,
function (error) {
console.error("Error loading zombie sound:", error);
sounds.zombieGrowl = null;
sounds.zombieAttack = null;
}
);
console.log("Sound effects loading initiated");
}
// Update volume for loaded sounds
function updateSoundVolumes() {
if (sounds.gunfire && sounds.gunfire.setVolume) {
sounds.gunfire.setVolume(effectsVolume);
}
if (sounds.machinegun && sounds.machinegun.setVolume) {
sounds.machinegun.setVolume(effectsVolume);
}
if (sounds.zombieGrowl && sounds.zombieGrowl.setVolume) {
sounds.zombieGrowl.setVolume(effectsVolume);
}
if (sounds.zombieAttack && sounds.zombieAttack.setVolume) {
sounds.zombieAttack.setVolume(effectsVolume);
}
}
// Play gunfire sound
function playGunfireSound() {
// Use appropriate sound based on current weapon
const weaponSound =
currentWeapon === "rifle" ? sounds.gunfire : sounds.machinegun;
if (!weaponSound) {
console.warn(`No sound loaded for ${currentWeapon}`);
return;
}
// Stop the sound if it's already playing (for rapid fire)
if (weaponSound.isPlaying) {
weaponSound.stop();
}
// Update volume and play
weaponSound.setVolume(effectsVolume);
weaponSound.play();
}
// Play zombie growl sound
function playZombieGrowlSound() {
if (!sounds.zombieGrowl) {
console.warn("No zombie growl sound loaded");
return;
}
const currentTime = Date.now();
if (currentTime - lastGrowlTime < growlCooldownTime) return;
lastGrowlTime = currentTime;
// Stop the sound if it's already playing
if (sounds.zombieGrowl.isPlaying) {
sounds.zombieGrowl.stop();
}
// Update volume and play
sounds.zombieGrowl.setVolume(effectsVolume * 0.6);
sounds.zombieGrowl.play();
}
// Play zombie attack sound
function playZombieAttackSound() {
if (!sounds.zombieAttack) {
console.warn("No zombie attack sound loaded");
return;
}
// Stop the sound if it's already playing
if (sounds.zombieAttack.isPlaying) {
sounds.zombieAttack.stop();
}
// Update volume and play
sounds.zombieAttack.setVolume(effectsVolume * 0.8);
sounds.zombieAttack.play();
}
// Initialize the scene
function init() {
// Create scene
scene = new THREE.Scene();
// Create camera
camera = new THREE.PerspectiveCamera(
75, // Field of view
window.innerWidth / window.innerHeight, // Aspect ratio
0.1, // Near clipping plane
1000 // Far clipping plane
);
camera.position.set(0, 5, 20);
// Create renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x87ceeb); // Sky blue background
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
// Initialize audio system
initAudio();
// Initialize pointer lock controls
initControls();
// Create weapons
createGun();
createMachineGun();
// Create ground
createGround();
// Create sky
createSky();
// Add lighting
addLighting();
// Add some objects to make the scene more interesting
addObjects();
// Load zombie model and start wave system
loadZombieModel();
// Add event listeners
addEventListeners();
// Initialize radar
initRadar();
// Start animation loop
animate();
}
// Create ground plane
function createGround() {
const groundGeometry = new THREE.PlaneGeometry(100, 100);
const groundMaterial = new THREE.MeshLambertMaterial({
color: 0x4a4a4a,
side: THREE.DoubleSide,
});
ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
ground.position.y = 0;
ground.receiveShadow = true;
scene.add(ground);
// Add a grid helper for better depth perception
const gridHelper = new THREE.GridHelper(100, 100, 0x606060, 0x404040);
scene.add(gridHelper);
}
// Create sky dome
function createSky() {
const skyGeometry = new THREE.SphereGeometry(500, 60, 40);
const skyMaterial = new THREE.MeshBasicMaterial({
color: 0x87ceeb,
side: THREE.BackSide, // Render inside of sphere
});
sky = new THREE.Mesh(skyGeometry, skyMaterial);
scene.add(sky);
// Add gradient effect to sky
const skyGradient = new THREE.ShaderMaterial({
uniforms: {
topColor: { value: new THREE.Color(0x0077be) },
bottomColor: { value: new THREE.Color(0x87ceeb) },
offset: { value: 33 },
exponent: { value: 0.6 },
},
vertexShader: `
varying vec3 vWorldPosition;
void main() {
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorldPosition = worldPosition.xyz;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform vec3 topColor;
uniform vec3 bottomColor;
uniform float offset;
uniform float exponent;
varying vec3 vWorldPosition;
void main() {
float h = normalize(vWorldPosition + offset).y;
gl_FragColor = vec4(mix(bottomColor, topColor, max(pow(max(h, 0.0), exponent), 0.0)), 1.0);
}
`,
side: THREE.BackSide,
});
sky.material = skyGradient;
}
// Add lighting to the scene
function addLighting() {
// Ambient light
const ambientLight = new THREE.AmbientLight(0x404040, 0.4);
scene.add(ambientLight);
// Directional light (sun)
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(50, 50, 50);
directionalLight.castShadow = true;
// Configure shadow properties
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
directionalLight.shadow.camera.near = 0.5;
directionalLight.shadow.camera.far = 500;
directionalLight.shadow.camera.left = -50;
directionalLight.shadow.camera.right = 50;
directionalLight.shadow.camera.top = 50;
directionalLight.shadow.camera.bottom = -50;
scene.add(directionalLight);
// Point light for additional illumination
const pointLight = new THREE.PointLight(0xffffff, 0.5, 100);
pointLight.position.set(10, 10, 10);
pointLight.castShadow = true;
scene.add(pointLight);
}
// Add apocalyptic environment objects to create zombie movie atmosphere
function addObjects() {
// Create burned/abandoned buildings
createBurnedBuildings();
// Create abandoned vehicles
createAbandonedVehicles();
// Create graveyard elements
createGraveyardElements();
// Create dead trees
createDeadTrees();
// Create debris and wreckage
createDebrisAndWreckage();
// Create additional urban elements
createStreetLights();
// Create barricades and barriers
createBarricades();
// Create ruined structures
createRuinedStructures();
// Create playground areas
createPlaygrounds();
// Create school buildings
createSchools();
// Create hospital complexes
createHospitals();
}
// Create burned and damaged buildings
function createBurnedBuildings() {
for (let i = 0; i < 2; i++) {
const buildingGroup = new THREE.Group();
// Main building structure
const buildingGeometry = new THREE.BoxGeometry(
4 + Math.random() * 3,
3 + Math.random() * 4,
4 + Math.random() * 3
);
const buildingMaterial = new THREE.MeshLambertMaterial({
color: 0x2a2a2a, // Dark gray/black for burned look
});
const building = new THREE.Mesh(buildingGeometry, buildingMaterial);
building.position.y = building.geometry.parameters.height / 2;
buildingGroup.add(building);
// Roof (damaged/collapsed)
const roofGeometry = new THREE.BoxGeometry(
buildingGeometry.parameters.width + 0.5,
0.3,
buildingGeometry.parameters.depth + 0.5
);
const roofMaterial = new THREE.MeshLambertMaterial({ color: 0x1a1a1a });
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = buildingGeometry.parameters.height + 0.15;
roof.rotation.z = (Math.random() - 0.5) * 0.3; // Slight tilt for damage
buildingGroup.add(roof);
// Windows (broken/dark)
for (let j = 0; j < 3; j++) {
const windowGeometry = new THREE.BoxGeometry(0.8, 1.2, 0.1);
const windowMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 });
const window = new THREE.Mesh(windowGeometry, windowMaterial);
window.position.set(
-1.5 + j * 1.5,
1 + Math.random() * 1.5,
buildingGeometry.parameters.depth / 2 + 0.05
);
buildingGroup.add(window);
}
// Damage/holes in walls
const holeGeometry = new THREE.BoxGeometry(1, 1.5, 0.2);
const holeMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 });
const hole = new THREE.Mesh(holeGeometry, holeMaterial);
hole.position.set(Math.random() * 2 - 1, 1, 0);
buildingGroup.add(hole);
// Add social media advertising text on walls
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 1024;
canvas.height = 512;
// Set background with border
ctx.fillStyle = "#000000";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#00ffcc";
ctx.fillRect(10, 10, canvas.width - 20, canvas.height - 20);
ctx.fillStyle = "#000000";
ctx.fillRect(20, 20, canvas.width - 40, canvas.height - 40);
// Configure text style
ctx.fillStyle = "#00ffcc";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
// Add different social media handles for each building
if (i === 0) {
// First building: GitHub, LinkedIn, X
ctx.font = "bold 40px Arial";
ctx.fillText("FOLLOW ON:", canvas.width / 2, 80);
ctx.font = "bold 32px Arial";
ctx.fillText("GitHub: apoorvdarshan", canvas.width / 2, 150);
ctx.fillText("LinkedIn: apoorvdarshan", canvas.width / 2, 200);
ctx.fillText("X: @apoorvdarshan", canvas.width / 2, 250);
ctx.font = "bold 28px Arial";
ctx.fillText("FOLLOW FOR UPDATES!", canvas.width / 2, 320);
} else {
// Second building: YouTube, Instagram
ctx.font = "bold 40px Arial";
ctx.fillText("FOLLOW ON:", canvas.width / 2, 100);
ctx.font = "bold 32px Arial";
ctx.fillText("YouTube: @apoorvdarshan", canvas.width / 2, 170);
ctx.fillText("Instagram: @apoorvdarshan", canvas.width / 2, 220);
ctx.font = "bold 28px Arial";
ctx.fillText("LIKE & SUBSCRIBE!", canvas.width / 2, 290);
}
// Create texture from canvas
const texture = new THREE.CanvasTexture(canvas);
texture.needsUpdate = true;
// Don't flip Y - keep it as default (true) for proper orientation
// Create advertising sign material
const signMaterial = new THREE.MeshBasicMaterial({
map: texture,
transparent: false,
});
// Add advertising sign to building wall
const signGeometry = new THREE.PlaneGeometry(5, 2.5);
const sign = new THREE.Mesh(signGeometry, signMaterial);
// Position the sign clearly on the front wall
sign.position.set(0, 2.5, buildingGeometry.parameters.depth / 2 + 0.02);
// Make sure it casts and receives shadows
sign.castShadow = true;
sign.receiveShadow = true;
buildingGroup.add(sign);
// Position building
buildingGroup.position.set(
(Math.random() - 0.5) * 70,
0,
(Math.random() - 0.5) * 70
);
buildingGroup.rotation.y = Math.random() * Math.PI;
// Enable shadows
buildingGroup.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(buildingGroup);
}
}
// Create abandoned and wrecked vehicles
function createAbandonedVehicles() {
for (let i = 0; i < 6; i++) {
const carGroup = new THREE.Group();
// Car body
const bodyGeometry = new THREE.BoxGeometry(4, 1.2, 1.8);
const bodyMaterial = new THREE.MeshLambertMaterial({
color: [0x8b0000, 0x2f4f4f, 0x1a1a1a, 0x654321][
Math.floor(Math.random() * 4)
], // Random rust/dark colors
});
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.position.y = 0.6;
carGroup.add(body);
// Car roof/cabin
const cabinGeometry = new THREE.BoxGeometry(2.5, 1, 1.6);
const cabinMaterial = new THREE.MeshLambertMaterial({ color: 0x2a2a2a });
const cabin = new THREE.Mesh(cabinGeometry, cabinMaterial);
cabin.position.set(0.5, 1.7, 0);
carGroup.add(cabin);
// Wheels (flat/damaged)
for (let j = 0; j < 4; j++) {
const wheelGeometry = new THREE.CylinderGeometry(0.4, 0.4, 0.3, 8);
const wheelMaterial = new THREE.MeshLambertMaterial({ color: 0x1a1a1a });
const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(j < 2 ? -1.5 : 1.5, 0.2, j % 2 === 0 ? -0.8 : 0.8);
carGroup.add(wheel);
}
// Broken windows
const windshieldGeometry = new THREE.BoxGeometry(2.2, 0.8, 0.05);
const windshieldMaterial = new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.3,
});
const windshield = new THREE.Mesh(windshieldGeometry, windshieldMaterial);
windshield.position.set(0.8, 1.5, 0.8);
windshield.rotation.x = -0.2;
carGroup.add(windshield);
// Position car
carGroup.position.set(
(Math.random() - 0.5) * 75,
0,
(Math.random() - 0.5) * 75
);
carGroup.rotation.y = Math.random() * Math.PI * 2;
carGroup.rotation.z = (Math.random() - 0.5) * 0.2; // Slight tilt
// Enable shadows
carGroup.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(carGroup);
}
}
// Create graveyard elements
function createGraveyardElements() {
for (let i = 0; i < 8; i++) {
const tombstoneGroup = new THREE.Group();
// Tombstone base
const baseGeometry = new THREE.BoxGeometry(0.8, 1.5, 0.2);
const baseMaterial = new THREE.MeshLambertMaterial({ color: 0x696969 });
const base = new THREE.Mesh(baseGeometry, baseMaterial);
base.position.y = 0.75;
tombstoneGroup.add(base);
// Tombstone top (rounded or cross)
if (Math.random() > 0.5) {
// Rounded top
const topGeometry = new THREE.CylinderGeometry(0.4, 0.4, 0.2, 8);
const topMaterial = new THREE.MeshLambertMaterial({ color: 0x555555 });
const top = new THREE.Mesh(topGeometry, topMaterial);
top.position.y = 1.6;
top.rotation.x = Math.PI / 2;
tombstoneGroup.add(top);
} else {
// Cross
const crossV = new THREE.BoxGeometry(0.1, 0.6, 0.1);
const crossH = new THREE.BoxGeometry(0.4, 0.1, 0.1);
const crossMaterial = new THREE.MeshLambertMaterial({ color: 0x4a4a4a });
const verticalCross = new THREE.Mesh(crossV, crossMaterial);
verticalCross.position.y = 1.8;
tombstoneGroup.add(verticalCross);
const horizontalCross = new THREE.Mesh(crossH, crossMaterial);
horizontalCross.position.y = 1.9;
tombstoneGroup.add(horizontalCross);
}
// Small mound of dirt
const moundGeometry = new THREE.SphereGeometry(1.2, 8, 6);
const moundMaterial = new THREE.MeshLambertMaterial({ color: 0x3e2723 });
const mound = new THREE.Mesh(moundGeometry, moundMaterial);
mound.position.y = -0.3;
mound.scale.y = 0.3;
tombstoneGroup.add(mound);
// Position tombstone
tombstoneGroup.position.set(
(Math.random() - 0.5) * 65,
0,
(Math.random() - 0.5) * 65
);
tombstoneGroup.rotation.y = Math.random() * Math.PI * 2;
tombstoneGroup.rotation.z = (Math.random() - 0.5) * 0.1; // Slight lean
// Enable shadows
tombstoneGroup.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(tombstoneGroup);
}
}
// Create dead trees
function createDeadTrees() {
for (let i = 0; i < 6; i++) {
const treeGroup = new THREE.Group();
// Tree trunk
const trunkGeometry = new THREE.CylinderGeometry(
0.2,
0.3,
3 + Math.random() * 2,
6
);
const trunkMaterial = new THREE.MeshLambertMaterial({ color: 0x2d1b14 });
const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
trunk.position.y = trunk.geometry.parameters.height / 2;
treeGroup.add(trunk);
// Dead branches
for (let j = 0; j < 3 + Math.random() * 3; j++) {
const branchGeometry = new THREE.CylinderGeometry(
0.05,
0.1,
1 + Math.random() * 1.5,
4
);
const branchMaterial = new THREE.MeshLambertMaterial({ color: 0x1a1a1a });
const branch = new THREE.Mesh(branchGeometry, branchMaterial);
branch.position.set(
Math.random() * 2 - 1,
2 + Math.random() * 2,
Math.random() * 2 - 1
);
branch.rotation.z = ((Math.random() - 0.5) * Math.PI) / 2;
branch.rotation.x = ((Math.random() - 0.5) * Math.PI) / 4;
treeGroup.add(branch);
}
// Position tree
treeGroup.position.set(
(Math.random() - 0.5) * 80,
0,
(Math.random() - 0.5) * 80
);
// Enable shadows
treeGroup.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(treeGroup);
}
}
// Create debris and wreckage
function createDebrisAndWreckage() {
for (let i = 0; i < 6; i++) {
const debrisGroup = new THREE.Group();
// Random debris pieces
for (let j = 0; j < 2 + Math.random() * 3; j++) {
const debrisGeometry = new THREE.BoxGeometry(
0.3 + Math.random() * 1.5,
0.2 + Math.random() * 0.8,
0.3 + Math.random() * 1.2
);
const debrisMaterial = new THREE.MeshLambertMaterial({
color: [0x2f2f2f, 0x8b4513, 0x1a1a1a, 0x654321][
Math.floor(Math.random() * 4)
],
});
const debris = new THREE.Mesh(debrisGeometry, debrisMaterial);
debris.position.set(
(Math.random() - 0.5) * 3,
debris.geometry.parameters.height / 2,
(Math.random() - 0.5) * 3
);
debris.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
debris.castShadow = true;
debris.receiveShadow = true;
debrisGroup.add(debris);
}
// Position debris cluster
debrisGroup.position.set(
(Math.random() - 0.5) * 70,
0,
(Math.random() - 0.5) * 70
);
scene.add(debrisGroup);
}
}
// Create broken street lights and lamp posts
function createStreetLights() {
for (let i = 0; i < 6; i++) {
const lampGroup = new THREE.Group();
// Lamp post
const postGeometry = new THREE.CylinderGeometry(0.1, 0.15, 4, 8);
const postMaterial = new THREE.MeshLambertMaterial({ color: 0x3a3a3a });
const post = new THREE.Mesh(postGeometry, postMaterial);
post.position.y = 2;
lampGroup.add(post);
// Lamp head (broken/dark)
const headGeometry = new THREE.BoxGeometry(0.8, 0.6, 0.8);
const headMaterial = new THREE.MeshLambertMaterial({ color: 0x1a1a1a });
const head = new THREE.Mesh(headGeometry, headMaterial);
head.position.y = 4.3;
head.rotation.x = (Math.random() - 0.5) * 0.4; // Tilted/damaged
lampGroup.add(head);
// Some hanging wires
const wireGeometry = new THREE.CylinderGeometry(0.02, 0.02, 1, 4);
const wireMaterial = new THREE.MeshLambertMaterial({ color: 0x2c2c2c });
const wire = new THREE.Mesh(wireGeometry, wireMaterial);
wire.position.set(0.3, 3.5, 0);
wire.rotation.z = 0.3;
lampGroup.add(wire);
// Position lamp
lampGroup.position.set(
(Math.random() - 0.5) * 75,
0,
(Math.random() - 0.5) * 75
);
lampGroup.rotation.y = Math.random() * Math.PI * 2;
lampGroup.rotation.z = (Math.random() - 0.5) * 0.2; // Slight lean
// Enable shadows
lampGroup.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(lampGroup);
}
}
// Create barricades and roadblocks
function createBarricades() {
for (let i = 0; i < 8; i++) {
const barrierGroup = new THREE.Group();
// Main barrier structure
for (let j = 0; j < 2 + Math.random() * 3; j++) {
const barrierGeometry = new THREE.BoxGeometry(2, 0.8, 0.3);
const barrierMaterial = new THREE.MeshLambertMaterial({
color: [0x8b4513, 0x2f2f2f, 0x654321][Math.floor(Math.random() * 3)],
});
const barrier = new THREE.Mesh(barrierGeometry, barrierMaterial);
barrier.position.set(j * 2.2, 0.4, 0);
barrier.rotation.y = (Math.random() - 0.5) * 0.3;
barrier.castShadow = true;
barrier.receiveShadow = true;
barrierGroup.add(barrier);
}
// Support posts
for (let k = 0; k < 3; k++) {
const postGeometry = new THREE.BoxGeometry(0.2, 1.5, 0.2);
const postMaterial = new THREE.MeshLambertMaterial({ color: 0x4a4a4a });