Spaces:
Running
Running
cutechicken
commited on
Update index.html
Browse files- index.html +67 -53
index.html
CHANGED
@@ -471,55 +471,61 @@ function buyTank(tankImg, cost, tankId) {
|
|
471 |
ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
|
472 |
}
|
473 |
function drawGame() {
|
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 |
ctx.fillStyle = 'white';
|
512 |
ctx.font = '24px Arial';
|
513 |
ctx.fillText(`Round ${currentRound}/10`, 10, 30);
|
514 |
ctx.fillText(`Gold: ${gold}`, 10, 60);
|
515 |
|
516 |
-
// 이펙트 그리기
|
517 |
effects = effects.filter(effect => !effect.isExpired());
|
518 |
effects.forEach(effect => {
|
519 |
ctx.save();
|
520 |
ctx.translate(effect.x, effect.y);
|
521 |
if(effect.type === 'fire') ctx.rotate(effect.angle);
|
522 |
-
ctx.drawImage(effect.img, -25, -25, 50, 50);
|
523 |
ctx.restore();
|
524 |
});
|
525 |
|
@@ -527,18 +533,24 @@ function buyTank(tankImg, cost, tankId) {
|
|
527 |
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
528 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
529 |
}
|
|
|
|
|
|
|
530 |
function gameLoop() {
|
531 |
updateGame();
|
532 |
drawGame();
|
533 |
requestAnimationFrame(gameLoop);
|
534 |
}
|
|
|
535 |
nextRoundBtn.addEventListener('click', () => {
|
536 |
currentRound++;
|
537 |
nextRoundBtn.style.display = 'none';
|
538 |
-
document.getElementById('shop').style.display = 'none';
|
539 |
initRound();
|
540 |
});
|
|
|
541 |
bossButton.addEventListener('click', startBossStage);
|
|
|
542 |
restartBtn.addEventListener('click', () => {
|
543 |
currentRound = 1;
|
544 |
gameOver = false;
|
@@ -552,19 +564,21 @@ restartBtn.addEventListener('click', () => {
|
|
552 |
bgm.play();
|
553 |
initRound();
|
554 |
});
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
|
|
|
|
568 |
</script>
|
569 |
</body>
|
570 |
</html>
|
|
|
471 |
ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
|
472 |
}
|
473 |
function drawGame() {
|
474 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
475 |
+
const pattern = ctx.createPattern(backgroundImg, 'repeat');
|
476 |
+
ctx.fillStyle = pattern;
|
477 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
478 |
+
|
479 |
+
// 플레이어 그리기
|
480 |
+
ctx.save();
|
481 |
+
ctx.translate(player.x, player.y);
|
482 |
+
ctx.rotate(player.angle);
|
483 |
+
ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
|
484 |
+
ctx.restore();
|
485 |
+
|
486 |
+
// 체력바
|
487 |
+
drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
|
488 |
+
|
489 |
+
// 적 그리기
|
490 |
+
enemies.forEach(enemy => {
|
491 |
+
ctx.save();
|
492 |
+
ctx.translate(enemy.x, enemy.y);
|
493 |
+
ctx.rotate(enemy.angle);
|
494 |
+
const img = enemy.isBoss ? enemy.enemyImg : (enemy.enemyImg || enemyImg);
|
495 |
+
ctx.drawImage(img, -enemy.width/2, -enemy.height/2, enemy.width, enemy.height);
|
496 |
+
ctx.restore();
|
497 |
+
drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
|
498 |
+
});
|
499 |
+
|
500 |
+
// 총알 그리기
|
501 |
+
bullets.forEach(bullet => {
|
502 |
+
ctx.beginPath();
|
503 |
+
ctx.fillStyle = bullet.isEnemy ? 'red' : 'blue';
|
504 |
+
ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
|
505 |
+
ctx.fill();
|
506 |
+
});
|
507 |
+
|
508 |
+
// 아이템 그리기
|
509 |
+
items.forEach(item => {
|
510 |
+
ctx.beginPath();
|
511 |
+
ctx.fillStyle = 'green';
|
512 |
+
ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
|
513 |
+
ctx.fill();
|
514 |
+
});
|
515 |
+
|
516 |
+
// UI 그리기
|
517 |
ctx.fillStyle = 'white';
|
518 |
ctx.font = '24px Arial';
|
519 |
ctx.fillText(`Round ${currentRound}/10`, 10, 30);
|
520 |
ctx.fillText(`Gold: ${gold}`, 10, 60);
|
521 |
|
522 |
+
// 이펙트 그리기
|
523 |
effects = effects.filter(effect => !effect.isExpired());
|
524 |
effects.forEach(effect => {
|
525 |
ctx.save();
|
526 |
ctx.translate(effect.x, effect.y);
|
527 |
if(effect.type === 'fire') ctx.rotate(effect.angle);
|
528 |
+
ctx.drawImage(effect.img, -25, -25, 50, 50);
|
529 |
ctx.restore();
|
530 |
});
|
531 |
|
|
|
533 |
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
534 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
535 |
}
|
536 |
+
}
|
537 |
+
|
538 |
+
// drawGame 함수 밖으로 이동
|
539 |
function gameLoop() {
|
540 |
updateGame();
|
541 |
drawGame();
|
542 |
requestAnimationFrame(gameLoop);
|
543 |
}
|
544 |
+
|
545 |
nextRoundBtn.addEventListener('click', () => {
|
546 |
currentRound++;
|
547 |
nextRoundBtn.style.display = 'none';
|
548 |
+
document.getElementById('shop').style.display = 'none';
|
549 |
initRound();
|
550 |
});
|
551 |
+
|
552 |
bossButton.addEventListener('click', startBossStage);
|
553 |
+
|
554 |
restartBtn.addEventListener('click', () => {
|
555 |
currentRound = 1;
|
556 |
gameOver = false;
|
|
|
564 |
bgm.play();
|
565 |
initRound();
|
566 |
});
|
567 |
+
|
568 |
+
Promise.all([
|
569 |
+
new Promise(resolve => backgroundImg.onload = resolve),
|
570 |
+
new Promise(resolve => playerImg.onload = resolve),
|
571 |
+
new Promise(resolve => enemyImg.onload = resolve)
|
572 |
+
]).then(() => {
|
573 |
+
initRound();
|
574 |
+
gameLoop();
|
575 |
+
bgm.play();
|
576 |
+
});
|
577 |
+
|
578 |
+
window.addEventListener('resize', () => {
|
579 |
+
canvas.width = window.innerWidth;
|
580 |
+
canvas.height = window.innerHeight;
|
581 |
+
});
|
582 |
</script>
|
583 |
</body>
|
584 |
</html>
|