Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicioei a funcionalidade de perca de vidas ao errar o enemy #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,53 @@

<head>

<!-- settings -->

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Detona Ralph</title>

<!-- fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Press+Start+2P&display=swap" rel="stylesheet">

<!-- styles -->
<link rel="stylesheet" href="./src/styles/reset.css">
<link rel="stylesheet" href="./src/styles/main.css">

</head>

<body>

<div class="container">
<div class="menu">
<div class="menu-time">
<h2 style="color: red;">Time Left</h2>
<h2 style="color: #ff0000;">Time Left</h2>
<h2 id="time-left">0</h2>
</div>
<div class="menu-score">
<h2 style="color: red;">Your Score</h2>
<h2 style="color: #ff0000;">Your Score</h2>
<h2 id="score">0</h2>
</div>
<div class="menu-lives">
<img src="./src/images/player.png" alt="foto do jogador" height="60px" />
<h2>x3</h2>
<div class="menu-lives">
<h2 style="color: #ff0000;">:</h2>
<h2 id="lives">x3</h2>
</div>



</div>
</div>

<div class="panel">
<div class="panel-row">
<div class="square " id="1"></div>
<div class="square enemy" id="1"></div>
<div class="square" id="2"></div>
<div class="square" id="3"></div>
</div>

<div class="panel-row">
<div class="square enemy" id="4"></div>
<div class="square" id="4"></div>
<div class="square" id="5"></div>
<div class="square" id="6"></div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,20 @@ Este jogo foi desenvolvido como parte de um projeto educacional da Digital Innov
---

Divirta-se jogando o **JSGame Detona Ralph** enquanto explora as técnicas modernas de desenvolvimento de jogos em JavaScript. Lembre-se de conferir o repositório original [aqui](https://github.com/digitalinnovationone/jsgame-detona-ralph) e deixar uma ⭐️ se você gostou do projeto!








### Funcionalidade criada por Ruan cyplayker

[Meu github](https://github.com/Cyplayker)



### Adicionei a funcionalidade de perca de vidas quando erra o quadrado

<img src="./src/images/ralph2.png" /><br><br>
Binary file added src/images/ralph2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions src/scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,43 @@ const state = {
enemy: document.querySelector(".enemy"),
timeLeft: document.querySelector("#time-left"),
score: document.querySelector("#score"),
lives: document.querySelector("#lives"),
},

values: {
gameVelocity: 1000,
hitPosition: 0,
result: 0,
curretTime: 60,
lives: 3,
},
actions: {
timerId: setInterval(randomSquare, 1000),
countDownTimerId: setInterval(countDown, 1000),
},
};

function loseLife() {
state.values.lives--;
state.view.lives.textContent = "x" + state.values.lives;

if (state.values.lives <= 0) {
gameOver();
}
}

function gameOver() {
clearInterval(state.actions.countDownTimerId);
clearInterval(state.actions.timerId);
alert("Game Over! Sua pontuação foi: " + state.values.result);
}

function countDown() {
state.values.curretTime--;
state.view.timeLeft.textContent = state.values.curretTime;

if (state.values.curretTime <= 0) {
clearInterval(state.actions.countDownTimerId);
clearInterval(state.actions.timerId);
alert("Game Over! O seu resultado foi: " + state.values.result);
gameOver();
}
}

Expand Down Expand Up @@ -53,6 +69,8 @@ function addListenerHitBox() {
state.view.score.textContent = state.values.result;
state.values.hitPosition = null;
playSound("hit");
} else {
loseLife();
}
});
});
Expand Down