Skip to content
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
16 changes: 16 additions & 0 deletions Awesome Javascript Projects_Scripts/Flying-Ostrich-Game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en" onclick="jump()">
<head>
<meta charset="UTF-8" />
<title>Flying Ostrich!</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="game">
<div id="block"></div>
<div id="hole"></div>
<div id="character"></div>
</div>
</body>
<script src="script.js"></script>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Awesome Javascript Projects_Scripts/Flying-Ostrich-Game/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var block = document.getElementById('block');
var hole = document.getElementById('hole');
var character = document.getElementById('character');
var jumping = 0;
var counter = 0;

hole.addEventListener('animationiteration', () => {
var random = -(Math.random() * 300 + 150);
hole.style.top = random + 'px';
counter++;
});
setInterval(function () {
var characterTop = parseInt(
window.getComputedStyle(character).getPropertyValue('top')
);
if (jumping == 0) {
character.style.top = characterTop + 3 + 'px';
}
var blockLeft = parseInt(
window.getComputedStyle(block).getPropertyValue('left')
);
var holeTop = parseInt(window.getComputedStyle(hole).getPropertyValue('top'));
var cTop = -(500 - characterTop);
if (
characterTop > 480 ||
(blockLeft < 20 &&
blockLeft > -50 &&
(cTop < holeTop || cTop > holeTop + 130))
) {
alert('Game over. Score: ' + (counter - 1));
character.style.top = 100 + 'px';
counter = 0;
}
}, 10);

function jump() {
jumping = 1;
let jumpCount = 0;
var jumpInterval = setInterval(function () {
var characterTop = parseInt(
window.getComputedStyle(character).getPropertyValue('top')
);
if (characterTop > 6 && jumpCount < 15) {
character.style.top = characterTop - 5 + 'px';
}
if (jumpCount > 20) {
clearInterval(jumpInterval);
jumping = 0;
jumpCount = 0;
}
jumpCount++;
}, 10);
}
45 changes: 45 additions & 0 deletions Awesome Javascript Projects_Scripts/Flying-Ostrich-Game/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
* {
padding: 0;
margin: 0;
}
#game {
width: 400px;
height: 500px;
border: 1px solid black;
margin: auto;
overflow: hidden;
}
#block {
width: 50px;
height: 500px;
background-color: green;
position: relative;
left: 400px;
animation: block 2s infinite linear;
}
@keyframes block {
0% {
left: 400px;
}
100% {
left: -50px;
}
}
#hole {
width: 50px;
height: 150px;
background-color: white;
position: relative;
left: 400px;
top: -500px;
animation: block 2s infinite linear;
}
#character {
width: 50px;
height: 50px;
position: absolute;
background-image: url('ostrich.jpeg');
background-size: contain;
top: 100px;
border-radius: 50%;
}