Skip to content

Added my entry to the site #159

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 3 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 @@ -21,6 +21,13 @@ const entries = [
author: "Christopher Powroznik (Metroxe)",
github: "Metroxe"
},
{
title: "Shape Dodge Frenzy",
filename: "shape-dodge-frenzy.html",
description: "A cool and simple game where you(a shape) try to dodge other falling shapes.",
author: "Abhi (d2crashout)",
github: "d2crashout"
},
{
title: "Ant Colony",
filename: "ant_colony.html",
Expand Down
136 changes: 136 additions & 0 deletions entries/shape-dodge-frenzy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!-- Cool game yay -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shape Dodge Frenzy</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #ff7e5f, #feb47b);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
color: white;
}
canvas {
border: 3px solid white;
display: block;
background: #1d1f21;
}
#scoreboard {
position: absolute;
top: 10px;
left: 10px;
font-size: 1.5rem;
}
</style>
</head>
<body>
<div id="scoreboard">
🏆 Score: <span id="score">0</span>
</div>
<canvas id="gameCanvas"></canvas>

<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 600;
canvas.height = 400;

// Game variables
let player = { x: 280, y: 370, width: 40, height: 20, speed: 5 };
let shapes = [];
let score = 0;
let gameRunning = true;

// Generate random falling shapes
function createShape() {
const size = Math.random() * 30 + 10;
shapes.push({
x: Math.random() * (canvas.width - size),
y: -size,
size: size,
color: `hsl(${Math.random() * 360}, 80%, 60%)`,
speed: Math.random() * 3 + 2,
});
}

// Game loop functions
function update() {
if (!gameRunning) return;

// Move shapes
shapes.forEach(shape => {
shape.y += shape.speed;
});

// Remove shapes that go off the screen
shapes = shapes.filter(shape => shape.y <= canvas.height);

// Check for collisions
shapes.forEach(shape => {
if (
player.x < shape.x + shape.size &&
player.x + player.width > shape.x &&
player.y < shape.y + shape.size &&
player.y + player.height > shape.y
) {
// Collision detected
gameRunning = false;
alert(`Game Over! Final Score: ${score}`);
document.location.reload();
}
});

// Update score
score++;
document.getElementById('score').innerText = score;
}

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

// Draw player
ctx.fillStyle = 'deepskyblue';
ctx.fillRect(player.x, player.y, player.width, player.height);

// Draw shapes
shapes.forEach(shape => {
ctx.fillStyle = shape.color;
ctx.fillRect(shape.x, shape.y, shape.size, shape.size);
});
}

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

// Handle player movement
window.addEventListener('keydown', e => {
if (e.code === 'ArrowLeft' && player.x > 0) {
player.x -= player.speed;
} else if (e.code === 'ArrowRight' && player.x < canvas.width - player.width) {
player.x += player.speed;
}
});

// Start game
setInterval(createShape, 1000); // Spawn shapes every second
gameLoop();
</script>
</body>
</html>