cutechicken
commited on
Update index.html
Browse files- index.html +115 -13
index.html
CHANGED
@@ -109,6 +109,13 @@
|
|
109 |
<p style="color: #4CAF50;">+100% HP</p>
|
110 |
<p style="color: #ff6b6b;">-30% Speed</p>
|
111 |
<button onclick="buyTank('player3.png', 500, 'tank2')">Buy</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
</div>
|
113 |
<div id="apcr" style="text-align:center;">
|
114 |
<h3>APCR</h3>
|
@@ -148,6 +155,9 @@
|
|
148 |
let isBossStage = false;
|
149 |
let effects = [];
|
150 |
let hasAPCR = false; // APCR ๊ตฌ๋งค ์ฌ๋ถ
|
|
|
|
|
|
|
151 |
// Load assets
|
152 |
const backgroundImg = new Image();
|
153 |
backgroundImg.src = 'city.png';
|
@@ -235,6 +245,61 @@
|
|
235 |
isExpired() {
|
236 |
return Date.now() - this.startTime > this.duration;
|
237 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
}
|
239 |
class Enemy {
|
240 |
constructor(isBoss = false) {
|
@@ -348,6 +413,14 @@ function buyTank(tankImg, cost, tankId) {
|
|
348 |
document.getElementById('apcr').style.display = 'none';
|
349 |
document.getElementById('shop').style.display = 'none';
|
350 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
}
|
352 |
function initRound() {
|
353 |
enemies = [];
|
@@ -414,17 +487,35 @@ function buyTank(tankImg, cost, tankId) {
|
|
414 |
}
|
415 |
}
|
416 |
function updateGame() {
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
if(!isCountingDown) {
|
429 |
bullets = bullets.filter(bullet => {
|
430 |
bullet.x += Math.cos(bullet.angle) * bullet.speed;
|
@@ -530,7 +621,13 @@ function buyTank(tankImg, cost, tankId) {
|
|
530 |
ctx.restore();
|
531 |
drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
|
532 |
});
|
533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
// ์ด์ ๊ทธ๋ฆฌ๊ธฐ
|
535 |
bullets.forEach(bullet => {
|
536 |
if (bullet.isEnemy || !bullet.isAPCR) {
|
@@ -604,11 +701,16 @@ restartBtn.addEventListener('click', () => {
|
|
604 |
isBossStage = false;
|
605 |
gold = 0;
|
606 |
hasAPCR = false; // APCR ์ด๊ธฐํ
|
|
|
|
|
|
|
607 |
restartBtn.style.display = 'none';
|
608 |
document.getElementById('winMessage').style.display = 'none';
|
609 |
document.getElementById('tank1').style.display = 'block';
|
610 |
document.getElementById('tank2').style.display = 'block';
|
611 |
-
document.getElementById('apcr').style.display = 'block';
|
|
|
|
|
612 |
playerImg.src = 'player.png';
|
613 |
bgm.src = 'BGM2.ogg';
|
614 |
bgm.play();
|
|
|
109 |
<p style="color: #4CAF50;">+100% HP</p>
|
110 |
<p style="color: #ff6b6b;">-30% Speed</p>
|
111 |
<button onclick="buyTank('player3.png', 500, 'tank2')">Buy</button>
|
112 |
+
</div>
|
113 |
+
<div id="bf109" style="text-align:center;">
|
114 |
+
<h3>BF-109</h3>
|
115 |
+
<img src="bf109.png" width="100" height="100">
|
116 |
+
<p>1000 Gold</p>
|
117 |
+
<p style="color: #4CAF50;">Air support from BF-109</p>
|
118 |
+
<button onclick="buyBF109()">Buy</button>
|
119 |
</div>
|
120 |
<div id="apcr" style="text-align:center;">
|
121 |
<h3>APCR</h3>
|
|
|
155 |
let isBossStage = false;
|
156 |
let effects = [];
|
157 |
let hasAPCR = false; // APCR ๊ตฌ๋งค ์ฌ๋ถ
|
158 |
+
let hasBF109 = false; // BF-109 ๊ตฌ๋งค ์ฌ๋ถ
|
159 |
+
let supportUnits = []; // ์ง์ ์ ๋ ๋ฐฐ์ด
|
160 |
+
let lastSupportSpawn = 0; // ๋ง์ง๋ง ์ง์ ์ ๋ ์์ฑ ์๊ฐ
|
161 |
// Load assets
|
162 |
const backgroundImg = new Image();
|
163 |
backgroundImg.src = 'city.png';
|
|
|
245 |
isExpired() {
|
246 |
return Date.now() - this.startTime > this.duration;
|
247 |
}
|
248 |
+
}
|
249 |
+
class SupportUnit {
|
250 |
+
constructor(yPosition) {
|
251 |
+
this.x = 0;
|
252 |
+
this.y = yPosition;
|
253 |
+
this.speed = 5; // ๊ธฐ๋ณธ ์ด๋ ์๋
|
254 |
+
this.lastShot = 0;
|
255 |
+
this.width = 100;
|
256 |
+
this.height = 100;
|
257 |
+
this.angle = 0;
|
258 |
+
this.img = new Image();
|
259 |
+
this.img.src = 'bf109.png';
|
260 |
+
}
|
261 |
+
|
262 |
+
update() {
|
263 |
+
// ์ด๋
|
264 |
+
this.x += this.speed;
|
265 |
+
|
266 |
+
// ๋ฐ์ฌ (1์ด์ 5๋ฐ)
|
267 |
+
const now = Date.now();
|
268 |
+
if (now - this.lastShot > 200) { // 200ms = 1์ด์ 5๋ฐ
|
269 |
+
this.shoot();
|
270 |
+
this.lastShot = now;
|
271 |
+
}
|
272 |
+
|
273 |
+
// ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์ ํฅํด ๊ฐ๋ ์กฐ์
|
274 |
+
let nearestEnemy = null;
|
275 |
+
let minDist = Infinity;
|
276 |
+
enemies.forEach(enemy => {
|
277 |
+
const dist = Math.hypot(enemy.x - this.x, enemy.y - this.y);
|
278 |
+
if (dist < minDist) {
|
279 |
+
minDist = dist;
|
280 |
+
nearestEnemy = enemy;
|
281 |
+
}
|
282 |
+
});
|
283 |
+
|
284 |
+
if (nearestEnemy) {
|
285 |
+
this.angle = Math.atan2(nearestEnemy.y - this.y, nearestEnemy.x - this.x);
|
286 |
+
}
|
287 |
+
|
288 |
+
return this.x < canvas.width; // ํ๋ฉด ๋ด์ ์์ผ๋ฉด true ๋ฐํ
|
289 |
+
}
|
290 |
+
|
291 |
+
shoot() {
|
292 |
+
machinegunSound.cloneNode().play();
|
293 |
+
bullets.push({
|
294 |
+
x: this.x + Math.cos(this.angle) * 30,
|
295 |
+
y: this.y + Math.sin(this.angle) * 30,
|
296 |
+
angle: this.angle,
|
297 |
+
speed: 10,
|
298 |
+
isEnemy: false,
|
299 |
+
damage: weapons.machinegun.damage,
|
300 |
+
size: weapons.machinegun.bulletSize
|
301 |
+
});
|
302 |
+
}
|
303 |
}
|
304 |
class Enemy {
|
305 |
constructor(isBoss = false) {
|
|
|
413 |
document.getElementById('apcr').style.display = 'none';
|
414 |
document.getElementById('shop').style.display = 'none';
|
415 |
}
|
416 |
+
}
|
417 |
+
function buyBF109() {
|
418 |
+
if (gold >= 1000 && !hasBF109) {
|
419 |
+
gold -= 1000;
|
420 |
+
hasBF109 = true;
|
421 |
+
document.getElementById('bf109').style.display = 'none';
|
422 |
+
document.getElementById('shop').style.display = 'none';
|
423 |
+
}
|
424 |
}
|
425 |
function initRound() {
|
426 |
enemies = [];
|
|
|
487 |
}
|
488 |
}
|
489 |
function updateGame() {
|
490 |
+
if(gameOver) return;
|
491 |
+
if(!isCountingDown) {
|
492 |
+
// ํ๋ ์ด์ด ์์ง์
|
493 |
+
if(keys['w']) player.y -= player.speed;
|
494 |
+
if(keys['s']) player.y += player.speed;
|
495 |
+
if(keys['a']) player.x -= player.speed;
|
496 |
+
if(keys['d']) player.x += player.speed;
|
497 |
+
player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
|
498 |
+
player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
|
499 |
+
fireBullet();
|
500 |
+
}
|
501 |
+
|
502 |
+
// ์ฌ๊ธฐ์ BF109 ๊ด๋ จ ์ฝ๋ ์ถ๊ฐ
|
503 |
+
if (hasBF109 && !isCountingDown) {
|
504 |
+
const now = Date.now();
|
505 |
+
if (now - lastSupportSpawn > 10000) { // 10์ด๋ง๋ค
|
506 |
+
// ์๋จ, ์ค๋จ, ํ๋จ์ ์ ๋ ์์ฑ
|
507 |
+
supportUnits.push(
|
508 |
+
new SupportUnit(canvas.height * 0.2),
|
509 |
+
new SupportUnit(canvas.height * 0.5),
|
510 |
+
new SupportUnit(canvas.height * 0.8)
|
511 |
+
);
|
512 |
+
lastSupportSpawn = now;
|
513 |
+
}
|
514 |
+
// ์ง์ ์ ๋ ์
๋ฐ์ดํธ ๋ฐ ํ๋ฉด ๋ฐ ์ ๋ ์ ๊ฑฐ
|
515 |
+
supportUnits = supportUnits.filter(unit => unit.update());
|
516 |
+
}
|
517 |
+
|
518 |
+
enemies.forEach(enemy => enemy.update());
|
519 |
if(!isCountingDown) {
|
520 |
bullets = bullets.filter(bullet => {
|
521 |
bullet.x += Math.cos(bullet.angle) * bullet.speed;
|
|
|
621 |
ctx.restore();
|
622 |
drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
|
623 |
});
|
624 |
+
supportUnits.forEach(unit => {
|
625 |
+
ctx.save();
|
626 |
+
ctx.translate(unit.x, unit.y);
|
627 |
+
ctx.rotate(unit.angle);
|
628 |
+
ctx.drawImage(unit.img, -unit.width/2, -unit.height/2, unit.width, unit.height);
|
629 |
+
ctx.restore();
|
630 |
+
});
|
631 |
// ์ด์ ๊ทธ๋ฆฌ๊ธฐ
|
632 |
bullets.forEach(bullet => {
|
633 |
if (bullet.isEnemy || !bullet.isAPCR) {
|
|
|
701 |
isBossStage = false;
|
702 |
gold = 0;
|
703 |
hasAPCR = false; // APCR ์ด๊ธฐํ
|
704 |
+
hasBF109 = false; // BF109 ์ด๊ธฐํ
|
705 |
+
supportUnits = []; // ์ง์ ์ ๋ ๋ฐฐ์ด ์ด๊ธฐํ
|
706 |
+
|
707 |
restartBtn.style.display = 'none';
|
708 |
document.getElementById('winMessage').style.display = 'none';
|
709 |
document.getElementById('tank1').style.display = 'block';
|
710 |
document.getElementById('tank2').style.display = 'block';
|
711 |
+
document.getElementById('apcr').style.display = 'block';
|
712 |
+
document.getElementById('bf109').style.display = 'block'; // BF109 ์์ ์์ดํ
๋ค์ ํ์
|
713 |
+
|
714 |
playerImg.src = 'player.png';
|
715 |
bgm.src = 'BGM2.ogg';
|
716 |
bgm.play();
|