initial vibecode lol

This commit is contained in:
2026-05-03 22:25:31 +02:00
commit a02592120e
4 changed files with 446 additions and 0 deletions

230
index.html Normal file
View File

@ -0,0 +1,230 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Frugger</title>
<style>
body { margin: 0; background: #222; overflow: hidden; }
canvas { display: block; margin: auto; background: #4aa3d8; }
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// --- Game state ---
let frog = { x: 0, y: 0, z: 0 };
let pads = [];
let currentPad = 0;
let charging = false;
let charge = 0;
let score = 0;
// --- Camera ---
let camera = { x: 0, y: 0 };
// --- Settings (adjusted) ---
const GRAVITY = 0.3; // lower gravity = slower fall
const MAX_CHARGE = 20;
const JUMP_POWER = 0.8; // higher arc
const HORIZONTAL_SCALE = 0.012; // slower forward movement
// --- Create lily pads ---
function generatePads() {
pads = [{ x: 0, y: 0 }];
for (let i = 1; i < 20; i++) {
pads.push({
x: pads[i-1].x + (Math.random() * 200 + 150),
y: pads[i-1].y + (Math.random() * 200 - 100)
});
}
}
generatePads();
// --- Reset frog ---
function resetFrog() {
frog.x = pads[currentPad].x;
frog.y = pads[currentPad].y;
frog.z = 0;
// center camera on current pad
camera.x = frog.x;
camera.y = frog.y;
}
resetFrog();
// --- Input ---
window.addEventListener("keydown", e => {
if (e.code === "Space") charging = true;
});
window.addEventListener("keyup", e => {
if (e.code === "Space") {
charging = false;
jump();
}
});
// --- Jump physics ---
let velocity = { x: 0, y: 0, z: 0 };
let jumping = false;
function jump() {
if (jumping) return;
const next = pads[currentPad + 1];
if (!next) return;
const dx = next.x - frog.x;
const dy = next.y - frog.y;
velocity.x = dx * charge * HORIZONTAL_SCALE;
velocity.y = dy * charge * HORIZONTAL_SCALE;
velocity.z = charge * JUMP_POWER;
jumping = true;
charge = 0;
}
// --- Update ---
function update() {
if (charging) {
charge += 0.3;
if (charge > MAX_CHARGE) charge = MAX_CHARGE;
}
if (jumping) {
frog.x += velocity.x;
frog.y += velocity.y;
frog.z += velocity.z;
velocity.z -= GRAVITY;
if (frog.z <= 0) {
frog.z = 0;
jumping = false;
checkLanding();
}
}
// smooth camera follow
camera.x += (pads[currentPad].x - camera.x) * 0.1;
camera.y += (pads[currentPad].y - camera.y) * 0.1;
}
// --- Landing check ---
function checkLanding() {
const next = pads[currentPad + 1];
if (!next) return;
const dist = Math.hypot(frog.x - next.x, frog.y - next.y);
if (dist < 40) {
currentPad++;
score += 10;
} else {
score -= 5;
}
resetFrog();
}
// --- Isometric projection with camera ---
function iso(x, y, z = 0) {
const sx = x - camera.x;
const sy = y - camera.y;
return {
x: canvas.width / 2 + (sx - sy),
y: canvas.height / 2 + (sx + sy) / 2 - z
};
}
// --- Draw lily pads ---
function drawPads() {
for (let i = 0; i < pads.length; i++) {
const p = iso(pads[i].x, pads[i].y);
ctx.fillStyle = i === currentPad ? "#2ecc71" : "#27ae60";
ctx.beginPath();
ctx.ellipse(p.x, p.y, 50, 25, 0, 0, Math.PI * 2);
ctx.fill();
}
}
// --- Draw frog ---
function drawFrog() {
const p = iso(frog.x, frog.y, frog.z);
ctx.fillStyle = "lime";
ctx.beginPath();
ctx.arc(p.x, p.y - 10, 15, 0, Math.PI * 2);
ctx.fill();
}
// --- Trajectory preview ---
function drawTrajectory() {
if (!charging || jumping) return;
const next = pads[currentPad + 1];
if (!next) return;
const dx = next.x - frog.x;
const dy = next.y - frog.y;
let vx = dx * charge * HORIZONTAL_SCALE;
let vy = dy * charge * HORIZONTAL_SCALE;
let vz = charge * JUMP_POWER;
let tx = frog.x;
let ty = frog.y;
let tz = frog.z;
ctx.strokeStyle = "rgba(255,255,255,0.5)";
ctx.beginPath();
for (let i = 0; i < 40; i++) {
tx += vx;
ty += vy;
tz += vz;
vz -= GRAVITY;
if (tz < 0) break;
const p = iso(tx, ty, tz);
ctx.lineTo(p.x, p.y);
}
ctx.stroke();
}
// --- Draw score ---
function drawUI() {
ctx.fillStyle = "white";
ctx.font = "20px Arial";
ctx.fillText("Score: " + score, 20, 30);
}
// --- Main loop ---
function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
update();
drawPads();
drawTrajectory();
drawFrog();
drawUI();
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>