cutechicken commited on
Commit
a1d0412
Β·
verified Β·
1 Parent(s): 0f7399b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +41 -39
index.html CHANGED
@@ -309,13 +309,14 @@
309
  this.angle = Math.PI;
310
  this.img = new Image();
311
  this.img.src = 'ju87.png';
312
- this.target = null; // μ²˜μŒμ—λŠ” νƒ€κ²Ÿ μ—†μŒ
313
  this.lastShot = 0;
314
  this.spawnTime = Date.now();
315
  this.hasPlayedSound = false;
316
  this.hasPlayedMGSound = false;
317
  this.isReturning = false;
318
- this.circleAngle = 0; // μ›ν˜• 비행을 μœ„ν•œ 각도 μΆ”κ°€
 
319
  }
320
 
321
  selectTarget() {
@@ -324,13 +325,13 @@
324
  }
325
 
326
  shoot() {
327
- // 졜초 λ°œμ‚¬μ‹œμ—λ§Œ μ†Œλ¦¬ μž¬μƒ
328
  if (!this.hasPlayedMGSound) {
329
- new Audio('ju87mg.ogg').play();
 
 
330
  this.hasPlayedMGSound = true;
331
  }
332
 
333
- // μ–‘μͺ½ 기관총 μœ„μΉ˜
334
  [[59, 36], [59, 62]].forEach(([x, y]) => {
335
  const rotatedX = this.x + (Math.cos(this.angle) * x - Math.sin(this.angle) * y);
336
  const rotatedY = this.y + (Math.sin(this.angle) * x + Math.cos(this.angle) * y);
@@ -348,60 +349,61 @@
348
  }
349
 
350
  update() {
351
- // 졜초 λ“±μž₯μ‹œ μ‚¬μ΄λ Œ
352
  if (!this.hasPlayedSound) {
353
- new Audio('ju87siren.ogg').play();
 
 
354
  this.hasPlayedSound = true;
355
  }
356
 
357
  const timeSinceSpawn = Date.now() - this.spawnTime;
 
 
358
 
359
- // 5초 이후 행동
360
  if (timeSinceSpawn > 5000) {
361
  if (!this.isReturning) {
362
  this.isReturning = true;
363
  this.target = null;
364
- this.angle = Math.atan2(canvas.height/2 - this.y, canvas.width/2 - this.x);
365
  } else {
366
  this.angle = Math.PI;
367
  this.x -= this.speed;
368
  return this.x > 0;
369
  }
370
- } else {
371
- // νƒ€κ²Ÿ μ—†μœΌλ©΄ μƒˆλ‘œ 선택
372
- if (!this.target) this.target = this.selectTarget();
 
 
 
 
 
 
 
373
 
374
- if (this.target) {
375
- if (!enemies.includes(this.target) ||
376
- Math.hypot(this.x - this.target.x, this.y - this.target.y) < 30) {
377
- this.target = this.selectTarget();
378
- }
379
-
380
- if (this.target) {
381
- this.angle = Math.atan2(this.target.y - this.y, this.target.x - this.x);
382
- }
383
  } else {
384
- // 적이 없을 λ•Œ μ›ν˜• λΉ„ν–‰
385
- const centerX = canvas.width / 2;
386
- const centerY = canvas.height / 2;
387
- const radius = Math.min(canvas.width, canvas.height) / 4; // μ›μ˜ λ°˜μ§€λ¦„
388
-
389
- this.circleAngle += 0.02; // μ›μš΄λ™ 속도
 
 
390
  const targetX = centerX + Math.cos(this.circleAngle) * radius;
391
  const targetY = centerY + Math.sin(this.circleAngle) * radius;
392
-
393
  this.angle = Math.atan2(targetY - this.y, targetX - this.x);
394
  }
395
  }
396
 
397
- // 이동
398
- if (!this.isReturning || Math.hypot(this.x - canvas.width/2, this.y - canvas.height/2) > 10) {
399
- this.x += Math.cos(this.angle) * this.speed;
400
- this.y += Math.sin(this.angle) * this.speed;
401
- }
402
 
403
- // λ°œμ‚¬
404
- if (Date.now() - this.lastShot > 200 && this.target && !this.isReturning) {
405
  this.shoot();
406
  this.lastShot = Date.now();
407
  }
@@ -540,7 +542,7 @@ function buyTank(tankImg, cost, tankId) {
540
  lastJU87Spawn = Date.now(); // ꡬ맀 μ¦‰μ‹œ 슀폰 타이머 μ΄ˆκΈ°ν™”
541
  }
542
  }
543
- function initRound() {
544
  enemies = [];
545
  for(let i = 0; i < 1 * currentRound; i++) {
546
  enemies.push(new Enemy());
@@ -548,10 +550,10 @@ function buyTank(tankImg, cost, tankId) {
548
  player.health = player.maxHealth;
549
  bullets = [];
550
  items = [];
551
- supportUnits = []; // 지원 μœ λ‹› μ΄ˆκΈ°ν™”
552
- lastSupportSpawn = 0; // 슀폰 타이머 μ΄ˆκΈ°ν™”
553
 
554
- // JU87 초기 슀폰 μΆ”κ°€
555
  if (hasJU87) {
556
  supportUnits.push(new JU87());
557
  lastJU87Spawn = Date.now();
 
309
  this.angle = Math.PI;
310
  this.img = new Image();
311
  this.img.src = 'ju87.png';
312
+ this.target = null;
313
  this.lastShot = 0;
314
  this.spawnTime = Date.now();
315
  this.hasPlayedSound = false;
316
  this.hasPlayedMGSound = false;
317
  this.isReturning = false;
318
+ this.circleAngle = 0;
319
+ this.returningToCenter = false; // μ€‘μ•™μœΌλ‘œ λŒμ•„κ°€λŠ” μƒνƒœ μΆ”κ°€
320
  }
321
 
322
  selectTarget() {
 
325
  }
326
 
327
  shoot() {
 
328
  if (!this.hasPlayedMGSound) {
329
+ const mgSound = new Audio('ju87mg.ogg');
330
+ mgSound.volume = 1.0;
331
+ mgSound.play().catch(error => console.error('Audio play failed:', error));
332
  this.hasPlayedMGSound = true;
333
  }
334
 
 
335
  [[59, 36], [59, 62]].forEach(([x, y]) => {
336
  const rotatedX = this.x + (Math.cos(this.angle) * x - Math.sin(this.angle) * y);
337
  const rotatedY = this.y + (Math.sin(this.angle) * x + Math.cos(this.angle) * y);
 
349
  }
350
 
351
  update() {
 
352
  if (!this.hasPlayedSound) {
353
+ const sirenSound = new Audio('ju87siren.ogg');
354
+ sirenSound.volume = 1.0;
355
+ sirenSound.play().catch(error => console.error('Audio play failed:', error));
356
  this.hasPlayedSound = true;
357
  }
358
 
359
  const timeSinceSpawn = Date.now() - this.spawnTime;
360
+ const centerX = canvas.width / 2;
361
+ const centerY = canvas.height / 2;
362
 
 
363
  if (timeSinceSpawn > 5000) {
364
  if (!this.isReturning) {
365
  this.isReturning = true;
366
  this.target = null;
367
+ this.angle = Math.atan2(centerY - this.y, centerX - this.x);
368
  } else {
369
  this.angle = Math.PI;
370
  this.x -= this.speed;
371
  return this.x > 0;
372
  }
373
+ } else if (this.returningToCenter) {
374
+ const distToCenter = Math.hypot(this.x - centerX, this.y - centerY);
375
+ if (distToCenter > 50) {
376
+ this.angle = Math.atan2(centerY - this.y, centerX - this.x);
377
+ } else {
378
+ this.returningToCenter = false;
379
+ this.target = this.selectTarget();
380
+ }
381
+ } else if (this.target) {
382
+ const distToTarget = Math.hypot(this.x - this.target.x, this.y - this.target.y);
383
 
384
+ if (!enemies.includes(this.target) || distToTarget < 30) {
385
+ this.returningToCenter = true;
386
+ this.target = null;
 
 
 
 
 
 
387
  } else {
388
+ this.angle = Math.atan2(this.target.y - this.y, this.target.x - this.x);
389
+ }
390
+ } else {
391
+ this.target = this.selectTarget();
392
+
393
+ if (!this.target) {
394
+ this.circleAngle += 0.02;
395
+ const radius = Math.min(canvas.width, canvas.height) / 4;
396
  const targetX = centerX + Math.cos(this.circleAngle) * radius;
397
  const targetY = centerY + Math.sin(this.circleAngle) * radius;
 
398
  this.angle = Math.atan2(targetY - this.y, targetX - this.x);
399
  }
400
  }
401
 
402
+ this.x += Math.cos(this.angle) * this.speed;
403
+ this.y += Math.sin(this.angle) * this.speed;
 
 
 
404
 
405
+ if (!this.returningToCenter && !this.isReturning && this.target &&
406
+ Date.now() - this.lastShot > 200) {
407
  this.shoot();
408
  this.lastShot = Date.now();
409
  }
 
542
  lastJU87Spawn = Date.now(); // ꡬ맀 μ¦‰μ‹œ 슀폰 타이머 μ΄ˆκΈ°ν™”
543
  }
544
  }
545
+ function initRound() {
546
  enemies = [];
547
  for(let i = 0; i < 1 * currentRound; i++) {
548
  enemies.push(new Enemy());
 
550
  player.health = player.maxHealth;
551
  bullets = [];
552
  items = [];
553
+ supportUnits = [];
554
+ lastSupportSpawn = 0;
555
 
556
+ // JU87 초기 슀폰
557
  if (hasJU87) {
558
  supportUnits.push(new JU87());
559
  lastJU87Spawn = Date.now();