Skip to content

Added my code and added info on entries.js #158

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*/

const entries = [
{
title: "botblitz",
filename: "botblitz.html",
description: "A never ending war against bot's A Fast-paced robot battles await youc change mode play fast or or slow make a high score and challenge your friends to if they beat you no problem tell them you made the high score in hard mode or just beat them again(Currently only works in desktop)",
author: "JDot",
github: "JDot555"
},
{
title: "Dancing Man",
filename: "dancing_man.html",
Expand Down
307 changes: 307 additions & 0 deletions entries/botblitz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 0;
height: 100vh;
background-color: #222;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
color: #fff;
}

canvas {
background-color: #333;
border: 3px solid #fff;
display: block;
margin: auto;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
}

#gameModeButtons {
position: absolute;
display: flex;
justify-content: center;
bottom: 20px;
width: 100%;
gap: 10px;
}

.gameModeButton {
padding: 10px 20px;
background-color: #008CBA;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}

.gameModeButton:hover {
background-color: #005f80;
}

#pauseButton {
position: absolute;
top: 20px;
right: 20px;
padding: 10px;
background-color: #f00;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}

#resumeButton {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
justify-content: center;
align-items: center;
font-size: 24px;
color: white;
}
</style>
<title>2D Shooting Game</title>
</head>
<body>
<canvas id="gameCanvas"></canvas>
<button id="pauseButton" onclick="pauseGame()">Pause</button>
<div id="resumeButton" onclick="resumeGame()">Resume</div>
<div id="gameModeButtons">
<button class="gameModeButton" onclick="setGameMode('easy')">Easy</button>
<button class="gameModeButton" onclick="setGameMode('normal')">Normal</button>
<button class="gameModeButton" onclick="setGameMode('hard')">Hard</button>
</div>

<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");

canvas.width = 600;
canvas.height = 400;

const player = {
x: canvas.width / 2,
y: canvas.height - 30,
width: 30,
height: 30,
color: "#00F",
speed: 5,
lives: 7,
};

const bullets = [];
const targets = [];

let score = 0;
let highScore = localStorage.getItem("highScore") || 0;
let spawnChance = 0.1;
let speedMultiplier = 0.5;
let gamePaused = false;
let gameMode = 'easy';

const keys = {};

window.addEventListener("keydown", (e) => {
keys[e.key] = true;
if (e.key === " ") {
shoot();
}
});

window.addEventListener("keyup", (e) => {
keys[e.key] = false;
});

function setGameMode(mode) {
gameMode = mode;
switch (mode) {
case 'easy':
speedMultiplier = 3;
break;
case 'normal':
speedMultiplier = 5;
break;
case 'hard':
speedMultiplier = 7;
break;
default:
speedMultiplier = 3;
}
}

function drawPlayer() {
ctx.fillStyle = player.color;
ctx.fillRect(player.x - player.width / 2, player.y - player.height / 2, player.width, player.height);
}

function drawBullets() {
ctx.fillStyle = "#F00";
bullets.forEach(bullet => {
ctx.fillRect(bullet.x - bullet.width / 2, bullet.y - bullet.height / 2, bullet.width, bullet.height);
});
}

function drawTargets() {
ctx.fillStyle = "#0F0";
targets.forEach(target => {
ctx.fillRect(target.x - target.width / 2, target.y - target.height / 2, target.width, target.height);
});
}

function drawScore() {
ctx.fillStyle = "#FFF";
ctx.font = "20px Arial";
ctx.fillText("Score: " + score, 10, 30);
}

function drawLives() {
ctx.fillStyle = "#FFF";
ctx.font = "20px Arial";
ctx.fillText("Lives: " + player.lives, canvas.width / 2 - 40, 30);
}

function drawHighScore() {
ctx.fillStyle = "#FFF";
ctx.font = "20px Arial";
ctx.fillText("High Score: " + highScore, canvas.width - 180, 30);
}

function update() {
if (gamePaused) return;

if (keys["ArrowUp"] && player.y > player.height / 2) player.y -= player.speed;
if (keys["ArrowDown"] && player.y < canvas.height - player.height / 2) player.y += player.speed;
if (keys["ArrowLeft"] && player.x > player.width / 2) player.x -= player.speed;
if (keys["ArrowRight"] && player.x < canvas.width - player.width / 2) player.x += player.speed;

bullets.forEach(bullet => {
bullet.y -= bullet.speed;
});

targets.forEach(target => {
target.y += target.speed * speedMultiplier;

if (target.y + target.height / 2 > canvas.height) {
player.lives--;
if (player.lives <= 0) {
gameOver();
}
resetTarget(target);
}
});

bullets.forEach(bullet => {
targets.forEach(target => {
if (
bullet.x < target.x + target.width / 2 &&
bullet.x > target.x - target.width / 2 &&
bullet.y < target.y + target.height / 2 &&
bullet.y > target.y - target.height / 2
) {
bullets.splice(bullets.indexOf(bullet), 1);
score += 1;
resetTarget(target);
}
});
});
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawPlayer();
drawBullets();
drawTargets();
drawScore();
drawLives();
drawHighScore();
}

function resetTarget(target) {
target.y = -Math.random() * 100;
target.x = Math.random() * (canvas.width - target.width) + target.width / 2;
}

function gameOver() {
alert("Game Over!\nScore: " + score);
if (score > highScore) {
highScore = score;
localStorage.setItem("highScore", highScore);
}

score = 0;
player.lives = 7;
bullets.length = 0;
targets.length = 0;
spawnChance = 0.1;
speedMultiplier = 0.5;

for (let i = 0; i < 2; i++) {
targets.push({
x: Math.random() * canvas.width,
y: -Math.random() * 100,
width: 20,
height: 20,
speed: Math.random() * 0.5 + 0.1,
});
}
}

function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}

function shoot() {
bullets.push({
x: player.x,
y: player.y,
width: 10,
height: 10,
speed: 8,
});
}

function pauseGame() {
gamePaused = true;
resumeButton.style.display = "flex";
}

function resumeGame() {
gamePaused = false;
resumeButton.style.display = "none";
}

window.addEventListener("resize", () => {
canvas.width = 600;
canvas.height = 400;
});

for (let i = 0; i < 2; i++) {
targets.push({
x: Math.random() * canvas.width,
y: -Math.random() * 100,
width: 20,
height: 20,
speed: Math.random() * 0.5 + 0.1,
});
}

gameLoop();
</script>
</body>
</html>