<!DOCTYPE html>
<html lang="en" onclick="jump()">
<head>
<meta charset="UTF-8">
<title>Dinosaur game by SP :P</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="game">
<div id="dinosaur"></div>
<div id="cactus"></div>
</div>
<p>point: <span id="point"></span></p>
<canvas id="game" width="500" height="410"></canvas> <p>Click on screen to jump</p>
</body>
<script src="script.js"></script>
</html>
var dinosaur = document.getElementById("dinosaur");
var cactus = document.getElementById("block");
var counter=0;
function jump(){
dinosaur.classList.add("animate");
setTimeout(function(){
dinosaur.classList.remove
("animate");},300);
}
*{
padding: 0;
margin: 0;
overflow-x: hidden;
}
.game{
width: 500px;
height: 200px;
border: 1px solid black;
margin: auto;
}
#dinosaur{
width: 20px;
height: 50px;
background-color: #DC0A0A;
position:relative;
top: 150px;
}
.animate{
animation: jump 0.3s linear;
}
@keyframes jump{
0%{top: 150px;}
30%{top: 100px;}
70%{top: 100px;}
100%{top: 150px;}
}
#cactus{
background-color: #14920F;
width: 20px;
height: 20px;
position: relative;
top: 130px;
left: 500px;
animation: block 1s infinite linear;
}
@keyframes block{
0%{left: 500px}
100%{left: -20px}
}
p{
text-align: center;
}
<!DOCTYPE html>
<html lang="en" onclick="jump()">
<head>
<meta charset="UTF-8">
<title>Dinosaur game by SP :P</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="game">
<div id="dinosaur"></div>
<div id="cactus"></div>
</div>
<p>point: <span id="point"></span></p>
<canvas id="game" width="500" height="410"></canvas> <p>Click on screen to jump</p>
</body>
<script src="script.js"></script>
</html>
var dinosaur = document.getElementById("dinosaur");
var cactus = document.getElementById("block");
var counter=0;
function jump(){
dinosaur.classList.add("animate");
setTimeout(function(){
dinosaur.classList.remove
("animate");},300);
}
*{
padding: 0;
margin: 0;
overflow-x: hidden;
}
.game{
width: 500px;
height: 200px;
border: 1px solid black;
margin: auto;
}
#dinosaur{
width: 20px;
height: 50px;
background-color: #DC0A0A;
position:relative;
top: 150px;
}
.animate{
animation: jump 0.3s linear;
}
@keyframes jump{
0%{top: 150px;}
30%{top: 100px;}
70%{top: 100px;}
100%{top: 150px;}
}
#cactus{
background-color: #14920F;
width: 20px;
height: 20px;
position: relative;
top: 130px;
left: 500px;
animation: block 1s infinite linear;
}
@keyframes block{
0%{left: 500px}
100%{left: -20px}
}
p{
text-align: center;
}