diff --git a/Games/Chrome_Dino/README.md b/Games/Chrome_Dino/README.md new file mode 100644 index 0000000000..b109abf4ed --- /dev/null +++ b/Games/Chrome_Dino/README.md @@ -0,0 +1,31 @@ +# **Chrome_Dino** + +--- + +
+ +## **Description 📃** + +- This is the very famous google chrome dinosaur game! + +## **functionalities 🎮** + +- Easy +- Funny +- Interasting +
+ +## **How to play? 🕹ī¸** + +- Your aim is to protect your dino from the upcoming cactus and thundering clouds, you can easily control your dino with the help of arrow or space keys. +- The score keeps adding up on the basis of how far you have reached in the game. +- If you collide with any obstacle just refresh the site and game will be start again. + +
+ +## **Screenshots 📸** +![image](https://github.com/MitulSonagara/GameZone/assets/95460188/de368526-49e6-426b-9dcb-9a6eb156858f) + +
+ + diff --git a/Games/Chrome_Dino/dino.css b/Games/Chrome_Dino/dino.css new file mode 100644 index 0000000000..8e033733c9 --- /dev/null +++ b/Games/Chrome_Dino/dino.css @@ -0,0 +1,9 @@ +body { + font-family:'Courier New', Courier, monospace; + text-align: center; +} + +#board { + background-color: lightgray; + border-bottom: 1px solid black; +} diff --git a/Games/Chrome_Dino/dino.js b/Games/Chrome_Dino/dino.js new file mode 100644 index 0000000000..c0a22614d0 --- /dev/null +++ b/Games/Chrome_Dino/dino.js @@ -0,0 +1,167 @@ + +//board +let board; +let boardWidth = 750; +let boardHeight = 250; +let context; + +//dino +let dinoWidth = 88; +let dinoHeight = 94; +let dinoX = 50; +let dinoY = boardHeight - dinoHeight; +let dinoImg; + +let dino = { + x : dinoX, + y : dinoY, + width : dinoWidth, + height : dinoHeight +} + +//cactus +let cactusArray = []; + +let cactus1Width = 34; +let cactus2Width = 69; +let cactus3Width = 102; + +let cactusHeight = 70; +let cactusX = 700; +let cactusY = boardHeight - cactusHeight; + +let cactus1Img; +let cactus2Img; +let cactus3Img; + +//physics +let velocityX = -8; //cactus moving left speed +let velocityY = 0; +let gravity = .4; + +let gameOver = false; +let score = 0; + +window.onload = function() { + board = document.getElementById("board"); + board.height = boardHeight; + board.width = boardWidth; + + context = board.getContext("2d"); //used for drawing on the board + + //draw initial dinosaur + // context.fillStyle="green"; + // context.fillRect(dino.x, dino.y, dino.width, dino.height); + + dinoImg = new Image(); + dinoImg.src = "./img/dino.png"; + dinoImg.onload = function() { + context.drawImage(dinoImg, dino.x, dino.y, dino.width, dino.height); + } + + cactus1Img = new Image(); + cactus1Img.src = "./img/cactus1.png"; + + cactus2Img = new Image(); + cactus2Img.src = "./img/cactus2.png"; + + cactus3Img = new Image(); + cactus3Img.src = "./img/cactus3.png"; + + requestAnimationFrame(update); + setInterval(placeCactus, 1000); //1000 milliseconds = 1 second + document.addEventListener("keydown", moveDino); +} + +function update() { + requestAnimationFrame(update); + if (gameOver) { + return; + } + context.clearRect(0, 0, board.width, board.height); + + //dino + velocityY += gravity; + dino.y = Math.min(dino.y + velocityY, dinoY); //apply gravity to current dino.y, making sure it doesn't exceed the ground + context.drawImage(dinoImg, dino.x, dino.y, dino.width, dino.height); + + //cactus + for (let i = 0; i < cactusArray.length; i++) { + let cactus = cactusArray[i]; + cactus.x += velocityX; + context.drawImage(cactus.img, cactus.x, cactus.y, cactus.width, cactus.height); + + if (detectCollision(dino, cactus)) { + gameOver = true; + dinoImg.src = "./img/dino-dead.png"; + dinoImg.onload = function() { + context.drawImage(dinoImg, dino.x, dino.y, dino.width, dino.height); + } + } + } + + //score + context.fillStyle="black"; + context.font="20px courier"; + score++; + context.fillText(score, 5, 20); +} + +function moveDino(e) { + if (gameOver) { + return; + } + + if ((e.code == "Space" || e.code == "ArrowUp") && dino.y == dinoY) { + //jump + velocityY = -10; + } + else if (e.code == "ArrowDown" && dino.y == dinoY) { + //duck + } + +} + +function placeCactus() { + if (gameOver) { + return; + } + + //place cactus + let cactus = { + img : null, + x : cactusX, + y : cactusY, + width : null, + height: cactusHeight + } + + let placeCactusChance = Math.random(); //0 - 0.9999... + + if (placeCactusChance > .90) { //10% you get cactus3 + cactus.img = cactus3Img; + cactus.width = cactus3Width; + cactusArray.push(cactus); + } + else if (placeCactusChance > .70) { //30% you get cactus2 + cactus.img = cactus2Img; + cactus.width = cactus2Width; + cactusArray.push(cactus); + } + else if (placeCactusChance > .50) { //50% you get cactus1 + cactus.img = cactus1Img; + cactus.width = cactus1Width; + cactusArray.push(cactus); + } + + if (cactusArray.length > 5) { + cactusArray.shift(); //remove the first element from the array so that the array doesn't constantly grow + } +} + +function detectCollision(a, b) { + return a.x < b.x + b.width && //a's top left corner doesn't reach b's top right corner + a.x + a.width > b.x && //a's top right corner passes b's top left corner + a.y < b.y + b.height && //a's top left corner doesn't reach b's bottom left corner + a.y + a.height > b.y; //a's bottom left corner passes b's top left corner +} diff --git a/Games/Chrome_Dino/img/a.css b/Games/Chrome_Dino/img/a.css new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Games/Chrome_Dino/img/a.css @@ -0,0 +1 @@ + diff --git a/Games/Chrome_Dino/img/big-cactus1.png b/Games/Chrome_Dino/img/big-cactus1.png new file mode 100644 index 0000000000..2d266ba342 Binary files /dev/null and b/Games/Chrome_Dino/img/big-cactus1.png differ diff --git a/Games/Chrome_Dino/img/big-cactus2.png b/Games/Chrome_Dino/img/big-cactus2.png new file mode 100644 index 0000000000..88dc1c4137 Binary files /dev/null and b/Games/Chrome_Dino/img/big-cactus2.png differ diff --git a/Games/Chrome_Dino/img/big-cactus3.png b/Games/Chrome_Dino/img/big-cactus3.png new file mode 100644 index 0000000000..f3885d6572 Binary files /dev/null and b/Games/Chrome_Dino/img/big-cactus3.png differ diff --git a/Games/Chrome_Dino/img/bird1.png b/Games/Chrome_Dino/img/bird1.png new file mode 100644 index 0000000000..eb53e059b3 Binary files /dev/null and b/Games/Chrome_Dino/img/bird1.png differ diff --git a/Games/Chrome_Dino/img/bird2.png b/Games/Chrome_Dino/img/bird2.png new file mode 100644 index 0000000000..1135bb121d Binary files /dev/null and b/Games/Chrome_Dino/img/bird2.png differ diff --git a/Games/Chrome_Dino/img/cactus1.png b/Games/Chrome_Dino/img/cactus1.png new file mode 100644 index 0000000000..b1a57ed3d3 Binary files /dev/null and b/Games/Chrome_Dino/img/cactus1.png differ diff --git a/Games/Chrome_Dino/img/cactus2.png b/Games/Chrome_Dino/img/cactus2.png new file mode 100644 index 0000000000..e9608b1a57 Binary files /dev/null and b/Games/Chrome_Dino/img/cactus2.png differ diff --git a/Games/Chrome_Dino/img/cactus3.png b/Games/Chrome_Dino/img/cactus3.png new file mode 100644 index 0000000000..df890d2c20 Binary files /dev/null and b/Games/Chrome_Dino/img/cactus3.png differ diff --git a/Games/Chrome_Dino/img/cloud.png b/Games/Chrome_Dino/img/cloud.png new file mode 100644 index 0000000000..718d57ccaf Binary files /dev/null and b/Games/Chrome_Dino/img/cloud.png differ diff --git a/Games/Chrome_Dino/img/dino-dead.png b/Games/Chrome_Dino/img/dino-dead.png new file mode 100644 index 0000000000..0428237946 Binary files /dev/null and b/Games/Chrome_Dino/img/dino-dead.png differ diff --git a/Games/Chrome_Dino/img/dino-duck1.png b/Games/Chrome_Dino/img/dino-duck1.png new file mode 100644 index 0000000000..08ee8a448b Binary files /dev/null and b/Games/Chrome_Dino/img/dino-duck1.png differ diff --git a/Games/Chrome_Dino/img/dino-duck2.png b/Games/Chrome_Dino/img/dino-duck2.png new file mode 100644 index 0000000000..dabdc1a601 Binary files /dev/null and b/Games/Chrome_Dino/img/dino-duck2.png differ diff --git a/Games/Chrome_Dino/img/dino-jump.png b/Games/Chrome_Dino/img/dino-jump.png new file mode 100644 index 0000000000..8574c3961f Binary files /dev/null and b/Games/Chrome_Dino/img/dino-jump.png differ diff --git a/Games/Chrome_Dino/img/dino-run1.png b/Games/Chrome_Dino/img/dino-run1.png new file mode 100644 index 0000000000..048a631fd2 Binary files /dev/null and b/Games/Chrome_Dino/img/dino-run1.png differ diff --git a/Games/Chrome_Dino/img/dino-run2.png b/Games/Chrome_Dino/img/dino-run2.png new file mode 100644 index 0000000000..027fa673c6 Binary files /dev/null and b/Games/Chrome_Dino/img/dino-run2.png differ diff --git a/Games/Chrome_Dino/img/dino.png b/Games/Chrome_Dino/img/dino.png new file mode 100644 index 0000000000..8574c3961f Binary files /dev/null and b/Games/Chrome_Dino/img/dino.png differ diff --git a/Games/Chrome_Dino/img/game-over.png b/Games/Chrome_Dino/img/game-over.png new file mode 100644 index 0000000000..e1e6357bcd Binary files /dev/null and b/Games/Chrome_Dino/img/game-over.png differ diff --git a/Games/Chrome_Dino/img/reset.png b/Games/Chrome_Dino/img/reset.png new file mode 100644 index 0000000000..e7cf2e1c89 Binary files /dev/null and b/Games/Chrome_Dino/img/reset.png differ diff --git a/Games/Chrome_Dino/img/track.png b/Games/Chrome_Dino/img/track.png new file mode 100644 index 0000000000..b6a8857120 Binary files /dev/null and b/Games/Chrome_Dino/img/track.png differ diff --git a/Games/Chrome_Dino/index.html b/Games/Chrome_Dino/index.html new file mode 100644 index 0000000000..af5ce00d63 --- /dev/null +++ b/Games/Chrome_Dino/index.html @@ -0,0 +1,14 @@ + + + + + + Chrome Dinosaur Game + + + + +

