Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sky Jumper Game #5079

Merged
merged 2 commits into from
Aug 4, 2024
Merged
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
31 changes: 31 additions & 0 deletions Games/Sky_Jumper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Sky Jumper Game

A simple 2D platformer game where the player jumps between platforms in a sky-themed environment. This game is built using HTML, CSS, and JavaScript.

## Overview

Sky Jumper is a basic web-based game where the player controls a character that can jump between floating platforms. It features:
- Gravity and jumping mechanics
- Basic platform collision detection
- Simple controls using arrow keys and the space bar

## Features

- **Player Movement**: Move left and right using arrow keys.
- **Jumping**: Jump using the space bar.
- **Platforms**: Jump between floating platforms in the sky.
- **Responsive Canvas**: Adjusts to the window size.

## Getting Started

### Prerequisites

No additional software is required other than a modern web browser.

### Setup

1. **Clone the Repository**

```bash
git clone <repository-url>
cd sky-jumper
88 changes: 88 additions & 0 deletions Games/Sky_Jumper/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');

canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

// Game variables
const playerWidth = 50;
const playerHeight = 50;
const platformWidth = 150;
const platformHeight = 20;
let playerX = canvas.width / 2 - playerWidth / 2;
let playerY = canvas.height - playerHeight - 100;
let playerSpeedX = 0;
let playerSpeedY = 0;
const gravity = 0.5;
const jumpPower = -10;
const moveSpeed = 5;

// Platforms
const platforms = [
{ x: 100, y: canvas.height - 50, width: platformWidth, height: platformHeight },
{ x: 300, y: canvas.height - 150, width: platformWidth, height: platformHeight },
{ x: 500, y: canvas.height - 250, width: platformWidth, height: platformHeight }
];

// Input
const keys = {};

// Event listeners
window.addEventListener('keydown', (e) => keys[e.code] = true);
window.addEventListener('keyup', (e) => keys[e.code] = false);

function update() {
// Player movement
if (keys['ArrowLeft']) playerSpeedX = -moveSpeed;
else if (keys['ArrowRight']) playerSpeedX = moveSpeed;
else playerSpeedX = 0;

if (keys['Space'] && onGround()) {
playerSpeedY = jumpPower;
}

playerSpeedY += gravity;
playerX += playerSpeedX;
playerY += playerSpeedY;

// Collision detection
if (playerY + playerHeight > canvas.height) {
playerY = canvas.height - playerHeight;
playerSpeedY = 0;
}

platforms.forEach(platform => {
if (playerX < platform.x + platform.width &&
playerX + playerWidth > platform.x &&
playerY + playerHeight > platform.y &&
playerY + playerHeight < platform.y + platform.height &&
playerSpeedY > 0) {
playerY = platform.y - playerHeight;
playerSpeedY = 0;
}
});

// Draw everything
draw();
requestAnimationFrame(update);
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);

// Draw player
ctx.fillStyle = 'red';
ctx.fillRect(playerX, playerY, playerWidth, playerHeight);

// Draw platforms
ctx.fillStyle = 'green';
platforms.forEach(platform => {
ctx.fillRect(platform.x, platform.y, platform.width, platform.height);
});
}

function onGround() {
return playerY + playerHeight >= canvas.height;
}

update();
15 changes: 15 additions & 0 deletions Games/Sky_Jumper/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sky Jumper Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="gameCanvasContainer">
<canvas id="gameCanvas"></canvas>
</div>
<script src="game.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions Games/Sky_Jumper/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #87CEEB; /* Sky blue */
}

#gameCanvasContainer {
position: relative;
width: 100vw;
height: 100vh;
}

canvas {
display: block;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ This repository also provides one such platforms where contributers come over an
|[Five_Nights_at_Freddys](https://github.com/kunjgit/GameZone/tree/main/Games/Five_Nights_at_Freddys)|
|[Snake_Gun_Water](https://github.com/kunjgit/GameZone/tree/main/Games/Snake_Gun_Water)|
|[Catch_The_Object](https://github.com/kunjgit/GameZone/tree/main/Games/Catch_The_Objects)|
|[Sky_Jumper](https://github.com/kunjgit/GameZone/tree/main/Games/Sky_Jumper)|
</center>

| Game | Game | Game | Game | Game |
Expand Down
Binary file added assets/images/Sky_Jumper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading