cutechicken commited on
Commit
ca81386
·
verified ·
1 Parent(s): a2229ab

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +182 -108
index.html CHANGED
@@ -917,131 +917,205 @@ document.addEventListener('keydown', e => {
917
  autoFire = !autoFire;
918
  }
919
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
 
921
- document.addEventListener('keyup', e => keys[e.key] = false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922
 
923
- // 마우스 이벤트 리스너
924
- canvas.addEventListener('mousemove', (e) => {
925
- player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
926
  });
927
 
928
- // 총알 발사 함수
929
- function fireBullet() {
930
- if(isCountingDown) return;
931
- const weapon = weapons[currentWeapon];
932
- const now = Date.now();
933
- if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
934
- weapon.sound.cloneNode().play();
935
- effects.push(new Effect(
936
- player.x + Math.cos(player.angle) * 30,
937
- player.y + Math.sin(player.angle) * 30,
938
- 500,
939
- 'fire',
940
- player.angle,
941
- player
942
- ));
943
 
944
- bullets.push({
945
- x: player.x + Math.cos(player.angle) * 30,
946
- y: player.y + Math.sin(player.angle) * 30,
947
- angle: player.angle,
948
- speed: hasAPCR ? 20 : 10,
949
- isEnemy: false,
950
- damage: weapon.damage,
951
- size: weapon.bulletSize,
952
- isAPCR: hasAPCR
953
- });
954
- lastShot = now;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  }
956
  }
957
 
958
- // 게임 렌더링 함수
959
- function drawGame() {
960
- ctx.clearRect(0, 0, canvas.width, canvas.height);
961
- const pattern = ctx.createPattern(backgroundImg, 'repeat');
962
- ctx.fillStyle = pattern;
963
- ctx.fillRect(0, 0, canvas.width, canvas.height);
964
-
965
- // 플레이어 그리기
966
- ctx.save();
967
- ctx.translate(player.x, player.y);
968
- ctx.rotate(player.angle);
969
- ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
970
- ctx.restore();
971
-
972
- // 체력바 그리기
973
- drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
974
-
975
- // 적 그리기
976
- enemies.forEach(enemy => {
977
- ctx.save();
978
- ctx.translate(enemy.x, enemy.y);
979
- ctx.rotate(enemy.angle);
980
- const img = enemy.isBoss ? enemy.enemyImg : (enemy.enemyImg || enemyImg);
981
- ctx.drawImage(img, -enemy.width/2, -enemy.height/2, enemy.width, enemy.height);
982
- ctx.restore();
983
- drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
984
- });
985
 
986
- // 지원 유닛 그리기
987
- supportUnits.forEach(unit => {
988
- ctx.save();
989
- ctx.translate(unit.x, unit.y);
990
- ctx.rotate(unit.angle);
991
- ctx.drawImage(unit.img, -unit.width/2, -unit.height/2, unit.width, unit.height);
992
- ctx.restore();
993
- });
994
 
995
- // 총알 그리기
996
- bullets.forEach(bullet => {
997
- if (bullet.isEnemy || !bullet.isAPCR) {
998
- ctx.beginPath();
999
- ctx.fillStyle = bullet.isEnemy ? 'red' : 'blue';
1000
- ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
1001
- ctx.fill();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  } else {
1003
- ctx.save();
1004
- ctx.translate(bullet.x, bullet.y);
1005
- ctx.rotate(bullet.angle);
1006
- const width = currentWeapon === 'machinegun' ? 10 : 20;
1007
- const height = currentWeapon === 'machinegun' ? 5 : 10;
1008
- ctx.drawImage(bulletImg, -width/2, -height/2, width, height);
1009
- ctx.restore();
 
 
 
 
1010
  }
 
 
 
1011
  });
1012
 
1013
- // 아이템 그리기
1014
- items.forEach(item => {
1015
- ctx.beginPath();
1016
- ctx.fillStyle = 'green';
1017
- ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
1018
- ctx.fill();
1019
- });
1020
-
1021
- // UI 그리기
1022
- ctx.fillStyle = 'white';
1023
- ctx.font = '24px Arial';
1024
- ctx.fillText(`Round ${currentRound}/10`, 10, 30);
1025
- ctx.fillText(`Gold: ${gold}`, 10, 60);
1026
-
1027
- // 이펙트 그리기
1028
- effects = effects.filter(effect => !effect.isExpired());
1029
- effects.forEach(effect => {
1030
- effect.update();
1031
- ctx.save();
1032
- ctx.translate(effect.x, effect.y);
1033
- if (effect.type === 'fire') ctx.rotate(effect.angle);
1034
- const size = effect.type === 'death' ? 75 : 42;
1035
- ctx.drawImage(effect.img, -size / 2, -size / 2, size, size);
1036
- ctx.restore();
1037
  });
1038
 
1039
- if (isCountingDown) {
1040
- ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
1041
- ctx.fillRect(0, 0, canvas.width, canvas.height);
 
 
 
 
 
 
 
 
 
 
 
 
 
1042
  }
1043
- }
 
1044
 
1045
  </script>
1046
  </body>
1047
- </html>
 
917
  autoFire = !autoFire;
918
  }