Chrome Dinosaur Game

+ + + diff --git a/README.md b/README.md index 83eff7f26f..1fce3e1e16 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ This repository also provides one such platforms where contributers come over an | [Find Extra Cube](https://github.com/kunjgit/GameZone/tree/main/Games/Find_Extra_Cube) | [PathPlex](https://github.com/kunjgit/GameZone/tree/main/Games/Pathplex) | [CSS Select](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Select) | [Squid](https://github.com/kunjgit/GameZone/tree/main/Games/Squid_Game) | [CSS Crossword](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Crossword) | | [CSS Select](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Select) | [Squid](https://github.com/kunjgit/GameZone/tree/main/Games/Squid_Game) | [Flip Coin](https://github.com/kunjgit/GameZone/tree/main/Games/Flip_Coin) | [Witty Word Quest](https://github.com/kunjgit/GameZone/tree/main/Games/witty_word_quest) | [Typing Game](https://github.com/Ishan-77/GameZone/tree/main/Games/Typing_Game) | | [numeral-whiz](https://github.com/Ishan-77/GameZone/tree/main/Games/numeral-whiz) | [candy_match](https://github.com/kunjgit/GameZone/tree/main/Games/Candy_Match_Saga) | [Crossy_Road](https://github.com/tanujbordikar/GameZone/tree/Crossy_Road) | [HueHero](https://github.com/kunjgit/GameZone/tree/main/Games/HueHero) | [Puzzel_Winner](https://github.com/kunjgit/GameZone/tree/main/Games/Puzzel_Winner) | -| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | | | +| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) |[Chrome_Dino](https://github.com/kunjgit/GameZone/tree/main/Games/Chrome_Dino) | | diff --git a/assets/images/Chrome_Dino.png b/assets/images/Chrome_Dino.png new file mode 100644 index 0000000000..e09458d93d Binary files /dev/null and b/assets/images/Chrome_Dino.png differ