Spaces:
Running
Running
cutechicken
commited on
Update index.html
Browse files- index.html +80 -25
index.html
CHANGED
@@ -139,6 +139,7 @@
|
|
139 |
let autoFire = false;
|
140 |
let gold = 0;
|
141 |
let isBossStage = false;
|
|
|
142 |
// Load assets
|
143 |
const backgroundImg = new Image();
|
144 |
backgroundImg.src = 'city.png';
|
@@ -152,6 +153,7 @@
|
|
152 |
const enemyFireSound = new Audio('fireenemy.ogg');
|
153 |
const bgm = new Audio('BGM.ogg');
|
154 |
const countSound = new Audio('count.ogg');
|
|
|
155 |
bgm.loop = true;
|
156 |
enemyFireSound.volume = 0.5;
|
157 |
const weapons = {
|
@@ -197,6 +199,23 @@
|
|
197 |
countdownEl.textContent = countdownTime > 0 ? countdownTime : 'GO!';
|
198 |
}, 1000);
|
199 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
class Enemy {
|
201 |
constructor(isBoss = false) {
|
202 |
this.x = Math.random() * canvas.width;
|
@@ -244,19 +263,28 @@
|
|
244 |
this.lastShot = now;
|
245 |
}
|
246 |
}
|
247 |
-
|
248 |
const sound = this.isBoss ? new Audio('firemn.ogg') : enemyFireSound.cloneNode();
|
249 |
sound.play();
|
250 |
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
}
|
262 |
function showShop() {
|
@@ -327,12 +355,20 @@ function buyTank(tankImg, cost, tankId) {
|
|
327 |
});
|
328 |
|
329 |
document.addEventListener('keyup', e => keys[e.key] = false);
|
330 |
-
|
331 |
if(isCountingDown) return;
|
332 |
const weapon = weapons[currentWeapon];
|
333 |
const now = Date.now();
|
334 |
if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
|
335 |
weapon.sound.cloneNode().play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
bullets.push({
|
337 |
x: player.x + Math.cos(player.angle) * 30,
|
338 |
y: player.y + Math.sin(player.angle) * 30,
|
@@ -367,11 +403,20 @@ function buyTank(tankImg, cost, tankId) {
|
|
367 |
if(dist < 30) {
|
368 |
let damage = currentWeapon === 'cannon' ? 250 : 50; // 고정 데미지로 변경
|
369 |
enemy.health -= damage;
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
return true;
|
376 |
}
|
377 |
return true;
|
@@ -463,15 +508,25 @@ function buyTank(tankImg, cost, tankId) {
|
|
463 |
ctx.fill();
|
464 |
});
|
465 |
// UI 그리기
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
function gameLoop() {
|
476 |
updateGame();
|
477 |
drawGame();
|
|
|
139 |
let autoFire = false;
|
140 |
let gold = 0;
|
141 |
let isBossStage = false;
|
142 |
+
let effects = [];
|
143 |
// Load assets
|
144 |
const backgroundImg = new Image();
|
145 |
backgroundImg.src = 'city.png';
|
|
|
153 |
const enemyFireSound = new Audio('fireenemy.ogg');
|
154 |
const bgm = new Audio('BGM.ogg');
|
155 |
const countSound = new Audio('count.ogg');
|
156 |
+
const deathSound = new Audio('death.ogg');
|
157 |
bgm.loop = true;
|
158 |
enemyFireSound.volume = 0.5;
|
159 |
const weapons = {
|
|
|
199 |
countdownEl.textContent = countdownTime > 0 ? countdownTime : 'GO!';
|
200 |
}, 1000);
|
201 |
}
|
202 |
+
|
203 |
+
class Effect {
|
204 |
+
constructor(x, y, duration, type, angle = 0) {
|
205 |
+
this.x = x;
|
206 |
+
this.y = y;
|
207 |
+
this.startTime = Date.now();
|
208 |
+
this.duration = duration;
|
209 |
+
this.type = type; // 'death' 또는 'fire'
|
210 |
+
this.angle = angle;
|
211 |
+
this.img = new Image();
|
212 |
+
this.img.src = type === 'death' ? 'bang.png' : 'fire.png';
|
213 |
+
}
|
214 |
+
|
215 |
+
isExpired() {
|
216 |
+
return Date.now() - this.startTime > this.duration;
|
217 |
+
}
|
218 |
+
}
|
219 |
class Enemy {
|
220 |
constructor(isBoss = false) {
|
221 |
this.x = Math.random() * canvas.width;
|
|
|
263 |
this.lastShot = now;
|
264 |
}
|
265 |
}
|
266 |
+
shoot() {
|
267 |
const sound = this.isBoss ? new Audio('firemn.ogg') : enemyFireSound.cloneNode();
|
268 |
sound.play();
|
269 |
|
270 |
+
// 발사 이펙트 추가
|
271 |
+
effects.push(new Effect(
|
272 |
+
this.x + Math.cos(this.angle) * 30,
|
273 |
+
this.y + Math.sin(this.angle) * 30,
|
274 |
+
500, // 0.5초
|
275 |
+
'fire',
|
276 |
+
this.angle
|
277 |
+
));
|
278 |
+
|
279 |
+
bullets.push({
|
280 |
+
x: this.x + Math.cos(this.angle) * 30,
|
281 |
+
y: this.y + Math.sin(this.angle) * 30,
|
282 |
+
angle: this.angle,
|
283 |
+
speed: this.isBoss ? 10 : 5,
|
284 |
+
isEnemy: true,
|
285 |
+
size: this.isBoss ? 5 : 3,
|
286 |
+
damage: this.isBoss ? 300 : 150
|
287 |
+
});
|
288 |
}
|
289 |
}
|
290 |
function showShop() {
|
|
|
355 |
});
|
356 |
|
357 |
document.addEventListener('keyup', e => keys[e.key] = false);
|
358 |
+
function fireBullet() {
|
359 |
if(isCountingDown) return;
|
360 |
const weapon = weapons[currentWeapon];
|
361 |
const now = Date.now();
|
362 |
if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
|
363 |
weapon.sound.cloneNode().play();
|
364 |
+
// 발사 이펙트 추가
|
365 |
+
effects.push(new Effect(
|
366 |
+
player.x + Math.cos(player.angle) * 30,
|
367 |
+
player.y + Math.sin(player.angle) * 30,
|
368 |
+
500, // 0.5초
|
369 |
+
'fire',
|
370 |
+
player.angle
|
371 |
+
));
|
372 |
bullets.push({
|
373 |
x: player.x + Math.cos(player.angle) * 30,
|
374 |
y: player.y + Math.sin(player.angle) * 30,
|
|
|
403 |
if(dist < 30) {
|
404 |
let damage = currentWeapon === 'cannon' ? 250 : 50; // 고정 데미지로 변경
|
405 |
enemy.health -= damage;
|
406 |
+
if(enemy.health <= 0) {
|
407 |
+
spawnHealthItem(enemy.x, enemy.y);
|
408 |
+
gold += 100;
|
409 |
+
// 죽음 이펙트와 사운드 추가
|
410 |
+
effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
|
411 |
+
deathSound.cloneNode().play();
|
412 |
+
return false;
|
413 |
+
}
|
414 |
+
if(player.health <= 0) {
|
415 |
+
gameOver = true;
|
416 |
+
restartBtn.style.display = 'block';
|
417 |
+
effects.push(new Effect(player.x, player.y, 1000, 'death'));
|
418 |
+
deathSound.cloneNode().play();
|
419 |
+
}
|
420 |
return true;
|
421 |
}
|
422 |
return true;
|
|
|
508 |
ctx.fill();
|
509 |
});
|
510 |
// UI 그리기
|
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 |
+
|
526 |
+
if(isCountingDown) {
|
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();
|