-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add project Code-space- jump-game project (#287)
add project code-space-jump-game-project. issue no. here: closes #283 ## Email id used to regsiter for VSoc'24 Email id : [email protected] ## Description add project code-space-jump-game-project ## Type of PR - [ ] Bug fix - [ x] Feature enhancement - [ x] Documentation update - [ x] Security enhancement - [ ] Other (specify): _______________ check in issue by entering [X] in boxes ## Screenshots / Videos (if applicable) https://github.com/user-attachments/assets/28b1bada-2d12-4164-9283-80d95fe61220 [Attach any relevant screenshots or videos demonstrating the changes] ## Checklist - [x ] I have performed a self-review of my code. - [x ] I have read and followed the Contribution Guidelines. - [x ] I have tested the changes thoroughly before submitting this pull request. - [x ] I have provided relevant issue numbers, screenshots, and videos after making the changes. - [ x] I have commented my code, particularly in hard-to-understand areas. - [ x] I have followed the code style guidelines of this project. - [ x] I have checked for any existing open issues that my pull request may address. - [ x] I have ensured that my changes do not break any existing functionality. - [ x] Each contributor is allowed to create a maximum of 4 issues per day. This helps us manage and address issues efficiently. - [ x] I have read the resources for guidance listed below. - [ x] I have followed security best practices in my code changes. check in issue by entering [X] in boxes ## Additional Context [Include any additional information or context that might be helpful for reviewers.] ## Contribution Guidelines Thank you for considering contributing to our project! To ensure smooth collaboration and effective contribution management, please adhere to the following guidelines: ### Issue Creation 1. **Limit on Issues:** - Each contributor is allowed to create a maximum of **4 issues per day**. This helps us manage and address issues efficiently. ### Contribution Levels 2. **Basic Contributions:** - This project is primarily focused on documentation. Most of the setup has been completed, so contributors will generally need to work on basic code tasks, such as writing tests. - For these tasks, issues will be assigned the **Easy** label. 3. **Acknowledging Hard Work:** - If a contributor puts in significant effort on a task, the issue will be upgraded to **Medium**. This is our way of recognizing and appreciating extra effort. 4. **Feature Additions and Component Work:** - Contributors working on new features or components using JSX/TSX will be assigned a level based on the complexity and quality of their work. - The more complex and valuable the contribution, the higher the level assigned. ### Level Definitions - **Easy:** - Tasks are straightforward, such as fixing minor bugs, writing tests, or making simple documentation updates. - **Medium:** - Tasks require more effort, such as addressing complex bugs, improving existing features, or making substantial documentation improvements. - **Hard:** - Tasks are highly complex and involve significant new feature development, major refactoring, or extensive contributions to the project’s core components. We look forward to your contributions and appreciate your effort in helping us improve the project!
- Loading branch information
Showing
9 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport", content="width=device-width, initial-scale=1.0"> | ||
<title>Doodle Jump</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src="script.js"></script> | ||
</head> | ||
<body> | ||
<canvas id="board"></canvas> | ||
</body> | ||
</html> |
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,217 @@ | ||
//board | ||
let board; | ||
let boardWidth = 360; | ||
let boardHeight = 576; | ||
let context; | ||
|
||
//doodler | ||
let doodlerWidth = 46; | ||
let doodlerHeight = 46; | ||
let doodlerX = boardWidth/2 - doodlerWidth/2; | ||
let doodlerY = boardHeight*7/8 - doodlerHeight; | ||
let doodlerRightImg; | ||
let doodlerLeftImg; | ||
|
||
let doodler = { | ||
img : null, | ||
x : doodlerX, | ||
y : doodlerY, | ||
width : doodlerWidth, | ||
height : doodlerHeight | ||
} | ||
|
||
//physics | ||
let velocityX = 0; | ||
let velocityY = 0; //doodler jump speed | ||
let initialVelocityY = -8; //starting velocity Y | ||
let gravity = 0.4; | ||
|
||
//platforms | ||
let platformArray = []; | ||
let platformWidth = 60; | ||
let platformHeight = 18; | ||
let platformImg; | ||
|
||
let score = 0; | ||
let maxScore = 0; | ||
let gameOver = false; | ||
|
||
window.onload = function() { | ||
board = document.getElementById("board"); | ||
board.height = boardHeight; | ||
board.width = boardWidth; | ||
context = board.getContext("2d"); //used for drawing on the board | ||
|
||
//draw doodler | ||
// context.fillStyle = "green"; | ||
// context.fillRect(doodler.x, doodler.y, doodler.width, doodler.height); | ||
|
||
//load images | ||
doodlerRightImg = new Image(); | ||
doodlerRightImg.src = "./doodler-right.png"; | ||
doodler.img = doodlerRightImg; | ||
doodlerRightImg.onload = function() { | ||
context.drawImage(doodler.img, doodler.x, doodler.y, doodler.width, doodler.height); | ||
} | ||
|
||
doodlerLeftImg = new Image(); | ||
doodlerLeftImg.src = "./doodler-left.png"; | ||
|
||
platformImg = new Image(); | ||
platformImg.src = "./platform.png"; | ||
|
||
velocityY = initialVelocityY; | ||
placePlatforms(); | ||
requestAnimationFrame(update); | ||
document.addEventListener("keydown", moveDoodler); | ||
} | ||
|
||
function update() { | ||
requestAnimationFrame(update); | ||
if (gameOver) { | ||
return; | ||
} | ||
context.clearRect(0, 0, board.width, board.height); | ||
|
||
//doodler | ||
doodler.x += velocityX; | ||
if (doodler.x > boardWidth) { | ||
doodler.x = 0; | ||
} | ||
else if (doodler.x + doodler.width < 0) { | ||
doodler.x = boardWidth; | ||
} | ||
|
||
velocityY += gravity; | ||
doodler.y += velocityY; | ||
if (doodler.y > board.height) { | ||
gameOver = true; | ||
} | ||
context.drawImage(doodler.img, doodler.x, doodler.y, doodler.width, doodler.height); | ||
|
||
//platforms | ||
for (let i = 0; i < platformArray.length; i++) { | ||
let platform = platformArray[i]; | ||
if (velocityY < 0 && doodler.y < boardHeight*3/4) { | ||
platform.y -= initialVelocityY; //slide platform down | ||
} | ||
if (detectCollision(doodler, platform) && velocityY >= 0) { | ||
velocityY = initialVelocityY; //jump | ||
} | ||
context.drawImage(platform.img, platform.x, platform.y, platform.width, platform.height); | ||
} | ||
|
||
// clear platforms and add new platform | ||
while (platformArray.length > 0 && platformArray[0].y >= boardHeight) { | ||
platformArray.shift(); //removes first element from the array | ||
newPlatform(); //replace with new platform on top | ||
} | ||
|
||
//score | ||
updateScore(); | ||
context.fillStyle = "black"; | ||
context.font = "16px sans-serif"; | ||
context.fillText(score, 5, 20); | ||
|
||
if (gameOver) { | ||
context.fillText("Game Over: Press 'Space' to Restart", boardWidth/7, boardHeight*7/8); | ||
} | ||
} | ||
|
||
function moveDoodler(e) { | ||
if (e.code == "ArrowRight" || e.code == "KeyD") { //move right | ||
velocityX = 4; | ||
doodler.img = doodlerRightImg; | ||
} | ||
else if (e.code == "ArrowLeft" || e.code == "KeyA") { //move left | ||
velocityX = -4; | ||
doodler.img = doodlerLeftImg; | ||
} | ||
else if (e.code == "Space" && gameOver) { | ||
//reset | ||
doodler = { | ||
img : doodlerRightImg, | ||
x : doodlerX, | ||
y : doodlerY, | ||
width : doodlerWidth, | ||
height : doodlerHeight | ||
} | ||
|
||
velocityX = 0; | ||
velocityY = initialVelocityY; | ||
score = 0; | ||
maxScore = 0; | ||
gameOver = false; | ||
placePlatforms(); | ||
} | ||
} | ||
|
||
function placePlatforms() { | ||
platformArray = []; | ||
|
||
//starting platforms | ||
let platform = { | ||
img : platformImg, | ||
x : boardWidth/2, | ||
y : boardHeight - 50, | ||
width : platformWidth, | ||
height : platformHeight | ||
} | ||
|
||
platformArray.push(platform); | ||
|
||
// platform = { | ||
// img : platformImg, | ||
// x : boardWidth/2, | ||
// y : boardHeight - 150, | ||
// width : platformWidth, | ||
// height : platformHeight | ||
// } | ||
// platformArray.push(platform); | ||
|
||
for (let i = 0; i < 6; i++) { | ||
let randomX = Math.floor(Math.random() * boardWidth*3/4); //(0-1) * boardWidth*3/4 | ||
let platform = { | ||
img : platformImg, | ||
x : randomX, | ||
y : boardHeight - 75*i - 150, | ||
width : platformWidth, | ||
height : platformHeight | ||
} | ||
|
||
platformArray.push(platform); | ||
} | ||
} | ||
|
||
function newPlatform() { | ||
let randomX = Math.floor(Math.random() * boardWidth*3/4); //(0-1) * boardWidth*3/4 | ||
let platform = { | ||
img : platformImg, | ||
x : randomX, | ||
y : -platformHeight, | ||
width : platformWidth, | ||
height : platformHeight | ||
} | ||
|
||
platformArray.push(platform); | ||
} | ||
|
||
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 | ||
} | ||
|
||
function updateScore() { | ||
let points = Math.floor(50*Math.random()); //(0-1) *50 --> (0-50) | ||
if (velocityY < 0) { //negative going up | ||
maxScore += points; | ||
if (score < maxScore) { | ||
score = maxScore; | ||
} | ||
} | ||
else if (velocityY >= 0) { | ||
maxScore -= points; | ||
} | ||
} |
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,8 @@ | ||
body { | ||
text-align: center; | ||
} | ||
|
||
#board { | ||
/* background-color: green; */ | ||
background-image: url("./doodlejumpbg.png"); | ||
} |
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