919
  });
920
+ nextRoundBtn.addEventListener('click', () => {
921
+ currentRound++;
922
+ nextRoundBtn.style.display = 'none';
923
+ document.getElementById('shop').style.display = 'none';
924
+ initRound();
925
+ });
926
+ bossButton.addEventListener('click', () => {
927
+ startBossStage();
928
+ });
929
+ restartBtn.addEventListener('click', () => {
930
+ location.reload();
931
+ });
932
+ function initRound() {
933
+ enemies = [];
934
+ for(let i = 0; i < 1 * currentRound; i++) {
935
+ enemies.push(new Enemy());
936
+ }
937
+ player.health = player.maxHealth;
938
+ bullets = [];
939
+ items = [];
940
+ supportUnits = [];
941
+ lastSupportSpawn = 0;
942
+ startCountdown();
943
 
944
+ setTimeout(() => {
945
+ if (hasJU87) {
946
+ supportUnits.push(new JU87());
947
+ lastJU87Spawn = Date.now();
948
+ }
949
+ }, 3000);
950
+ }
951
+ function startBossStage() {
952
+ isBossStage = true;
953
+ enemies = [];
954
+ enemies.push(new Enemy(true));
955
+ player.health = player.maxHealth;
956
+ bullets = [];
957
+ items = [];
958
+ document.getElementById('bossButton').style.display = 'none';
959
+ bgm.src = 'BGM.ogg';
960
+ bgm.play().catch(err => console.error("Error playing boss music:", err));
961
+ startCountdown();
962
+ }
963
+ function gameLoop() {
964
+ if (!gameOver) {
965
+ updateGame();
966
+ drawGame();
967
+ requestAnimationFrame(gameLoop);
968
+ }
969
+ }
970
+ document.addEventListener('DOMContentLoaded', () => {
971
+ const titleScreen = document.getElementById('titleScreen');
972
+ const startButton = document.getElementById('startButton');
973
+ const instructions = document.getElementById('instructions');
974
+ const weaponInfo = document.getElementById('weaponInfo');
975
+ const gameCanvas = document.getElementById('gameCanvas');
976
+ instructions.style.display = 'none';
977
+ weaponInfo.style.display = 'none';
978
+ gameCanvas.style.display = 'none';
979
+
980
+ console.log("DOM Loaded");
981
+
982
+ bgm.play().catch(err => console.error("Error playing title music:", err));
983
+
984
+ startButton.addEventListener('click', () => {
985
+ console.log("Start Button Clicked");
986
+ titleScreen.style.display = 'none';
987
+ instructions.style.display = 'block';
988
+ weaponInfo.style.display = 'block';
989
+ gameCanvas.style.display = 'block';
990
+
991
+ bgm.pause();
992
+ bgm = new Audio('BGM2.ogg');
993
+ bgm.loop = true;
994
+ bgm.play().catch(err => console.error("Error playing game music:", err));
995
 
996
+ currentRound = 1; // 라운드 초기화 추가
997
+ initRound();
998
+ gameLoop();
999
  });
1000
 
1001
+ Promise.all([
1002
+ new Promise(resolve => backgroundImg.onload = resolve),
1003
+ new Promise(resolve => playerImg.onload = resolve),
1004
+ new Promise(resolve => enemyImg.onload = resolve)
1005
+ ]).then(() => {
1006
+ console.log("Assets loaded successfully");
1007
+ }).catch(err => console.error("Error loading assets:", err));
 
 
 
 
 
 
 
 
1008
 
1009
+ window.addEventListener('resize', () => {
1010
+ canvas.width = window.innerWidth;
1011
+ canvas.height = window.innerHeight;
1012
+ });
1013
+ });
1014
+ function updateGame() {
1015
+ if(gameOver) return;
1016
+ if(!isCountingDown) {
1017
+ if(keys['w']) player.y -= player.speed;
1018
+ if(keys['s']) player.y += player.speed;
1019
+ if(keys['a']) player.x -= player.speed;
1020
+ if(keys['d']) player.x += player.speed;
1021
+
1022
+ player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
1023
+ player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
1024
+
1025
+ fireBullet();
1026
+ }
1027
+
1028
+ if (hasBF109 && !isCountingDown) {
1029
+ const now = Date.now();
1030
+ if (now - lastSupportSpawn > 10000) {
1031
+ supportUnits.push(
1032
+ new SupportUnit(canvas.height * 0.2),
1033
+ new SupportUnit(canvas.height * 0.5),
1034
+ new SupportUnit(canvas.height * 0.8)
1035
+ );
1036
+ lastSupportSpawn = now;
1037
  }
1038
  }
1039
 
1040
+ if (hasJU87 && !isCountingDown) {
1041
+ const now = Date.now();
1042
+ if (now - lastJU87Spawn > 15000) {
1043
+ supportUnits.push(new JU87());
1044
+ lastJU87Spawn = now;
1045
+ }
1046
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1047
 
1048
+ supportUnits = supportUnits.filter(unit => unit.update());
1049
+ enemies.forEach(enemy => enemy.update());
 
 
 
 
 
 
1050
 
1051
+ if(!isCountingDown) {
1052
+ bullets = bullets.filter(bullet => {
1053
+ bullet.x += Math.cos(bullet.angle) * bullet.speed;
1054
+ bullet.y += Math.sin(bullet.angle) * bullet.speed;
1055
+
1056
+ if(!bullet.isEnemy) {
1057
+ enemies = enemies.filter(enemy => {
1058
+ const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
1059
+ if(dist < 30) {
1060
+ enemy.health -= bullet.damage * (hasAPCR ? 2 : 1);
1061
+ if(enemy.health <= 0) {
1062
+ spawnHealthItem(enemy.x, enemy.y);
1063
+ gold += 100;
1064
+ effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
1065
+ deathSound.cloneNode().play();
1066
+ return false;
1067
+ }
1068
+ return true;
1069
+ }
1070
+ return true;
1071
+ });
1072
  } else {
1073
+ const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
1074
+ if(dist < 30) {
1075
+ player.health -= bullet.damage;
1076
+ if(player.health <= 0) {
1077
+ gameOver = true;
1078
+ restartBtn.style.display = 'block';
1079
+ effects.push(new Effect(player.x, player.y, 1000, 'death'));
1080
+ deathSound.cloneNode().play();
1081
+ }
1082
+ return false;
1083
+ }
1084
  }
1085
+
1086
+ return bullet.x >= 0 && bullet.x <= canvas.width &&
1087
+ bullet.y >= 0 && bullet.y <= canvas.height;
1088
  });
1089
 
1090
+ items = items.filter(item => {
1091
+ const dist = Math.hypot(item.x - player.x, item.y - player.y);
1092
+ if(dist < 30) {
1093
+ player.health = Math.min(player.health + 200, player.maxHealth);
1094
+ return false;
1095
+ }
1096
+ return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1097
  });
1098
 
1099
+ if(enemies.length === 0) {
1100
+ if (!isBossStage) {
1101
+ if(currentRound < 10) {
1102
+ nextRoundBtn.style.display = 'block';
1103
+ showShop();
1104
+ } else {
1105
+ bossButton.style.display = 'block';
1106
+ }
1107
+ } else {
1108
+ gameOver = true;
1109
+ document.getElementById('winMessage').style.display = 'block';
1110
+ restartBtn.style.display = 'block';
1111
+ bgm.pause();
1112
+ const victorySound = new Audio('victory.ogg');
1113
+ victorySound.play();
1114
+ }
1115
  }
1116
+ }
1117
+ }
1118
 
1119
  </script>
1120
  </body>
1121
+ </html>