Skip to content

Commit

Permalink
🎨 style : 곡룑 κ²Œμž„ μ‚¬μš΄λ“œ ν•¨μˆ˜ 포맷 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
ctmdghks committed Apr 26, 2024
1 parent 25dc02c commit abc8ac8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 48 deletions.
14 changes: 5 additions & 9 deletions js/dinosaur/dinosaur.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
//dinosaur.js
function loadGameDino() {
console.log(globalSelectedCharacter); // μ„ νƒλœ 캐릭터 확인
console.log(globalSelectedCharacter);
const content = document.getElementById('content');

var newStyle = document.createElement('link');
newStyle.setAttribute('rel', 'stylesheet');

resetAnimation(content); // μ• λ‹ˆλ©”μ΄μ…˜ μ΄ˆκΈ°ν™”
updateGameContent(); // μ½˜ν…μΈ  μ—…λ°μ΄νŠΈ
resetAnimation(content);
updateGameContent();

// μ• λ‹ˆλ©”μ΄μ…˜ μ‹œμž‘
content.classList.add('fade-in');
}

function resetAnimation(element) {
element.classList.remove('fade-in');
void element.offsetWidth; // DOM λ¦¬ν”Œλ‘œμš° κ°•μ œ μ‹€ν–‰μœΌλ‘œ CSS μ• λ‹ˆλ©”μ΄μ…˜ 리셋
void element.offsetWidth;
element.classList.add('fade-in');
}

Expand Down Expand Up @@ -51,16 +49,14 @@ function updateGameContent() {
}

function loadScript(src) {
// 기쑴에 λ‘œλ“œλœ λ™μΌν•œ 슀크립트 νŒŒμΌμ„ μ°Ύμ•„ μ œκ±°ν•©λ‹ˆλ‹€.
const existingScript = document.querySelector(`script[src="${src}"]`);
if (existingScript) {
existingScript.remove();
}

// μƒˆ 슀크립트 μš”μ†Œλ₯Ό μƒμ„±ν•˜κ³ , νŽ˜μ΄μ§€μ— μΆ”κ°€ν•©λ‹ˆλ‹€.
let script = document.createElement('script');
script.src = src;
script.type = 'text/javascript';
script.async = false; // 슀크립트 λ‘œλ”© μˆœμ„œλ₯Ό 보μž₯ν•©λ‹ˆλ‹€.
script.async = false;
document.body.appendChild(script);
}
52 changes: 13 additions & 39 deletions js/dinosaur/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//main.js
(function () {
console.log(globalSelectedCharacter);
const SPEED_SCALE = 0.00001;
Expand Down Expand Up @@ -98,21 +97,21 @@
case 'Escape':
if (!isPaused) {
pauseGame();
playPauseSound(); // μΌμ‹œ 정지 μ†Œλ¦¬ μž¬μƒ
playSound('pauseSound');
} else {
resumeGame();
}
break;
case 'ArrowUp':
if (isPaused) {
selectButton(-1);
playMenuMoveSound(); // 메뉴 이동 μ†Œλ¦¬ μž¬μƒ
playSound('menuMoveSound');
}
break;
case 'ArrowDown':
if (isPaused) {
selectButton(1);
playMenuMoveSound(); // 메뉴 이동 μ†Œλ¦¬ μž¬μƒ
playSound('menuMoveSound');
}
break;
case 'Space':
Expand Down Expand Up @@ -147,7 +146,7 @@

if (checkGameOver()) {
pauseBackgroundMusic();
playObstacleHitSound();
playSound('obstacleHitSound');
return handleGameOver();
}

Expand Down Expand Up @@ -214,7 +213,7 @@
gameoverMessage.classList.remove('hide');
}, 100);

playGameOverSound(); // κ²Œμž„ μ˜€λ²„ μ†Œλ¦¬ μž¬μƒ
playSound('gameOverSound');
}

/* HANDLING CSS PROPERTIES */
Expand Down Expand Up @@ -337,7 +336,7 @@
isJumping = true;

if (!isPaused) {
playJumpSound(); // κ²Œμž„ 쀑일 λ•Œλ§Œ 점프 μ†Œλ¦¬ μž¬μƒ
playSound('jumpSound');
}
}

Expand Down Expand Up @@ -393,24 +392,18 @@

/* ADD AUDIO */

function playJumpSound() {
const jumpSound = document.getElementById('jumpSound');
jumpSound.currentTime = 0;
jumpSound.play();
}

function playBackgroundMusic() {
if (!isGameOver) {
const backgroundMusic = document.getElementById('backgroundMusic');
backgroundMusic.currentTime = 0; // λ°°κ²½μŒμ•…μ„ 처음으둜 되감음
backgroundMusic.play(); // λ°°κ²½μŒμ•… μž¬μƒ
backgroundMusic.currentTime = 0;
backgroundMusic.play();
}
}

function resumeBackgroundMusic() {
if (!isGameOver) {
const backgroundMusic = document.getElementById('backgroundMusic');
backgroundMusic.play(); // λ°°κ²½μŒμ•… μž¬μƒ
backgroundMusic.play();
}
}

Expand All @@ -419,28 +412,9 @@
backgroundMusic.pause();
}

function playMenuMoveSound() {
// 메뉴 이동 μ†Œλ¦¬λ₯Ό μž¬μƒν•˜λŠ” ν•¨μˆ˜
const menuMoveSound = document.getElementById('menuMoveSound');
menuMoveSound.currentTime = 0;
menuMoveSound.play();
}

function playGameOverSound() {
const gameOverSound = document.getElementById('gameOverSound');
gameOverSound.currentTime = 0;
gameOverSound.play();
}

function playObstacleHitSound() {
const obstacleHitSound = document.getElementById('obstacleHitSound');
obstacleHitSound.currentTime = 0;
obstacleHitSound.play();
}

function playPauseSound() {
const pauseSound = document.getElementById('pauseSound');
pauseSound.currentTime = 0;
pauseSound.play();
function playSound(soundId) {
const sound = document.getElementById(soundId);
sound.currentTime = 0;
sound.play();
}
})();

0 comments on commit abc8ac8

Please sign in to comment.