diff --git a/Detona Ralph/Audios/hit.m4a b/Detona Ralph/Audios/hit.m4a new file mode 100644 index 0000000..d747823 Binary files /dev/null and b/Detona Ralph/Audios/hit.m4a differ diff --git a/Detona Ralph/Images/favicon.jpg b/Detona Ralph/Images/favicon.jpg new file mode 100644 index 0000000..8c5153a Binary files /dev/null and b/Detona Ralph/Images/favicon.jpg differ diff --git a/Detona Ralph/Images/player.png b/Detona Ralph/Images/player.png new file mode 100644 index 0000000..3d32071 Binary files /dev/null and b/Detona Ralph/Images/player.png differ diff --git a/Detona Ralph/Images/ralph.png b/Detona Ralph/Images/ralph.png new file mode 100644 index 0000000..e8e5b9d Binary files /dev/null and b/Detona Ralph/Images/ralph.png differ diff --git a/Detona Ralph/Images/wall.png b/Detona Ralph/Images/wall.png new file mode 100644 index 0000000..7e4216a Binary files /dev/null and b/Detona Ralph/Images/wall.png differ diff --git a/Detona Ralph/Scripts/engine.js b/Detona Ralph/Scripts/engine.js new file mode 100644 index 0000000..ac9cfdd --- /dev/null +++ b/Detona Ralph/Scripts/engine.js @@ -0,0 +1,68 @@ +const state = { + view: { + squares: document.querySelectorAll(".square"), + enemy: document.querySelector(".enemy"), + timeLeft: document.querySelector("#time-left"), + score: document.querySelector("#score"), + }, + + values: { + gameVelocity: 1000, + hitPosition: 0, + result: 0, + currentTime: 60, + }, + + actions:{ + timerId: setInterval(randomSquare,1000), + countDownTimerId: setInterval(countDown, 1000), + }, +}; + +function countDown(){ + state.values.currentTime--; + state.view.timeLeft.textContent = state.values.currentTime; + + if(state.values.currentTime <= 0){ + clearInterval(state.actions.countDownTimerId) + clearInterval(state.actions.timerId) + alert("Game Over! O seu resultado foi: " + state.values.result); + } +} + +function playSound (){ + let audio = new Audio("./Audios/hit.m4a"); + audio.volume = 0.2; + audio.play(); +} + +function randomSquare(){ + state.view.squares.forEach((square)=>{ + square.classList.remove("enemy"); + }); + + let randomNumber = Math.floor(Math.random() * 9); + let randomSquare = state.view.squares[randomNumber]; + randomSquare.classList.add("enemy"); + state.values.hitPosition = randomSquare.id; +} + + +function addListenerHitBox () { + state.view.squares.forEach((square) => { + square.addEventListener("mousedown", () => { + if(square.id === state.values.hitPosition){ + state.values.result++ + state.view.score.textContent = state.values.result; + state.values.hitPosition = null; + playSound(); + } + }); + }); +} + +function init() { + addListenerHitBox(); +} + +init (); \ No newline at end of file diff --git a/Detona Ralph/Styles/main.css b/Detona Ralph/Styles/main.css new file mode 100644 index 0000000..ade6aaa --- /dev/null +++ b/Detona Ralph/Styles/main.css @@ -0,0 +1,34 @@ +.container {display: flex; +flex-direction: column; +height: 100vh; +background-image: url(../Images/wall.png);} + +.menu {display: flex; + justify-content: space-evenly; + align-items: center; + + height: 90px; + width: 100%; + background-color: #000000; + color: #ffffff; + border-bottom: 5px solid #ffae00;} + +.panel {margin-top: 1rem; + display: flex; + align-items: center; + justify-content:center;} + +.square {height: 150px; + width: 150px; + background-color: #ffae00; +border: 1px solid #000000;} + +.enemy {background-image: url(../Images/ralph.png); +background-size: cover;} + +.menu-lives {display: flex; +align-items: center; +justify-content: center;} + +.menu-time h2:nth-child(2), +.menu-score h2:nth-child(2){margin-top: 1rem;} \ No newline at end of file diff --git a/Detona Ralph/Styles/reset.css b/Detona Ralph/Styles/reset.css new file mode 100644 index 0000000..31313ea --- /dev/null +++ b/Detona Ralph/Styles/reset.css @@ -0,0 +1,6 @@ +@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); + +* {font-family: 'Press Start 2P', serif; +margin: 0; +padding: 0; +box-sizing: border-box;} \ No newline at end of file diff --git a/Detona Ralph/index.html b/Detona Ralph/index.html new file mode 100644 index 0000000..707b7f2 --- /dev/null +++ b/Detona Ralph/index.html @@ -0,0 +1,50 @@ + + + + + + Detona Ralph + + + + + +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + \ No newline at end of file