-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a86ea9
commit a92046c
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Jump Game</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="game"> | ||
<div id="character"></div> | ||
<div id="block"></div> | ||
</div> | ||
<div id="score">Score: 0</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var character = document.getElementById("character"); | ||
document.addEventListener("click", jump); | ||
var score = 0; | ||
var scoreDiv = document.getElementById("score"); | ||
|
||
function jump(){ | ||
if(character.classList == "animate"){return;} | ||
character.classList.add("animate"); | ||
setTimeout(removeJump,300); | ||
}; | ||
function removeJump(){ | ||
character.classList.remove("animate"); | ||
} | ||
|
||
var block = document.getElementById("block"); | ||
|
||
function updateScore(){ | ||
score++; | ||
scoreDiv.innerHTML = "Score: " + score; | ||
} | ||
|
||
function checkDead(){ | ||
let characterTop = parseInt(window.getComputedStyle(character).getPropertyValue("top")); | ||
let blockLeft = parseInt(window.getComputedStyle(block).getPropertyValue("left")); | ||
if(blockLeft<20 && blockLeft>-20 && characterTop>=130){ | ||
alert("Game over"); | ||
}else if(blockLeft<20 && blockLeft>-20){ | ||
updateScore(); | ||
} | ||
} | ||
|
||
setInterval(checkDead, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#game{ | ||
width: 500px; | ||
height: 200px; | ||
border: 1px solid black; | ||
margin: auto; | ||
} | ||
|
||
#character{ | ||
width: 20px; | ||
height: 50px; | ||
background-color: red; | ||
position: relative; | ||
top: 150px; | ||
} | ||
|
||
@keyframes jump{ | ||
0%{top: 150px;} | ||
30%{top: 100px;} | ||
70%{top: 100px;} | ||
100%{top: 150px;} | ||
} | ||
|
||
.animate{ | ||
animation: jump 300ms linear; | ||
} | ||
|
||
#block{ | ||
width: 20px; | ||
height: 20px; | ||
background-color: blue; | ||
position: relative; | ||
top: 130px; | ||
left: 480px; | ||
animation: block 1s infinite linear; | ||
} | ||
|
||
@keyframes block{ | ||
0%{left: 500px} | ||
100%{left: -20px} | ||
} | ||
|
||
#score{ | ||
position: absolute; | ||
top: 10px; | ||
left: 10px; | ||
font-size: 20px; | ||
} |