Spaces:
Running
Running
Update index.html
Browse files- 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 |
-
|
|
|
319 |
}
|
320 |
|
321 |
selectTarget() {
|
@@ -324,13 +325,13 @@
|
|
324 |
}
|
325 |
|
326 |
shoot() {
|
327 |
-
// μ΅μ΄ λ°μ¬μμλ§ μ리 μ¬μ
|
328 |
if (!this.hasPlayedMGSound) {
|
329 |
-
new Audio('ju87mg.ogg')
|
|
|
|
|
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')
|
|
|
|
|
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(
|
365 |
} else {
|
366 |
this.angle = Math.PI;
|
367 |
this.x -= this.speed;
|
368 |
return this.x > 0;
|
369 |
}
|
370 |
-
} else {
|
371 |
-
|
372 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
-
if (this.target) {
|
375 |
-
|
376 |
-
|
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 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
|
|
|
|
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 |
-
|
399 |
-
this.x += Math.cos(this.angle) * this.speed;
|
400 |
-
this.y += Math.sin(this.angle) * this.speed;
|
401 |
-
}
|
402 |
|
403 |
-
|
404 |
-
|
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 |
-
|
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();
|