cutechicken commited on
Commit
c29708a
โ€ข
1 Parent(s): 7aa0006

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +82 -10
game.js CHANGED
@@ -327,14 +327,14 @@ class Game {
327
 
328
  async initialize() {
329
  try {
330
- // ์•ˆ๊ฐœ ํšจ๊ณผ ์ถ”๊ฐ€
331
- this.scene.fog = new THREE.Fog(0xffd700, 1, 100);
332
- this.scene.background = new THREE.Color(0xffd700); // ์‚ฌ๋ง‰ ํ•˜๋Š˜์ƒ‰
333
 
334
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.7); // ์‚ฌ๋ง‰ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ๋ฐ๊ธฐ ์ฆ๊ฐ€
335
  this.scene.add(ambientLight);
336
 
337
- const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0); // ์‚ฌ๋ง‰์˜ ๊ฐ•ํ•œ ํ–‡๋น›
338
  directionalLight.position.set(50, 50, 50);
339
  directionalLight.castShadow = true;
340
  directionalLight.shadow.mapSize.width = 2048;
@@ -342,33 +342,43 @@ class Game {
342
  this.scene.add(directionalLight);
343
 
344
  // ์‚ฌ๋ง‰ ์ง€ํ˜• ์ƒ์„ฑ
345
- const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
346
  const groundTexture = new THREE.TextureLoader().load('/textures/sand.jpg');
347
  groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
348
  groundTexture.repeat.set(50, 50);
349
 
 
350
  const groundMaterial = new THREE.MeshStandardMaterial({
351
  map: groundTexture,
 
352
  roughness: 1.0,
353
  metalness: 0.0,
354
- color: 0xd2b48c // ์‚ฌ๋ง‰์ƒ‰
355
  });
356
 
357
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
358
  ground.rotation.x = -Math.PI / 2;
359
  ground.receiveShadow = true;
360
 
361
- // ์ง€ํ˜•์˜ ๋†’๋‚ฎ์ด ๋ณ€ํ™” ์ถ”๊ฐ€
362
  const vertices = ground.geometry.attributes.position.array;
 
363
  for (let i = 0; i < vertices.length; i += 3) {
364
- vertices[i + 1] = Math.sin(vertices[i] / 20) * Math.cos(vertices[i + 2] / 20) * 2;
 
 
 
 
 
 
365
  }
366
  ground.geometry.attributes.position.needsUpdate = true;
367
  ground.geometry.computeVertexNormals();
368
 
369
  this.scene.add(ground);
370
 
371
- await this.createBuildings();
 
372
  await this.tank.initialize(this.scene, this.loader);
373
 
374
  if (!this.tank.isLoaded) {
@@ -396,6 +406,68 @@ class Game {
396
  }
397
  }
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  setupEventListeners() {
400
  document.addEventListener('keydown', (event) => {
401
  if (this.isLoading || this.isGameOver) return;
 
327
 
328
  async initialize() {
329
  try {
330
+ // ์•ˆ๊ฐœ ํšจ๊ณผ ์กฐ์ •
331
+ this.scene.fog = new THREE.Fog(0xC2B280, 1, 150); // ๋” ์ž์—ฐ์Šค๋Ÿฌ์šด ์‚ฌ๋ง‰์ƒ‰
332
+ this.scene.background = new THREE.Color(0x87CEEB); // ํ•˜๋Š˜์ƒ‰ ๋ฐฐ๊ฒฝ
333
 
334
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); // ์ฃผ๋ณ€๊ด‘ ๊ฐ์†Œ
335
  this.scene.add(ambientLight);
336
 
337
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2); // ํƒœ์–‘๊ด‘ ๊ฐ•ํ™”
338
  directionalLight.position.set(50, 50, 50);
339
  directionalLight.castShadow = true;
340
  directionalLight.shadow.mapSize.width = 2048;
 
342
  this.scene.add(directionalLight);
343
 
344
  // ์‚ฌ๋ง‰ ์ง€ํ˜• ์ƒ์„ฑ
345
+ const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 200, 200);
346
  const groundTexture = new THREE.TextureLoader().load('/textures/sand.jpg');
347
  groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
348
  groundTexture.repeat.set(50, 50);
349
 
350
+ // ์‚ฌ๋ง‰ ์žฌ์งˆ ๊ฐœ์„ 
351
  const groundMaterial = new THREE.MeshStandardMaterial({
352
  map: groundTexture,
353
+ color: 0xD2B48C,
354
  roughness: 1.0,
355
  metalness: 0.0,
356
+ bumpScale: 0.5
357
  });
358
 
359
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
360
  ground.rotation.x = -Math.PI / 2;
361
  ground.receiveShadow = true;
362
 
363
+ // ์‚ฌ๋ง‰ ์ง€ํ˜•์˜ ๊ธฐ๋ณต ์ถ”๊ฐ€
364
  const vertices = ground.geometry.attributes.position.array;
365
+ let seed = Math.random() * 100;
366
  for (let i = 0; i < vertices.length; i += 3) {
367
+ // Perlin noise๋ฅผ ์‚ฌ์šฉํ•œ ์ž์—ฐ์Šค๋Ÿฌ์šด ๋†’๋‚ฎ์ด
368
+ const x = vertices[i] / 100;
369
+ const y = vertices[i + 1] / 100;
370
+ vertices[i + 2] =
371
+ (Math.sin(x + seed) * Math.cos(y + seed) * 2.0) + // ํฐ ์–ธ๋•
372
+ (Math.sin(x * 2 + seed) * Math.cos(y * 2 + seed) * 1.0) + // ์ค‘๊ฐ„ ํฌ๊ธฐ ์–ธ๋•
373
+ (Math.sin(x * 4 + seed) * Math.cos(y * 4 + seed) * 0.5); // ์ž‘์€ ๋ชจ๋ž˜ ์–ธ๋•
374
  }
375
  ground.geometry.attributes.position.needsUpdate = true;
376
  ground.geometry.computeVertexNormals();
377
 
378
  this.scene.add(ground);
379
 
380
+ // ์‚ฌ๋ง‰ ์žฅ์‹๋ฌผ ์ถ”๊ฐ€
381
+ await this.addDesertDecorations();
382
  await this.tank.initialize(this.scene, this.loader);
383
 
384
  if (!this.tank.isLoaded) {
 
406
  }
407
  }
408
 
409
+ // ์‚ฌ๋ง‰ ์žฅ์‹๋ฌผ ์ถ”๊ฐ€ ๋ฉ”์†Œ๋“œ
410
+ async addDesertDecorations() {
411
+ // ๋ฐ”์œ„ ์ƒ์„ฑ
412
+ const rockGeometries = [
413
+ new THREE.DodecahedronGeometry(3),
414
+ new THREE.DodecahedronGeometry(2),
415
+ new THREE.DodecahedronGeometry(4)
416
+ ];
417
+
418
+ const rockMaterial = new THREE.MeshStandardMaterial({
419
+ color: 0x8B4513,
420
+ roughness: 0.9,
421
+ metalness: 0.1
422
+ });
423
+
424
+ for (let i = 0; i < 100; i++) {
425
+ const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
426
+ const rock = new THREE.Mesh(rockGeometry, rockMaterial);
427
+
428
+ rock.position.set(
429
+ (Math.random() - 0.5) * MAP_SIZE * 0.9,
430
+ Math.random() * 2,
431
+ (Math.random() - 0.5) * MAP_SIZE * 0.9
432
+ );
433
+
434
+ rock.rotation.set(
435
+ Math.random() * Math.PI,
436
+ Math.random() * Math.PI,
437
+ Math.random() * Math.PI
438
+ );
439
+
440
+ rock.scale.set(
441
+ 1 + Math.random() * 0.5,
442
+ 1 + Math.random() * 0.5,
443
+ 1 + Math.random() * 0.5
444
+ );
445
+
446
+ rock.castShadow = true;
447
+ rock.receiveShadow = true;
448
+ this.scene.add(rock);
449
+ }
450
+
451
+ // ์„ ์ธ์žฅ ์ถ”๊ฐ€ (๊ฐ„๋‹จํ•œ geometry๋กœ ํ‘œํ˜„)
452
+ const cactusGeometry = new THREE.CylinderGeometry(0.5, 0.7, 4, 8);
453
+ const cactusMaterial = new THREE.MeshStandardMaterial({
454
+ color: 0x2F4F2F,
455
+ roughness: 0.8
456
+ });
457
+
458
+ for (let i = 0; i < 50; i++) {
459
+ const cactus = new THREE.Mesh(cactusGeometry, cactusMaterial);
460
+ cactus.position.set(
461
+ (Math.random() - 0.5) * MAP_SIZE * 0.8,
462
+ 2,
463
+ (Math.random() - 0.5) * MAP_SIZE * 0.8
464
+ );
465
+ cactus.castShadow = true;
466
+ cactus.receiveShadow = true;
467
+ this.scene.add(cactus);
468
+ }
469
+ }
470
+
471
  setupEventListeners() {
472
  document.addEventListener('keydown', (event) => {
473
  if (this.isLoading || this.isGameOver) return;