-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2196 from Niraj1608/mariogame
- Loading branch information
Showing
8 changed files
with
173 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,21 @@ | ||
### Game-Mario-Jump | ||
|
||
This Mario-inspired game requires you to press the spacebar to make Mario jump and avoid colliding with passing pipes. | ||
|
||
### Technologies Used: | ||
<div style="display: inline_block"> | ||
<img align="center" alt="JavaScript" height="30" width="40" src="https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-plain.svg"> | ||
<img align="center" alt="HTML" height="30" width="40" src="https://raw.githubusercontent.com/devicons/devicon/master/icons/html5/html5-original.svg"> | ||
<img align="center" alt="CSS" height="30" width="40" src="https://raw.githubusercontent.com/devicons/devicon/master/icons/css3/css3-original.svg"> | ||
</div> | ||
|
||
### Project Images: | ||
<div> | ||
<img width="300px" src="https://i.imgur.com/1bUH48J.png" alt="Game image" > | ||
<img width="300px" src="https://i.imgur.com/a0xz4kI.png" alt="Game image" > | ||
</div> | ||
|
||
<br> | ||
|
||
### Project Link: | ||
[https://niraj1608.github.io/Game-Mario/](https://niraj1608.github.io/Game-Mario/) |
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,87 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
.game-board{ | ||
width: 100%; | ||
height: 500px; | ||
border-bottom: 15px solid #049c18; | ||
margin: 0 auto; | ||
position: relative; | ||
overflow: hidden; | ||
background: linear-gradient(#87ceeb, #e0f6ff); | ||
} | ||
|
||
.pipe{ | ||
position: absolute; | ||
bottom: 0; | ||
width: 80px; | ||
animation: pipe-animation 2s infinite linear; | ||
} | ||
|
||
.mario{ | ||
width: 150px; | ||
position: absolute; | ||
bottom: 0; | ||
|
||
} | ||
|
||
.jump{ | ||
animation: jump 500ms ease-out; | ||
} | ||
|
||
.clouds{ | ||
position: absolute; | ||
width: 550px; | ||
animation: clouds-animation 20s infinite linear; | ||
} | ||
|
||
@keyframes clouds-animation { | ||
from{ | ||
right: -550px; | ||
} | ||
|
||
to{ | ||
right: 100%; | ||
} | ||
} | ||
|
||
@keyframes pipe-animation { | ||
from{ | ||
right: -80px; | ||
} | ||
|
||
to{ | ||
right: 100%; | ||
} | ||
} | ||
|
||
@keyframes jump { | ||
|
||
0%{ | ||
bottom: 0; | ||
} | ||
|
||
40%{ | ||
bottom: 180px; | ||
} | ||
|
||
50%{ | ||
bottom: 180px; | ||
} | ||
|
||
60%{ | ||
bottom: 180px; | ||
} | ||
|
||
100%{ | ||
bottom: 0; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Mario jump</title> | ||
|
||
<link rel="stylesheet" href="./css/style.css"> | ||
<script src="./js/script.js" defer></script> | ||
</head> | ||
<body> | ||
|
||
<div class="game-board"> | ||
<img src="./images/clouds.png" class="clouds"> | ||
<img src="./images/mario.gif" class="mario"> | ||
<img src="./images/pipe.png" class="pipe"> | ||
</div> | ||
|
||
</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,46 @@ | ||
const mario = document.querySelector('.mario'); | ||
const pipe = document.querySelector('.pipe'); | ||
const clouds = document.querySelector('.clouds'); | ||
|
||
const jump = () => { | ||
mario.classList.add('jump'); | ||
|
||
setTimeout(()=> { | ||
|
||
mario.classList.remove('jump'); | ||
|
||
}, 500) | ||
} | ||
|
||
const loop = setInterval(() => { | ||
|
||
|
||
const cloudsPosition = clouds.offsetLeft; | ||
const pipePosition = pipe.offsetLeft; | ||
const marioPosition = +window.getComputedStyle(mario).bottom.replace('px', ''); | ||
|
||
if (pipePosition <= 120 && pipePosition > 0 && marioPosition < 80) { | ||
|
||
pipe.style.animation = 'none'; | ||
pipe.style.left = `${pipePosition}px`; | ||
|
||
mario.style.animation = 'none'; | ||
mario.style.bottom = `${marioPosition}px`; | ||
|
||
mario.src = './images/game-over.png'; | ||
mario.style.width = '75px'; | ||
mario.style.marginLeft = '50px'; | ||
|
||
clouds.style.animation = 'none'; | ||
clouds.style.left = `${cloudsPosition}px`; | ||
|
||
clearInterval(loop); | ||
|
||
} | ||
|
||
}, 10); | ||
|
||
|
||
|
||
|
||
document.addEventListener('keydown', jump); |