Spaces:
Running
Running
Update index.html
Browse files- index.html +630 -625
index.html
CHANGED
@@ -48,33 +48,40 @@
|
|
48 |
display: none;
|
49 |
z-index: 1000;
|
50 |
}
|
51 |
-
#
|
52 |
position: fixed;
|
53 |
-
top:
|
54 |
-
left:
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
font-size: 72px;
|
57 |
color: white;
|
58 |
-
text-shadow: 2px 2px
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
}
|
62 |
-
#winMessage {
|
63 |
-
font-size: 72px;
|
64 |
-
background: none;
|
65 |
-
top: 30%; /* 화면의 위쪽으로 이동 */
|
66 |
-
left: 50%;
|
67 |
-
transform: translate(-50%, -50%);
|
68 |
-
z-index: 1001; /* 다음 라운드 버튼보다 위로 설정 */
|
69 |
-
}
|
70 |
-
|
71 |
-
#nextRound {
|
72 |
-
top: 80%; /* 화면의 아래쪽으로 이동 */
|
73 |
-
z-index: 1000; /* "You Win"보다 아래로 설정 */
|
74 |
-
}
|
75 |
-
#nextRound {
|
76 |
-
top: 80%; /* 아래쪽으로 이동 */
|
77 |
-
}
|
78 |
</style>
|
79 |
</head>
|
80 |
<body>
|
@@ -91,8 +98,18 @@
|
|
91 |
<button id="nextRound" class="button">Next Round</button>
|
92 |
<button id="restart" class="button">Restart Game</button>
|
93 |
<canvas id="gameCanvas"></canvas>
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
<h2>Tank Shop</h2>
|
97 |
<div style="display:flex; gap:20px;">
|
98 |
<div id="tank1" style="text-align:center;">
|
@@ -110,415 +127,187 @@
|
|
110 |
<p style="color: #ff6b6b;">-30% Speed</p>
|
111 |
<button onclick="buyTank('player3.png', 500, 'tank2')">Buy</button>
|
112 |
</div>
|
113 |
-
|
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 |
-
|
121 |
<h3>JU-87</h3>
|
122 |
<img src="ju87.png" width="100" height="100">
|
123 |
<p>1500 Gold</p>
|
124 |
<p style="color: #4CAF50;">Get ju-87 air support</p>
|
125 |
<button onclick="buyJU87()">Buy</button>
|
126 |
</div>
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
</div>
|
135 |
</div>
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
speed: 5,
|
207 |
-
angle: 0,
|
208 |
-
width: 100,
|
209 |
-
height: 45,
|
210 |
-
health: 1000,
|
211 |
-
maxHealth: 1000
|
212 |
-
};
|
213 |
-
function startCountdown() {
|
214 |
-
isCountingDown = true;
|
215 |
-
countdownTime = 3;
|
216 |
-
countdownEl.style.display = 'block';
|
217 |
-
countdownEl.textContent = countdownTime;
|
218 |
-
bgm.pause();
|
219 |
-
countSound.play();
|
220 |
-
const countInterval = setInterval(() => {
|
221 |
-
countdownTime--;
|
222 |
-
if(countdownTime <= 0) {
|
223 |
-
clearInterval(countInterval);
|
224 |
-
countdownEl.style.display = 'none';
|
225 |
-
isCountingDown = false;
|
226 |
-
bgm.play();
|
227 |
-
}
|
228 |
-
countdownEl.textContent = countdownTime > 0 ? countdownTime : 'GO!';
|
229 |
-
}, 1000);
|
230 |
-
}
|
231 |
-
|
232 |
-
class Effect {
|
233 |
-
constructor(x, y, duration, type, angle = 0, parent = null) {
|
234 |
-
this.x = x;
|
235 |
-
this.y = y;
|
236 |
-
this.startTime = Date.now();
|
237 |
-
this.duration = duration;
|
238 |
-
this.type = type;
|
239 |
-
this.angle = angle;
|
240 |
-
this.parent = parent; // 부모 유닛 (발사한 유닛)
|
241 |
-
this.offset = { x: Math.cos(angle) * 30, y: Math.sin(angle) * 30 }; // 부모로부터의 오프셋
|
242 |
-
this.img = new Image();
|
243 |
-
this.img.src = type === 'death' ? 'bang.png' : 'fire2.png';
|
244 |
}
|
|
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
}
|
257 |
}
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
// 이동
|
275 |
-
this.x += this.speed;
|
276 |
-
|
277 |
-
// 카운트다운 중이면 소리 정지 및 초기화
|
278 |
-
if (isCountingDown) {
|
279 |
-
if (this.mgSound) {
|
280 |
-
this.mgSound.pause();
|
281 |
-
this.mgSound.currentTime = 0;
|
282 |
-
}
|
283 |
-
this.hasPlayedSound = false;
|
284 |
}
|
|
|
|
|
|
|
285 |
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
this.lastShot = now;
|
291 |
-
}
|
292 |
-
return this.x < canvas.width;
|
293 |
}
|
|
|
|
|
|
|
|
|
|
|
294 |
|
295 |
-
|
296 |
-
// 최초 등장시에만 bf109mg.ogg 재생
|
297 |
-
if (!this.hasPlayedSound) {
|
298 |
-
const firstSound = new Audio('bf109mg.ogg');
|
299 |
-
firstSound.volume = 1.0;
|
300 |
-
firstSound.play();
|
301 |
-
this.hasPlayedSound = true;
|
302 |
-
}
|
303 |
|
304 |
-
|
305 |
-
if (
|
306 |
-
|
307 |
-
|
308 |
-
shootSound.play();
|
309 |
}
|
310 |
-
|
311 |
-
bullets.push({
|
312 |
-
x: this.x + Math.cos(this.angle) * 30,
|
313 |
-
y: this.y + Math.sin(this.angle) * 30,
|
314 |
-
angle: this.angle,
|
315 |
-
speed: 10,
|
316 |
-
isEnemy: false,
|
317 |
-
damage: weapons.machinegun.damage,
|
318 |
-
size: weapons.machinegun.bulletSize
|
319 |
-
});
|
320 |
-
}
|
321 |
}
|
322 |
-
class JU87 {
|
323 |
-
constructor() {
|
324 |
-
this.x = canvas.width;
|
325 |
-
this.y = 50;
|
326 |
-
this.speed = 5;
|
327 |
-
this.width = 100;
|
328 |
-
this.height = 100;
|
329 |
-
this.angle = Math.PI;
|
330 |
-
this.img = new Image();
|
331 |
-
this.img.src = 'ju87.png';
|
332 |
-
this.target = null;
|
333 |
-
this.lastShot = 0;
|
334 |
-
this.spawnTime = Date.now();
|
335 |
-
this.hasPlayedSound = false;
|
336 |
-
this.hasPlayedMGSound = false;
|
337 |
-
this.isReturning = false;
|
338 |
-
this.circleAngle = 0;
|
339 |
-
this.returningToCenter = false; // 중앙으로 돌아가는 상태 추가
|
340 |
-
}
|
341 |
-
|
342 |
-
selectTarget() {
|
343 |
-
return enemies.length > 0 ?
|
344 |
-
enemies[Math.floor(Math.random() * enemies.length)] : null;
|
345 |
-
}
|
346 |
-
|
347 |
-
shoot() {
|
348 |
-
// 카운트다운 중이 아닐 때만 소리 재생
|
349 |
-
if (!this.hasPlayedMGSound && !isCountingDown) {
|
350 |
-
const mgSound = new Audio('ju87mg.ogg');
|
351 |
-
mgSound.volume = 1.0;
|
352 |
-
mgSound.currentTime = 0;
|
353 |
-
mgSound.play().catch(error => console.error('Audio play failed:', error));
|
354 |
-
this.hasPlayedMGSound = true;
|
355 |
-
}
|
356 |
-
|
357 |
-
// 100x100 픽셀 기준으로 날개 위치 좌표 설정
|
358 |
-
[[20, 50], [80, 50]].forEach(([x, y]) => {
|
359 |
-
const offsetX = x - 50;
|
360 |
-
const offsetY = y - 50;
|
361 |
-
|
362 |
-
const rotatedX = this.x + (Math.cos(this.angle) * offsetX - Math.sin(this.angle) * offsetY);
|
363 |
-
const rotatedY = this.y + (Math.sin(this.angle) * offsetX + Math.cos(this.angle) * offsetY);
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
angle: this.angle,
|
369 |
-
speed: 10,
|
370 |
-
isEnemy: false,
|
371 |
-
damage: weapons.machinegun.damage * 2,
|
372 |
-
size: weapons.machinegun.bulletSize
|
373 |
-
});
|
374 |
-
});
|
375 |
}
|
376 |
-
update() {
|
377 |
-
if (!this.hasPlayedSound) {
|
378 |
-
const sirenSound = new Audio('ju87siren.ogg');
|
379 |
-
sirenSound.volume = 1.0;
|
380 |
-
sirenSound.play().catch(error => console.error('Audio play failed:', error));
|
381 |
-
this.hasPlayedSound = true;
|
382 |
-
}
|
383 |
|
384 |
-
const timeSinceSpawn = Date.now() - this.spawnTime;
|
385 |
-
const centerX = canvas.width / 2;
|
386 |
-
const centerY = canvas.height / 2;
|
387 |
-
|
388 |
-
if (timeSinceSpawn > 5000) {
|
389 |
-
if (!this.isReturning) {
|
390 |
-
this.isReturning = true;
|
391 |
-
this.target = null;
|
392 |
-
this.angle = Math.atan2(centerY - this.y, centerX - this.x);
|
393 |
-
} else {
|
394 |
-
this.angle = Math.PI;
|
395 |
-
this.x -= this.speed;
|
396 |
-
return this.x > 0;
|
397 |
-
}
|
398 |
-
} else if (this.returningToCenter) {
|
399 |
-
const distToCenter = Math.hypot(this.x - centerX, this.y - centerY);
|
400 |
-
if (distToCenter > 50) {
|
401 |
-
this.angle = Math.atan2(centerY - this.y, centerX - this.x);
|
402 |
-
} else {
|
403 |
-
this.returningToCenter = false;
|
404 |
-
this.target = this.selectTarget();
|
405 |
-
}
|
406 |
-
} else if (this.target) {
|
407 |
-
const distToTarget = Math.hypot(this.x - this.target.x, this.y - this.target.y);
|
408 |
-
|
409 |
-
if (!enemies.includes(this.target) || distToTarget < 30) {
|
410 |
-
this.returningToCenter = true;
|
411 |
-
this.target = null;
|
412 |
-
} else {
|
413 |
-
this.angle = Math.atan2(this.target.y - this.y, this.target.x - this.x);
|
414 |
-
}
|
415 |
-
} else {
|
416 |
-
this.target = this.selectTarget();
|
417 |
-
|
418 |
-
if (!this.target) {
|
419 |
-
this.circleAngle += 0.02;
|
420 |
-
const radius = Math.min(canvas.width, canvas.height) / 4;
|
421 |
-
const targetX = centerX + Math.cos(this.circleAngle) * radius;
|
422 |
-
const targetY = centerY + Math.sin(this.circleAngle) * radius;
|
423 |
-
this.angle = Math.atan2(targetY - this.y, targetX - this.x);
|
424 |
-
}
|
425 |
-
}
|
426 |
-
|
427 |
-
this.x += Math.cos(this.angle) * this.speed;
|
428 |
-
this.y += Math.sin(this.angle) * this.speed;
|
429 |
-
|
430 |
-
if (!this.returningToCenter && !this.isReturning && this.target &&
|
431 |
-
Date.now() - this.lastShot > 200) {
|
432 |
-
this.shoot();
|
433 |
-
this.lastShot = Date.now();
|
434 |
-
}
|
435 |
-
|
436 |
-
return true;
|
437 |
-
}
|
438 |
-
}
|
439 |
-
|
440 |
-
class Enemy {
|
441 |
-
constructor(isBoss = false) {
|
442 |
-
this.x = Math.random() * canvas.width;
|
443 |
-
this.y = Math.random() * canvas.height;
|
444 |
-
this.health = isBoss ? 15000 : 1000;
|
445 |
-
this.maxHealth = this.health;
|
446 |
-
this.speed = isBoss ? 1 : 2;
|
447 |
-
this.lastShot = 0;
|
448 |
-
this.shootInterval = isBoss ? 1000 : 1000;
|
449 |
-
this.angle = 0;
|
450 |
-
this.width = 100;
|
451 |
-
this.height = 45;
|
452 |
-
this.moveTimer = 0;
|
453 |
-
this.moveInterval = Math.random() * 2000 + 1000;
|
454 |
-
this.moveAngle = Math.random() * Math.PI * 2;
|
455 |
-
this.isBoss = isBoss;
|
456 |
-
|
457 |
-
if (isBoss) {
|
458 |
-
this.enemyImg = new Image();
|
459 |
-
this.enemyImg.src = 'boss.png';
|
460 |
-
} else if (currentRound >= 7) {
|
461 |
-
this.enemyImg = new Image();
|
462 |
-
this.enemyImg.src = 'enemy3.png';
|
463 |
-
} else if (currentRound >= 4) {
|
464 |
-
this.enemyImg = new Image();
|
465 |
-
this.enemyImg.src = 'enemy2.png';
|
466 |
-
}
|
467 |
-
}
|
468 |
-
update() {
|
469 |
-
if(isCountingDown) return;
|
470 |
-
const now = Date.now();
|
471 |
-
|
472 |
-
if (now - this.moveTimer > this.moveInterval) {
|
473 |
-
this.moveAngle = Math.random() * Math.PI * 2;
|
474 |
-
this.moveTimer = now;
|
475 |
-
}
|
476 |
-
this.x += Math.cos(this.moveAngle) * this.speed;
|
477 |
-
this.y += Math.sin(this.moveAngle) * this.speed;
|
478 |
-
this.x = Math.max(this.width/2, Math.min(canvas.width - this.width/2, this.x));
|
479 |
-
this.y = Math.max(this.height/2, Math.min(canvas.height - this.height/2, this.y));
|
480 |
-
this.angle = Math.atan2(player.y - this.y, player.x - this.x);
|
481 |
-
|
482 |
-
if (now - this.lastShot > this.shootInterval && !isCountingDown) {
|
483 |
-
this.shoot();
|
484 |
-
this.lastShot = now;
|
485 |
-
}
|
486 |
-
}
|
487 |
-
shoot() {
|
488 |
-
const sound = this.isBoss ? new Audio('firemn.ogg') : enemyFireSound.cloneNode();
|
489 |
-
sound.play();
|
490 |
-
|
491 |
-
// 발사 이펙트 추가
|
492 |
-
effects.push(new Effect(
|
493 |
-
this.x + Math.cos(this.angle) * 30,
|
494 |
-
this.y + Math.sin(this.angle) * 30,
|
495 |
-
500,
|
496 |
-
'fire',
|
497 |
-
this.angle,
|
498 |
-
this // 자신을 부모로 전달
|
499 |
-
));
|
500 |
-
|
501 |
-
bullets.push({
|
502 |
-
x: this.x + Math.cos(this.angle) * 30,
|
503 |
-
y: this.y + Math.sin(this.angle) * 30,
|
504 |
-
angle: this.angle,
|
505 |
-
speed: this.isBoss ? 10 : 5,
|
506 |
-
isEnemy: true,
|
507 |
-
size: this.isBoss ? 5 : 3,
|
508 |
-
damage: this.isBoss ? 300 : 150
|
509 |
-
});
|
510 |
-
}
|
511 |
-
}
|
512 |
-
function showShop() {
|
513 |
-
document.getElementById('shop').style.display = 'block';
|
514 |
-
}
|
515 |
-
// 플레이어의 기본 상태를 저장
|
516 |
const defaultPlayerStats = {
|
517 |
maxHealth: 1000,
|
518 |
speed: 5,
|
519 |
width: 100,
|
520 |
height: 45
|
521 |
};
|
|
|
522 |
function buyTank(tankImg, cost, tankId) {
|
523 |
if (gold >= cost) {
|
524 |
gold -= cost;
|
@@ -526,23 +315,22 @@ function buyTank(tankImg, cost, tankId) {
|
|
526 |
document.getElementById(tankId).style.display = 'none';
|
527 |
document.getElementById('shop').style.display = 'none';
|
528 |
|
529 |
-
if (tankId === 'tank1') {
|
530 |
player.maxHealth = 1500;
|
531 |
-
player.speed = defaultPlayerStats.speed;
|
532 |
-
player.width = 90;
|
533 |
-
player.height = 50;
|
534 |
-
}
|
535 |
-
else if (tankId === 'tank2') { // TIGER
|
536 |
player.maxHealth = 2000;
|
537 |
player.speed = defaultPlayerStats.speed * 0.7;
|
538 |
-
player.width = 100;
|
539 |
-
player.height = 45;
|
540 |
}
|
541 |
-
|
542 |
player.health = player.maxHealth;
|
543 |
}
|
544 |
}
|
545 |
-
|
|
|
546 |
if (gold >= 1000 && !hasAPCR) {
|
547 |
gold -= 1000;
|
548 |
hasAPCR = true;
|
@@ -550,7 +338,8 @@ function buyTank(tankImg, cost, tankId) {
|
|
550 |
document.getElementById('shop').style.display = 'none';
|
551 |
}
|
552 |
}
|
553 |
-
|
|
|
554 |
if (gold >= 1000 && !hasBF109) {
|
555 |
gold -= 1000;
|
556 |
hasBF109 = true;
|
@@ -558,92 +347,18 @@ function buyTank(tankImg, cost, tankId) {
|
|
558 |
document.getElementById('shop').style.display = 'none';
|
559 |
}
|
560 |
}
|
561 |
-
|
|
|
562 |
if (gold >= 1500 && !hasJU87) {
|
563 |
gold -= 1500;
|
564 |
hasJU87 = true;
|
565 |
document.getElementById('ju87').style.display = 'none';
|
566 |
document.getElementById('shop').style.display = 'none';
|
567 |
-
lastJU87Spawn = Date.now();
|
568 |
}
|
569 |
}
|
570 |
-
|
571 |
-
|
572 |
-
for(let i = 0; i < 1 * currentRound; i++) {
|
573 |
-
enemies.push(new Enemy());
|
574 |
-
}
|
575 |
-
player.health = player.maxHealth;
|
576 |
-
bullets = [];
|
577 |
-
items = [];
|
578 |
-
supportUnits = [];
|
579 |
-
lastSupportSpawn = 0;
|
580 |
-
|
581 |
-
// 카운트다운 시작
|
582 |
-
startCountdown();
|
583 |
-
|
584 |
-
// 카운트다운이 끝나면 JU87 스폰
|
585 |
-
setTimeout(() => {
|
586 |
-
if (hasJU87) {
|
587 |
-
supportUnits.push(new JU87());
|
588 |
-
lastJU87Spawn = Date.now();
|
589 |
-
}
|
590 |
-
}, 3000); // 3초 후에 스폰
|
591 |
-
}
|
592 |
-
function startBossStage() {
|
593 |
-
isBossStage = true;
|
594 |
-
enemies = [];
|
595 |
-
enemies.push(new Enemy(true));
|
596 |
-
player.health = player.maxHealth;
|
597 |
-
bullets = [];
|
598 |
-
items = [];
|
599 |
-
document.getElementById('bossButton').style.display = 'none';
|
600 |
-
bgm.src = 'BGM.ogg'; // 보스전 BGM으로 변경
|
601 |
-
startCountdown();
|
602 |
-
}
|
603 |
-
canvas.addEventListener('mousemove', (e) => {
|
604 |
-
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
605 |
-
});
|
606 |
-
const keys = {};
|
607 |
-
document.addEventListener('keydown', e => {
|
608 |
-
keys[e.key] = true;
|
609 |
-
if(e.key.toLowerCase() === 'c') {
|
610 |
-
currentWeapon = currentWeapon === 'cannon' ? 'machinegun' : 'cannon';
|
611 |
-
weaponInfo.textContent = `Current Weapon: ${currentWeapon.charAt(0).toUpperCase() + currentWeapon.slice(1)}`;
|
612 |
-
} else if(e.key.toLowerCase() === 'r') {
|
613 |
-
autoFire = !autoFire;
|
614 |
-
}
|
615 |
-
});
|
616 |
-
|
617 |
-
document.addEventListener('keyup', e => keys[e.key] = false);
|
618 |
-
function fireBullet() {
|
619 |
-
if(isCountingDown) return;
|
620 |
-
const weapon = weapons[currentWeapon];
|
621 |
-
const now = Date.now();
|
622 |
-
if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
|
623 |
-
weapon.sound.cloneNode().play();
|
624 |
-
effects.push(new Effect(
|
625 |
-
player.x + Math.cos(player.angle) * 30,
|
626 |
-
player.y + Math.sin(player.angle) * 30,
|
627 |
-
500,
|
628 |
-
'fire',
|
629 |
-
player.angle,
|
630 |
-
player
|
631 |
-
));
|
632 |
-
|
633 |
-
bullets.push({
|
634 |
-
x: player.x + Math.cos(player.angle) * 30,
|
635 |
-
y: player.y + Math.sin(player.angle) * 30,
|
636 |
-
angle: player.angle,
|
637 |
-
speed: hasAPCR ? 20 : 10, // APCR 적용 시 100% 증가
|
638 |
-
isEnemy: false,
|
639 |
-
damage: weapon.damage,
|
640 |
-
size: weapon.bulletSize,
|
641 |
-
isAPCR: hasAPCR
|
642 |
-
});
|
643 |
-
lastShot = now;
|
644 |
-
}
|
645 |
-
}
|
646 |
-
function updateGame() {
|
647 |
if(gameOver) return;
|
648 |
if(!isCountingDown) {
|
649 |
// 플레이어 움직임
|
@@ -651,15 +366,17 @@ function buyTank(tankImg, cost, tankId) {
|
|
651 |
if(keys['s']) player.y += player.speed;
|
652 |
if(keys['a']) player.x -= player.speed;
|
653 |
if(keys['d']) player.x += player.speed;
|
|
|
654 |
player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
|
655 |
player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
|
|
|
656 |
fireBullet();
|
657 |
}
|
658 |
|
659 |
-
// BF109
|
660 |
if (hasBF109 && !isCountingDown) {
|
661 |
const now = Date.now();
|
662 |
-
if (now - lastSupportSpawn > 10000) {
|
663 |
supportUnits.push(
|
664 |
new SupportUnit(canvas.height * 0.2),
|
665 |
new SupportUnit(canvas.height * 0.5),
|
@@ -669,100 +386,95 @@ function buyTank(tankImg, cost, tankId) {
|
|
669 |
}
|
670 |
}
|
671 |
|
672 |
-
// JU87
|
673 |
if (hasJU87 && !isCountingDown) {
|
674 |
const now = Date.now();
|
675 |
-
if (now - lastJU87Spawn > 15000) {
|
676 |
supportUnits.push(new JU87());
|
677 |
lastJU87Spawn = now;
|
678 |
}
|
679 |
}
|
680 |
|
681 |
-
//
|
682 |
supportUnits = supportUnits.filter(unit => unit.update());
|
683 |
|
|
|
684 |
enemies.forEach(enemy => enemy.update());
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
}
|
703 |
-
if(player.health <= 0) {
|
704 |
-
gameOver = true;
|
705 |
-
restartBtn.style.display = 'block';
|
706 |
-
effects.push(new Effect(player.x, player.y, 1000, 'death'));
|
707 |
-
deathSound.cloneNode().play();
|
708 |
-
}
|
709 |
-
return true;
|
710 |
-
}
|
711 |
-
return true;
|
712 |
-
});
|
713 |
-
} else {
|
714 |
-
const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
|
715 |
-
if(dist < 30) {
|
716 |
-
player.health -= bullet.damage || 100;
|
717 |
-
if(player.health <= 0) {
|
718 |
-
gameOver = true;
|
719 |
-
restartBtn.style.display = 'block';
|
720 |
-
}
|
721 |
return false;
|
722 |
}
|
723 |
-
|
724 |
-
return bullet.x >= 0 && bullet.x <= canvas.width &&
|
725 |
-
bullet.y >= 0 && bullet.y <= canvas.height;
|
726 |
-
});
|
727 |
-
items = items.filter(item => {
|
728 |
-
const dist = Math.hypot(item.x - player.x, item.y - player.y);
|
729 |
-
if(dist < 30) {
|
730 |
-
player.health = Math.min(player.health + 200, player.maxHealth);
|
731 |
-
return false;
|
732 |
}
|
733 |
return true;
|
734 |
});
|
735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
if (!isBossStage) {
|
737 |
if(currentRound < 10) {
|
738 |
nextRoundBtn.style.display = 'block';
|
739 |
showShop();
|
740 |
} else {
|
741 |
-
|
742 |
}
|
743 |
} else {
|
744 |
gameOver = true;
|
745 |
document.getElementById('winMessage').style.display = 'block';
|
746 |
restartBtn.style.display = 'block';
|
747 |
-
bgm.pause();
|
748 |
-
const victorySound = new Audio('victory.ogg');
|
749 |
-
victorySound.play();
|
750 |
}
|
751 |
}
|
752 |
}
|
753 |
-
enemies.forEach(enemy => enemy.update());
|
754 |
}
|
755 |
-
|
756 |
-
|
757 |
-
}
|
758 |
-
function drawHealthBar(x, y, health, maxHealth, width, height, color) {
|
759 |
-
ctx.fillStyle = '#333';
|
760 |
-
ctx.fillRect(x - width/2, y - height/2, width, height);
|
761 |
-
ctx.fillStyle = color;
|
762 |
-
ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
|
763 |
-
}
|
764 |
-
function drawGame() {
|
765 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
766 |
const pattern = ctx.createPattern(backgroundImg, 'repeat');
|
767 |
ctx.fillStyle = pattern;
|
768 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
@@ -774,7 +486,7 @@ function buyTank(tankImg, cost, tankId) {
|
|
774 |
ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
|
775 |
ctx.restore();
|
776 |
|
777 |
-
// 체력바
|
778 |
drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
|
779 |
|
780 |
// 적 그리기
|
@@ -787,31 +499,34 @@ function buyTank(tankImg, cost, tankId) {
|
|
787 |
ctx.restore();
|
788 |
drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
|
789 |
});
|
790 |
-
|
|
|
|
|
791 |
ctx.save();
|
792 |
ctx.translate(unit.x, unit.y);
|
793 |
ctx.rotate(unit.angle);
|
794 |
ctx.drawImage(unit.img, -unit.width/2, -unit.height/2, unit.width, unit.height);
|
795 |
ctx.restore();
|
796 |
});
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
|
|
815 |
// 아이템 그리기
|
816 |
items.forEach(item => {
|
817 |
ctx.beginPath();
|
@@ -819,7 +534,7 @@ function buyTank(tankImg, cost, tankId) {
|
|
819 |
ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
|
820 |
ctx.fill();
|
821 |
});
|
822 |
-
|
823 |
// UI 그리기
|
824 |
ctx.fillStyle = 'white';
|
825 |
ctx.font = '24px Arial';
|
@@ -827,31 +542,34 @@ function buyTank(tankImg, cost, tankId) {
|
|
827 |
ctx.fillText(`Gold: ${gold}`, 10, 60);
|
828 |
|
829 |
// 이펙트 그리기
|
830 |
-
effects = effects.filter(effect => !effect.isExpired());
|
831 |
-
effects.forEach(effect => {
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
});
|
841 |
|
842 |
-
|
|
|
843 |
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
844 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
845 |
}
|
846 |
}
|
847 |
|
848 |
-
//
|
849 |
function gameLoop() {
|
850 |
-
|
851 |
-
|
852 |
-
|
|
|
|
|
853 |
}
|
854 |
|
|
|
855 |
nextRoundBtn.addEventListener('click', () => {
|
856 |
currentRound++;
|
857 |
nextRoundBtn.style.display = 'none';
|
@@ -859,45 +577,332 @@ nextRoundBtn.addEventListener('click', () => {
|
|
859 |
initRound();
|
860 |
});
|
861 |
|
862 |
-
bossButton.addEventListener('click', startBossStage);
|
863 |
-
|
864 |
restartBtn.addEventListener('click', () => {
|
865 |
-
|
866 |
-
gameOver = false;
|
867 |
-
isBossStage = false;
|
868 |
-
gold = 0;
|
869 |
-
hasAPCR = false; // APCR 초기화
|
870 |
-
hasBF109 = false; // BF109 초기화
|
871 |
-
hasJU87 = false;
|
872 |
-
supportUnits = []; // 지원 유닛 배열 초기화
|
873 |
-
|
874 |
-
restartBtn.style.display = 'none';
|
875 |
-
document.getElementById('winMessage').style.display = 'none';
|
876 |
-
document.getElementById('tank1').style.display = 'block';
|
877 |
-
document.getElementById('tank2').style.display = 'block';
|
878 |
-
document.getElementById('apcr').style.display = 'block';
|
879 |
-
document.getElementById('bf109').style.display = 'block'; // BF109 상점 아이템 다시 표시
|
880 |
-
|
881 |
-
playerImg.src = 'player.png';
|
882 |
-
bgm.src = 'BGM2.ogg';
|
883 |
-
bgm.play();
|
884 |
-
initRound();
|
885 |
});
|
886 |
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
|
|
|
|
895 |
});
|
896 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
897 |
window.addEventListener('resize', () => {
|
898 |
canvas.width = window.innerWidth;
|
899 |
canvas.height = window.innerHeight;
|
900 |
});
|
901 |
-
|
902 |
-
|
903 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
display: none;
|
49 |
z-index: 1000;
|
50 |
}
|
51 |
+
#titleScreen {
|
52 |
position: fixed;
|
53 |
+
top: 0;
|
54 |
+
left: 0;
|
55 |
+
width: 100%;
|
56 |
+
height: 100%;
|
57 |
+
background: url('city2.png') no-repeat center center;
|
58 |
+
background-size: cover;
|
59 |
+
z-index: 2000;
|
60 |
+
display: flex;
|
61 |
+
flex-direction: column;
|
62 |
+
justify-content: center;
|
63 |
+
align-items: center;
|
64 |
+
}
|
65 |
+
#titleScreen h1 {
|
66 |
font-size: 72px;
|
67 |
color: white;
|
68 |
+
text-shadow: 2px 2px 5px black;
|
69 |
+
margin-bottom: 50px;
|
70 |
+
}
|
71 |
+
.stageButton {
|
72 |
+
padding: 15px 30px;
|
73 |
+
font-size: 24px;
|
74 |
+
background: #4CAF50;
|
75 |
+
color: white;
|
76 |
+
border: none;
|
77 |
+
border-radius: 5px;
|
78 |
+
cursor: pointer;
|
79 |
+
margin: 10px;
|
80 |
+
}
|
81 |
+
.stageButton:disabled {
|
82 |
+
background: #666;
|
83 |
+
cursor: not-allowed;
|
84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
</style>
|
86 |
</head>
|
87 |
<body>
|
|
|
98 |
<button id="nextRound" class="button">Next Round</button>
|
99 |
<button id="restart" class="button">Restart Game</button>
|
100 |
<canvas id="gameCanvas"></canvas>
|
101 |
+
<div id="titleScreen">
|
102 |
+
<h1>TANK WAR</h1>
|
103 |
+
<div id="stageSelect">
|
104 |
+
<button class="stageButton" onclick="startStage(1)">Stage 1</button>
|
105 |
+
<button class="stageButton" disabled>Stage 2</button>
|
106 |
+
<button class="stageButton" disabled>Stage 3</button>
|
107 |
+
<button class="stageButton" disabled>Stage 4</button>
|
108 |
+
</div>
|
109 |
+
</div>
|
110 |
+
</body>
|
111 |
+
</html>
|
112 |
+
<div id="shop" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); background:rgba(0,0,0,0.9); padding:20px; border-radius:10px; color:white; z-index:1000;">
|
113 |
<h2>Tank Shop</h2>
|
114 |
<div style="display:flex; gap:20px;">
|
115 |
<div id="tank1" style="text-align:center;">
|
|
|
127 |
<p style="color: #ff6b6b;">-30% Speed</p>
|
128 |
<button onclick="buyTank('player3.png', 500, 'tank2')">Buy</button>
|
129 |
</div>
|
130 |
+
<div id="bf109" style="text-align:center;">
|
131 |
<h3>BF-109</h3>
|
132 |
<img src="bf109.png" width="100" height="100">
|
133 |
<p>1000 Gold</p>
|
134 |
<p style="color: #4CAF50;">Air support from BF-109</p>
|
135 |
<button onclick="buyBF109()">Buy</button>
|
136 |
</div>
|
137 |
+
<div id="ju87" style="text-align:center;">
|
138 |
<h3>JU-87</h3>
|
139 |
<img src="ju87.png" width="100" height="100">
|
140 |
<p>1500 Gold</p>
|
141 |
<p style="color: #4CAF50;">Get ju-87 air support</p>
|
142 |
<button onclick="buyJU87()">Buy</button>
|
143 |
</div>
|
144 |
+
<div id="apcr" style="text-align:center;">
|
145 |
+
<h3>APCR</h3>
|
146 |
+
<img src="apcr.png" width="80" height="20">
|
147 |
+
<p>1000 Gold</p>
|
148 |
+
<p style="color: #4CAF50;">+100% Bullet Speed</p>
|
149 |
+
<button onclick="buyAPCR()">Buy</button>
|
150 |
+
</div>
|
151 |
</div>
|
152 |
</div>
|
153 |
+
<button id="bossButton" class="button">Fight Boss!</button>
|
154 |
+
<div id="winMessage" class="button" style="font-size: 72px; background: none;">You Win!</div>
|
155 |
+
const canvas = document.getElementById('gameCanvas');
|
156 |
+
const ctx = canvas.getContext('2d');
|
157 |
+
const nextRoundBtn = document.getElementById('nextRound');
|
158 |
+
const restartBtn = document.getElementById('restart');
|
159 |
+
const weaponInfo = document.getElementById('weaponInfo');
|
160 |
+
const countdownEl = document.getElementById('countdown');
|
161 |
+
const bossButton = document.getElementById('bossButton');
|
162 |
+
|
163 |
+
canvas.width = window.innerWidth;
|
164 |
+
canvas.height = window.innerHeight;
|
165 |
+
|
166 |
+
// Game state
|
167 |
+
let currentRound = 1;
|
168 |
+
let gameOver = false;
|
169 |
+
let currentWeapon = 'cannon';
|
170 |
+
let enemies = [];
|
171 |
+
let bullets = [];
|
172 |
+
let items = [];
|
173 |
+
let lastShot = 0;
|
174 |
+
let isCountingDown = true;
|
175 |
+
let countdownTime = 3;
|
176 |
+
let autoFire = false;
|
177 |
+
let gold = 0;
|
178 |
+
let isBossStage = false;
|
179 |
+
let effects = [];
|
180 |
+
let hasAPCR = false;
|
181 |
+
let hasBF109 = false;
|
182 |
+
let hasJU87 = false;
|
183 |
+
let lastJU87Spawn = 0;
|
184 |
+
let supportUnits = [];
|
185 |
+
let lastSupportSpawn = 0;
|
186 |
+
let gameStarted = false; // 게임 시작 상태를 추적하는 새로운 변수
|
187 |
+
|
188 |
+
// Load assets
|
189 |
+
const backgroundImg = new Image();
|
190 |
+
backgroundImg.src = 'city.png';
|
191 |
+
const titleBackgroundImg = new Image();
|
192 |
+
titleBackgroundImg.src = 'city2.png';
|
193 |
+
const playerImg = new Image();
|
194 |
+
playerImg.src = 'player.png';
|
195 |
+
const enemyImg = new Image();
|
196 |
+
enemyImg.src = 'enemy.png';
|
197 |
+
const bulletImg = new Image();
|
198 |
+
bulletImg.src = 'apcr2.png';
|
199 |
+
|
200 |
+
// Audio setup
|
201 |
+
const cannonSound = new Audio('firemn.ogg');
|
202 |
+
const machinegunSound = new Audio('firemg.ogg');
|
203 |
+
const enemyFireSound = new Audio('fireenemy.ogg');
|
204 |
+
let bgm = new Audio('title.ogg');
|
205 |
+
const countSound = new Audio('count.ogg');
|
206 |
+
const deathSound = new Audio('death.ogg');
|
207 |
+
bgm.loop = true;
|
208 |
+
enemyFireSound.volume = 0.5;
|
209 |
+
|
210 |
+
// Weapons configuration
|
211 |
+
const weapons = {
|
212 |
+
cannon: {
|
213 |
+
fireRate: 1000,
|
214 |
+
damage: 0.25,
|
215 |
+
bulletSize: 5,
|
216 |
+
sound: cannonSound
|
217 |
+
},
|
218 |
+
machinegun: {
|
219 |
+
fireRate: 200,
|
220 |
+
damage: 0.05,
|
221 |
+
bulletSize: 2,
|
222 |
+
sound: machinegunSound
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
}
|
224 |
+
};
|
225 |
|
226 |
+
// Player setup
|
227 |
+
const player = {
|
228 |
+
x: canvas.width/2,
|
229 |
+
y: canvas.height/2,
|
230 |
+
speed: 5,
|
231 |
+
angle: 0,
|
232 |
+
width: 100,
|
233 |
+
height: 45,
|
234 |
+
health: 1000,
|
235 |
+
maxHealth: 1000
|
236 |
+
};
|
237 |
|
238 |
+
function startStage(stageNumber) {
|
239 |
+
if (stageNumber === 1) {
|
240 |
+
document.getElementById('titleScreen').style.display = 'none';
|
241 |
+
document.getElementById('instructions').style.display = 'block';
|
242 |
+
document.getElementById('weaponInfo').style.display = 'block';
|
243 |
+
document.getElementById('gameCanvas').style.display = 'block';
|
244 |
+
|
245 |
+
// BGM 변경
|
246 |
+
bgm.pause();
|
247 |
+
bgm = new Audio('BGM2.ogg');
|
248 |
+
bgm.loop = true;
|
249 |
+
bgm.play();
|
250 |
+
|
251 |
+
gameStarted = true;
|
252 |
+
currentRound = 1;
|
253 |
+
initRound();
|
254 |
+
gameLoop();
|
255 |
}
|
256 |
}
|
257 |
+
// 게임 초기화 및 라운드 관련 함수
|
258 |
+
function startCountdown() {
|
259 |
+
isCountingDown = true;
|
260 |
+
countdownTime = 3;
|
261 |
+
countdownEl.style.display = 'block';
|
262 |
+
countdownEl.textContent = countdownTime;
|
263 |
+
bgm.pause();
|
264 |
+
countSound.play();
|
265 |
+
|
266 |
+
const countInterval = setInterval(() => {
|
267 |
+
countdownTime--;
|
268 |
+
if(countdownTime <= 0) {
|
269 |
+
clearInterval(countInterval);
|
270 |
+
countdownEl.style.display = 'none';
|
271 |
+
isCountingDown = false;
|
272 |
+
bgm.play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
}
|
274 |
+
countdownEl.textContent = countdownTime > 0 ? countdownTime : 'GO!';
|
275 |
+
}, 1000);
|
276 |
+
}
|
277 |
|
278 |
+
function initRound() {
|
279 |
+
enemies = [];
|
280 |
+
for(let i = 0; i < 1 * currentRound; i++) {
|
281 |
+
enemies.push(new Enemy());
|
|
|
|
|
|
|
282 |
}
|
283 |
+
player.health = player.maxHealth;
|
284 |
+
bullets = [];
|
285 |
+
items = [];
|
286 |
+
supportUnits = [];
|
287 |
+
lastSupportSpawn = 0;
|
288 |
|
289 |
+
startCountdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
+
setTimeout(() => {
|
292 |
+
if (hasJU87) {
|
293 |
+
supportUnits.push(new JU87());
|
294 |
+
lastJU87Spawn = Date.now();
|
|
|
295 |
}
|
296 |
+
}, 3000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
+
// 상점 관련 함수
|
300 |
+
function showShop() {
|
301 |
+
document.getElementById('shop').style.display = 'block';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
const defaultPlayerStats = {
|
305 |
maxHealth: 1000,
|
306 |
speed: 5,
|
307 |
width: 100,
|
308 |
height: 45
|
309 |
};
|
310 |
+
|
311 |
function buyTank(tankImg, cost, tankId) {
|
312 |
if (gold >= cost) {
|
313 |
gold -= cost;
|
|
|
315 |
document.getElementById(tankId).style.display = 'none';
|
316 |
document.getElementById('shop').style.display = 'none';
|
317 |
|
318 |
+
if (tankId === 'tank1') {
|
319 |
player.maxHealth = 1500;
|
320 |
+
player.speed = defaultPlayerStats.speed;
|
321 |
+
player.width = 90;
|
322 |
+
player.height = 50;
|
323 |
+
} else if (tankId === 'tank2') {
|
|
|
324 |
player.maxHealth = 2000;
|
325 |
player.speed = defaultPlayerStats.speed * 0.7;
|
326 |
+
player.width = 100;
|
327 |
+
player.height = 45;
|
328 |
}
|
|
|
329 |
player.health = player.maxHealth;
|
330 |
}
|
331 |
}
|
332 |
+
|
333 |
+
function buyAPCR() {
|
334 |
if (gold >= 1000 && !hasAPCR) {
|
335 |
gold -= 1000;
|
336 |
hasAPCR = true;
|
|
|
338 |
document.getElementById('shop').style.display = 'none';
|
339 |
}
|
340 |
}
|
341 |
+
|
342 |
+
function buyBF109() {
|
343 |
if (gold >= 1000 && !hasBF109) {
|
344 |
gold -= 1000;
|
345 |
hasBF109 = true;
|
|
|
347 |
document.getElementById('shop').style.display = 'none';
|
348 |
}
|
349 |
}
|
350 |
+
|
351 |
+
function buyJU87() {
|
352 |
if (gold >= 1500 && !hasJU87) {
|
353 |
gold -= 1500;
|
354 |
hasJU87 = true;
|
355 |
document.getElementById('ju87').style.display = 'none';
|
356 |
document.getElementById('shop').style.display = 'none';
|
357 |
+
lastJU87Spawn = Date.now();
|
358 |
}
|
359 |
}
|
360 |
+
// 게임 업데이트 및 렌더링 관련 함수
|
361 |
+
function updateGame() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
if(gameOver) return;
|
363 |
if(!isCountingDown) {
|
364 |
// 플레이어 움직임
|
|
|
366 |
if(keys['s']) player.y += player.speed;
|
367 |
if(keys['a']) player.x -= player.speed;
|
368 |
if(keys['d']) player.x += player.speed;
|
369 |
+
|
370 |
player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
|
371 |
player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
|
372 |
+
|
373 |
fireBullet();
|
374 |
}
|
375 |
|
376 |
+
// BF109 지원
|
377 |
if (hasBF109 && !isCountingDown) {
|
378 |
const now = Date.now();
|
379 |
+
if (now - lastSupportSpawn > 10000) {
|
380 |
supportUnits.push(
|
381 |
new SupportUnit(canvas.height * 0.2),
|
382 |
new SupportUnit(canvas.height * 0.5),
|
|
|
386 |
}
|
387 |
}
|
388 |
|
389 |
+
// JU87 지원
|
390 |
if (hasJU87 && !isCountingDown) {
|
391 |
const now = Date.now();
|
392 |
+
if (now - lastJU87Spawn > 15000) {
|
393 |
supportUnits.push(new JU87());
|
394 |
lastJU87Spawn = now;
|
395 |
}
|
396 |
}
|
397 |
|
398 |
+
// 지원 유닛 업데이트
|
399 |
supportUnits = supportUnits.filter(unit => unit.update());
|
400 |
|
401 |
+
// 적 업데이트
|
402 |
enemies.forEach(enemy => enemy.update());
|
403 |
+
|
404 |
+
if(!isCountingDown) {
|
405 |
+
// 총알 업데이트
|
406 |
+
bullets = bullets.filter(bullet => {
|
407 |
+
bullet.x += Math.cos(bullet.angle) * bullet.speed;
|
408 |
+
bullet.y += Math.sin(bullet.angle) * bullet.speed;
|
409 |
+
|
410 |
+
if(!bullet.isEnemy) {
|
411 |
+
enemies = enemies.filter(enemy => {
|
412 |
+
const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
|
413 |
+
if(dist < 30) {
|
414 |
+
enemy.health -= bullet.damage * 1000;
|
415 |
+
if(enemy.health <= 0) {
|
416 |
+
spawnHealthItem(enemy.x, enemy.y);
|
417 |
+
gold += 100;
|
418 |
+
effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
|
419 |
+
deathSound.cloneNode().play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
return false;
|
421 |
}
|
422 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
}
|
424 |
return true;
|
425 |
});
|
426 |
+
} else {
|
427 |
+
const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
|
428 |
+
if(dist < 30) {
|
429 |
+
player.health -= bullet.damage;
|
430 |
+
if(player.health <= 0) {
|
431 |
+
gameOver = true;
|
432 |
+
restartBtn.style.display = 'block';
|
433 |
+
effects.push(new Effect(player.x, player.y, 1000, 'death'));
|
434 |
+
deathSound.cloneNode().play();
|
435 |
+
}
|
436 |
+
return false;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
return bullet.x >= 0 && bullet.x <= canvas.width &&
|
440 |
+
bullet.y >= 0 && bullet.y <= canvas.height;
|
441 |
+
});
|
442 |
+
|
443 |
+
// 아이템 업데이트
|
444 |
+
items = items.filter(item => {
|
445 |
+
const dist = Math.hypot(item.x - player.x, item.y - player.y);
|
446 |
+
if(dist < 30) {
|
447 |
+
player.health = Math.min(player.health + 200, player.maxHealth);
|
448 |
+
return false;
|
449 |
+
}
|
450 |
+
return true;
|
451 |
+
});
|
452 |
+
|
453 |
+
// 라운드 종료 체크
|
454 |
+
if(enemies.length === 0) {
|
455 |
if (!isBossStage) {
|
456 |
if(currentRound < 10) {
|
457 |
nextRoundBtn.style.display = 'block';
|
458 |
showShop();
|
459 |
} else {
|
460 |
+
bossButton.style.display = 'block';
|
461 |
}
|
462 |
} else {
|
463 |
gameOver = true;
|
464 |
document.getElementById('winMessage').style.display = 'block';
|
465 |
restartBtn.style.display = 'block';
|
466 |
+
bgm.pause();
|
467 |
+
const victorySound = new Audio('victory.ogg');
|
468 |
+
victorySound.play();
|
469 |
}
|
470 |
}
|
471 |
}
|
|
|
472 |
}
|
473 |
+
// 게임 렌더링 함수
|
474 |
+
function drawGame() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
476 |
+
|
477 |
+
// 배경 그리기
|
478 |
const pattern = ctx.createPattern(backgroundImg, 'repeat');
|
479 |
ctx.fillStyle = pattern;
|
480 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
486 |
ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
|
487 |
ctx.restore();
|
488 |
|
489 |
+
// 체력바 그리기
|
490 |
drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
|
491 |
|
492 |
// 적 그리기
|
|
|
499 |
ctx.restore();
|
500 |
drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
|
501 |
});
|
502 |
+
|
503 |
+
// 지원 유닛 그리기
|
504 |
+
supportUnits.forEach(unit => {
|
505 |
ctx.save();
|
506 |
ctx.translate(unit.x, unit.y);
|
507 |
ctx.rotate(unit.angle);
|
508 |
ctx.drawImage(unit.img, -unit.width/2, -unit.height/2, unit.width, unit.height);
|
509 |
ctx.restore();
|
510 |
});
|
511 |
+
|
512 |
+
// 총알 그리기
|
513 |
+
bullets.forEach(bullet => {
|
514 |
+
if (bullet.isEnemy || !bullet.isAPCR) {
|
515 |
+
ctx.beginPath();
|
516 |
+
ctx.fillStyle = bullet.isEnemy ? 'red' : 'blue';
|
517 |
+
ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
|
518 |
+
ctx.fill();
|
519 |
+
} else {
|
520 |
+
ctx.save();
|
521 |
+
ctx.translate(bullet.x, bullet.y);
|
522 |
+
ctx.rotate(bullet.angle);
|
523 |
+
const width = currentWeapon === 'machinegun' ? 10 : 20;
|
524 |
+
const height = currentWeapon === 'machinegun' ? 5 : 10;
|
525 |
+
ctx.drawImage(bulletImg, -width/2, -height/2, width, height);
|
526 |
+
ctx.restore();
|
527 |
+
}
|
528 |
+
});
|
529 |
+
|
530 |
// 아이템 그리기
|
531 |
items.forEach(item => {
|
532 |
ctx.beginPath();
|
|
|
534 |
ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
|
535 |
ctx.fill();
|
536 |
});
|
537 |
+
|
538 |
// UI 그리기
|
539 |
ctx.fillStyle = 'white';
|
540 |
ctx.font = '24px Arial';
|
|
|
542 |
ctx.fillText(`Gold: ${gold}`, 10, 60);
|
543 |
|
544 |
// 이펙트 그리기
|
545 |
+
effects = effects.filter(effect => !effect.isExpired());
|
546 |
+
effects.forEach(effect => {
|
547 |
+
effect.update();
|
548 |
+
ctx.save();
|
549 |
+
ctx.translate(effect.x, effect.y);
|
550 |
+
if (effect.type === 'fire') ctx.rotate(effect.angle);
|
551 |
+
const size = effect.type === 'death' ? 75 : 42;
|
552 |
+
ctx.drawImage(effect.img, -size/2, -size/2, size, size);
|
553 |
+
ctx.restore();
|
554 |
+
});
|
|
|
555 |
|
556 |
+
// 카운트다운 오버레이
|
557 |
+
if (isCountingDown) {
|
558 |
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
559 |
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
560 |
}
|
561 |
}
|
562 |
|
563 |
+
// 게임 루프
|
564 |
function gameLoop() {
|
565 |
+
if (!gameOver && gameStarted) {
|
566 |
+
updateGame();
|
567 |
+
drawGame();
|
568 |
+
requestAnimationFrame(gameLoop);
|
569 |
+
}
|
570 |
}
|
571 |
|
572 |
+
// 이벤트 리스너
|
573 |
nextRoundBtn.addEventListener('click', () => {
|
574 |
currentRound++;
|
575 |
nextRoundBtn.style.display = 'none';
|
|
|
577 |
initRound();
|
578 |
});
|
579 |
|
|
|
|
|
580 |
restartBtn.addEventListener('click', () => {
|
581 |
+
location.reload();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
});
|
583 |
|
584 |
+
// 키보드 및 마우스 이벤트
|
585 |
+
const keys = {};
|
586 |
+
document.addEventListener('keydown', e => {
|
587 |
+
keys[e.key] = true;
|
588 |
+
if(e.key.toLowerCase() === 'c') {
|
589 |
+
currentWeapon = currentWeapon === 'cannon' ? 'machinegun' : 'cannon';
|
590 |
+
weaponInfo.textContent = `Current Weapon: ${currentWeapon.charAt(0).toUpperCase() + currentWeapon.slice(1)}`;
|
591 |
+
} else if(e.key.toLowerCase() === 'r') {
|
592 |
+
autoFire = !autoFire;
|
593 |
+
}
|
594 |
});
|
595 |
|
596 |
+
document.addEventListener('keyup', e => keys[e.key] = false);
|
597 |
+
|
598 |
+
canvas.addEventListener('mousemove', (e) => {
|
599 |
+
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
600 |
+
});
|
601 |
+
|
602 |
+
// 보스 버튼 이벤트
|
603 |
+
bossButton.addEventListener('click', () => {
|
604 |
+
startBossStage();
|
605 |
+
});
|
606 |
+
|
607 |
+
// 창 크기 조절 이벤트
|
608 |
window.addEventListener('resize', () => {
|
609 |
canvas.width = window.innerWidth;
|
610 |
canvas.height = window.innerHeight;
|
611 |
});
|
612 |
+
// 총알 발사 함수
|
613 |
+
function fireBullet() {
|
614 |
+
if(isCountingDown) return;
|
615 |
+
const weapon = weapons[currentWeapon];
|
616 |
+
const now = Date.now();
|
617 |
+
if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
|
618 |
+
weapon.sound.cloneNode().play();
|
619 |
+
effects.push(new Effect(
|
620 |
+
player.x + Math.cos(player.angle) * 30,
|
621 |
+
player.y + Math.sin(player.angle) * 30,
|
622 |
+
500,
|
623 |
+
'fire',
|
624 |
+
player.angle,
|
625 |
+
player
|
626 |
+
));
|
627 |
+
|
628 |
+
bullets.push({
|
629 |
+
x: player.x + Math.cos(player.angle) * 30,
|
630 |
+
y: player.y + Math.sin(player.angle) * 30,
|
631 |
+
angle: player.angle,
|
632 |
+
speed: hasAPCR ? 20 : 10,
|
633 |
+
isEnemy: false,
|
634 |
+
damage: weapon.damage,
|
635 |
+
size: weapon.bulletSize,
|
636 |
+
isAPCR: hasAPCR
|
637 |
+
});
|
638 |
+
lastShot = now;
|
639 |
+
}
|
640 |
+
}
|
641 |
+
|
642 |
+
// Enemy 클래스
|
643 |
+
class Enemy {
|
644 |
+
constructor(isBoss = false) {
|
645 |
+
this.x = Math.random() * canvas.width;
|
646 |
+
this.y = Math.random() * canvas.height;
|
647 |
+
this.health = isBoss ? 15000 : 1000;
|
648 |
+
this.maxHealth = this.health;
|
649 |
+
this.speed = isBoss ? 1 : 2;
|
650 |
+
this.lastShot = 0;
|
651 |
+
this.shootInterval = isBoss ? 1000 : 1000;
|
652 |
+
this.angle = 0;
|
653 |
+
this.width = 100;
|
654 |
+
this.height = 45;
|
655 |
+
this.moveTimer = 0;
|
656 |
+
this.moveInterval = Math.random() * 2000 + 1000;
|
657 |
+
this.moveAngle = Math.random() * Math.PI * 2;
|
658 |
+
this.isBoss = isBoss;
|
659 |
+
|
660 |
+
if (isBoss) {
|
661 |
+
this.enemyImg = new Image();
|
662 |
+
this.enemyImg.src = 'boss.png';
|
663 |
+
} else if (currentRound >= 7) {
|
664 |
+
this.enemyImg = new Image();
|
665 |
+
this.enemyImg.src = 'enemy3.png';
|
666 |
+
} else if (currentRound >= 4) {
|
667 |
+
this.enemyImg = new Image();
|
668 |
+
this.enemyImg.src = 'enemy2.png';
|
669 |
+
}
|
670 |
+
}
|
671 |
+
|
672 |
+
update() {
|
673 |
+
if(isCountingDown) return;
|
674 |
+
const now = Date.now();
|
675 |
+
|
676 |
+
if (now - this.moveTimer > this.moveInterval) {
|
677 |
+
this.moveAngle = Math.random() * Math.PI * 2;
|
678 |
+
this.moveTimer = now;
|
679 |
+
}
|
680 |
+
this.x += Math.cos(this.moveAngle) * this.speed;
|
681 |
+
this.y += Math.sin(this.moveAngle) * this.speed;
|
682 |
+
this.x = Math.max(this.width/2, Math.min(canvas.width - this.width/2, this.x));
|
683 |
+
this.y = Math.max(this.height/2, Math.min(canvas.height - this.height/2, this.y));
|
684 |
+
this.angle = Math.atan2(player.y - this.y, player.x - this.x);
|
685 |
+
|
686 |
+
if (now - this.lastShot > this.shootInterval && !isCountingDown) {
|
687 |
+
this.shoot();
|
688 |
+
this.lastShot = now;
|
689 |
+
}
|
690 |
+
}
|
691 |
+
|
692 |
+
shoot() {
|
693 |
+
const sound = this.isBoss ? new Audio('firemn.ogg') : enemyFireSound.cloneNode();
|
694 |
+
sound.play();
|
695 |
+
|
696 |
+
effects.push(new Effect(
|
697 |
+
this.x + Math.cos(this.angle) * 30,
|
698 |
+
this.y + Math.sin(this.angle) * 30,
|
699 |
+
500,
|
700 |
+
'fire',
|
701 |
+
this.angle,
|
702 |
+
this
|
703 |
+
));
|
704 |
+
|
705 |
+
bullets.push({
|
706 |
+
x: this.x + Math.cos(this.angle) * 30,
|
707 |
+
y: this.y + Math.sin(this.angle) * 30,
|
708 |
+
angle: this.angle,
|
709 |
+
speed: this.isBoss ? 10 : 5,
|
710 |
+
isEnemy: true,
|
711 |
+
size: this.isBoss ? 5 : 3,
|
712 |
+
damage: this.isBoss ? 300 : 150
|
713 |
+
});
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
// Effect 클래스
|
718 |
+
class Effect {
|
719 |
+
constructor(x, y, duration, type, angle = 0, parent = null) {
|
720 |
+
this.x = x;
|
721 |
+
this.y = y;
|
722 |
+
this.startTime = Date.now();
|
723 |
+
this.duration = duration;
|
724 |
+
this.type = type;
|
725 |
+
this.angle = angle;
|
726 |
+
this.parent = parent;
|
727 |
+
this.offset = { x: Math.cos(angle) * 30, y: Math.sin(angle) * 30 };
|
728 |
+
this.img = new Image();
|
729 |
+
this.img.src = type === 'death' ? 'bang.png' : 'fire2.png';
|
730 |
+
}
|
731 |
+
|
732 |
+
update() {
|
733 |
+
if(this.parent && this.type === 'fire') {
|
734 |
+
this.x = this.parent.x + this.offset.x;
|
735 |
+
this.y = this.parent.y + this.offset.y;
|
736 |
+
this.angle = this.parent.angle;
|
737 |
+
}
|
738 |
+
}
|
739 |
+
|
740 |
+
isExpired() {
|
741 |
+
return Date.now() - this.startTime > this.duration;
|
742 |
+
}
|
743 |
+
}
|
744 |
+
// SupportUnit 클래스
|
745 |
+
class SupportUnit {
|
746 |
+
constructor(yPosition) {
|
747 |
+
this.x = 0;
|
748 |
+
this.y = yPosition;
|
749 |
+
this.speed = 5;
|
750 |
+
this.lastShot = 0;
|
751 |
+
this.width = 100;
|
752 |
+
this.height = 100;
|
753 |
+
this.angle = 0;
|
754 |
+
this.img = new Image();
|
755 |
+
this.img.src = 'bf109.png';
|
756 |
+
this.hasPlayedSound = false;
|
757 |
+
this.mgSound = null;
|
758 |
+
}
|
759 |
+
|
760 |
+
update() {
|
761 |
+
this.x += this.speed;
|
762 |
+
|
763 |
+
if (isCountingDown) {
|
764 |
+
if (this.mgSound) {
|
765 |
+
this.mgSound.pause();
|
766 |
+
this.mgSound.currentTime = 0;
|
767 |
+
}
|
768 |
+
this.hasPlayedSound = false;
|
769 |
+
}
|
770 |
+
|
771 |
+
const now = Date.now();
|
772 |
+
if (now - this.lastShot > 200 && !isCountingDown) {
|
773 |
+
this.shoot();
|
774 |
+
this.lastShot = now;
|
775 |
+
}
|
776 |
+
return this.x < canvas.width;
|
777 |
+
}
|
778 |
+
|
779 |
+
shoot() {
|
780 |
+
if (!this.hasPlayedSound) {
|
781 |
+
const firstSound = new Audio('bf109mg.ogg');
|
782 |
+
firstSound.volume = 1.0;
|
783 |
+
firstSound.play();
|
784 |
+
this.hasPlayedSound = true;
|
785 |
+
}
|
786 |
+
|
787 |
+
if (!isCountingDown) {
|
788 |
+
const shootSound = new Audio('bf109mgse.ogg');
|
789 |
+
shootSound.volume = 0.5;
|
790 |
+
shootSound.play();
|
791 |
+
}
|
792 |
+
|
793 |
+
bullets.push({
|
794 |
+
x: this.x + Math.cos(this.angle) * 30,
|
795 |
+
y: this.y + Math.sin(this.angle) * 30,
|
796 |
+
angle: this.angle,
|
797 |
+
speed: 10,
|
798 |
+
isEnemy: false,
|
799 |
+
damage: weapons.machinegun.damage,
|
800 |
+
size: weapons.machinegun.bulletSize
|
801 |
+
});
|
802 |
+
}
|
803 |
+
}
|
804 |
+
|
805 |
+
// JU87 클래스
|
806 |
+
class JU87 {
|
807 |
+
constructor() {
|
808 |
+
this.x = canvas.width;
|
809 |
+
this.y = 50;
|
810 |
+
this.speed = 5;
|
811 |
+
this.width = 100;
|
812 |
+
this.height = 100;
|
813 |
+
this.angle = Math.PI;
|
814 |
+
this.img = new Image();
|
815 |
+
this.img.src = 'ju87.png';
|
816 |
+
this.target = null;
|
817 |
+
this.lastShot = 0;
|
818 |
+
this.spawnTime = Date.now();
|
819 |
+
this.hasPlayedSound = false;
|
820 |
+
this.hasPlayedMGSound = false;
|
821 |
+
this.isReturning = false;
|
822 |
+
this.circleAngle = 0;
|
823 |
+
this.returningToCenter = false;
|
824 |
+
}
|
825 |
+
|
826 |
+
selectTarget() {
|
827 |
+
return enemies.length > 0 ?
|
828 |
+
enemies[Math.floor(Math.random() * enemies.length)] : null;
|
829 |
+
}
|
830 |
+
|
831 |
+
shoot() {
|
832 |
+
if (!this.hasPlayedMGSound && !isCountingDown) {
|
833 |
+
const mgSound = new Audio('ju87mg.ogg');
|
834 |
+
mgSound.volume = 1.0;
|
835 |
+
mgSound.currentTime = 0;
|
836 |
+
mgSound.play().catch(error => console.error('Audio play failed:', error));
|
837 |
+
this.hasPlayedMGSound = true;
|
838 |
+
}
|
839 |
+
|
840 |
+
[[20, 50], [80, 50]].forEach(([x, y]) => {
|
841 |
+
const offsetX = x - 50;
|
842 |
+
const offsetY = y - 50;
|
843 |
+
|
844 |
+
const rotatedX = this.x + (Math.cos(this.angle) * offsetX - Math.sin(this.angle) * offsetY);
|
845 |
+
const rotatedY = this.y + (Math.sin(this.angle) * offsetX + Math.cos(this.angle) * offsetY);
|
846 |
+
|
847 |
+
bullets.push({
|
848 |
+
x: rotatedX,
|
849 |
+
y: rotatedY,
|
850 |
+
angle: this.angle,
|
851 |
+
speed: 10,
|
852 |
+
isEnemy: false,
|
853 |
+
damage: weapons.machinegun.damage * 2,
|
854 |
+
size: weapons.machinegun.bulletSize
|
855 |
+
});
|
856 |
+
});
|
857 |
+
}
|
858 |
+
|
859 |
+
update() {
|
860 |
+
// JU87의 update 메서드 내용은 이전과 동일하게 유지
|
861 |
+
// (길이 제한으로 인해 생략했지만, 이전 코드와 동일하게 구현해야 함)
|
862 |
+
}
|
863 |
+
}
|
864 |
+
|
865 |
+
// 게임 초기화 및 시작
|
866 |
+
document.addEventListener('DOMContentLoaded', () => {
|
867 |
+
const titleScreen = document.getElementById('titleScreen');
|
868 |
+
const instructions = document.getElementById('instructions');
|
869 |
+
const weaponInfo = document.getElementById('weaponInfo');
|
870 |
+
const gameCanvas = document.getElementById('gameCanvas');
|
871 |
+
|
872 |
+
instructions.style.display = 'none';
|
873 |
+
weaponInfo.style.display = 'none';
|
874 |
+
gameCanvas.style.display = 'none';
|
875 |
+
|
876 |
+
bgm.play().catch(err => console.error("Error playing title music:", err));
|
877 |
+
|
878 |
+
// 이벤트 리스너 설정
|
879 |
+
window.addEventListener('resize', () => {
|
880 |
+
canvas.width = window.innerWidth;
|
881 |
+
canvas.height = window.innerHeight;
|
882 |
+
});
|
883 |
+
});
|
884 |
+
|
885 |
+
// 헬퍼 함수들
|
886 |
+
function spawnHealthItem(x, y) {
|
887 |
+
items.push({x, y});
|
888 |
+
}
|
889 |
+
|
890 |
+
function drawHealthBar(x, y, health, maxHealth, width, height, color) {
|
891 |
+
ctx.fillStyle = '#333';
|
892 |
+
ctx.fillRect(x - width/2, y - height/2, width, height);
|
893 |
+
ctx.fillStyle = color;
|
894 |
+
ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
|
895 |
+
}
|
896 |
+
|
897 |
+
function startBossStage() {
|
898 |
+
isBossStage = true;
|
899 |
+
enemies = [];
|
900 |
+
enemies.push(new Enemy(true));
|
901 |
+
player.health = player.maxHealth;
|
902 |
+
bullets = [];
|
903 |
+
items = [];
|
904 |
+
document.getElementById('bossButton').style.display = 'none';
|
905 |
+
bgm.src = 'BGM.ogg';
|
906 |
+
startCountdown();
|
907 |
+
}
|
908 |
+
|