Entwickle in einer einzigen html datei ein browser game. dieses soll den nötigen html, css und js code beinhalten.
das design soll modern und minimalistisch mit gradients, transparent, liquid glass, animationen, etc. aussehen.
Das spiel selber soll immer wieder spielbar sein, also nicht nach leveln aufgebaut sein und einen großen spaßfaktor bieten. was genau es für ein game ist, ist dir überlassen.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Hier findest du eine vollständige HTML-Datei, die ein modernes, minimalistisches Browser-Game in einem einzigen Dokument implementiert. Das Spiel heißt "Circle Dodger": Du steuerst einen leuchtenden Kreis am unteren Bildschirmrand mit den Pfeiltasten (oder A/D) und musst herabfallenden Hindernissen ausweichen. Das Spiel ist endlos spielbar – bei einem Zusammenstoß erscheint eine Game‑Over-Meldung mit der Möglichkeit, per Leertaste neu zu starten.
Speichere den folgenden Code in einer HTML-Datei (z. B. index.html) und öffne sie in deinem Browser:
html
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Circle Dodger</title>
<style>
/* Globaler Body-Stil mit Gradient */
body {
margin: 0;
padding: 0;
background: linear-gradient(135deg, #6e8efb, #a777e3);
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* Container mit Liquid-Glass-Effekt */
.game-container {
position: relative;
padding: 20px;
border-radius: 20px;
background: rgba(255, 255, 255, 0.1);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
/* Canvas mit abgerundeten Ecken */
canvas {
display: block;
border-radius: 20px;
}
/* Score-Anzeige */
#score {
position: absolute;
top: 20px;
left: 20px;
color: #fff;
font-size: 24px;
font-weight: bold;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
user-select: none;
pointer-events: none;
}
/* Game Over-Overlay */
#gameOver {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 36px;
text-align: center;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
display: none;
user-select: none;
pointer-events: none;
}
</style>
</head>
<body>
<div class="game-container">
<canvas id="gameCanvas" width="400" height="600"></canvas>
<div id="score">0</div>
<div id="gameOver">Game Over<br>Drücke Leertaste zum Neustart</div>
</div>
<script>
(function() {
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
const scoreElement = document.getElementById("score");
const gameOverElement = document.getElementById("gameOver");
const width = canvas.width;
const height = canvas.height;
let gameSpeed = 2;
let obstacles = [];
let obstacleInterval = 1500; // Interval in Millisekunden
let lastObstacleTime = 0;
let score = 0;
let animationFrameId;
let gameOver = false;
// Spieler-Objekt: Ein Kreis
const player = {
x: width / 2,
y: height - 50,
radius: 15,
color: "rgba(255, 255, 255, 0.9)",
speed: 5,
movingLeft: false,
movingRight: false,
update: function() {
if (this.movingLeft) this.x -= this.speed;
if (this.movingRight) this.x += this.speed;
// Begrenzung am Canvas-Rand
if (this.x - this.radius < 0) this.x = this.radius;
if (this.x + this.radius > width) this.x = width - this.radius;
},
draw: function() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fillStyle = this.color;
ctx.fill();
ctx.closePath();
}
};
// Hindernisse als Rechtecke
class Obstacle {
constructor(x, y, w, h, speed, color) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
this.speed = speed;
this.color = color;
}
update() {
this.y += this.speed;
}
draw() {
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, this.width, this.height);
}
}
// Resetet den Spielzustand
function resetGame() {
obstacles = [];
score = 0;
gameSpeed = 2;
lastObstacleTime = performance.now();
player.x = width / 2;
gameOver = false;
gameOverElement.style.display = "none";
}
// Kollision zwischen Kreis und Rechteck
function collision(circle, rect) {
let distX = Math.abs(circle.x - rect.x - rect.width / 2);
let distY = Math.abs(circle.y - rect.y - rect.height / 2);
if (distX > (rect.width / 2 + circle.radius)) return false;
if (distY > (rect.height / 2 + circle.radius)) return false;
if (distX <= (rect.width / 2)) return true;
if (distY <= (rect.height / 2)) return true;
let dx = distX - rect.width / 2;
let dy = distY - rect.height / 2;
return (dx * dx + dy * dy <= (circle.radius * circle.radius));
}
// Die Haupt-Game-Loop
function update(time) {
if (gameOver) return;
ctx.clearRect(0, 0, width, height);
// Spieler aktualisieren und zeichnen
player.update();
player.draw();
// Neue Hindernisse basierend auf der Zeit erzeugen
if (time - lastObstacleTime > obstacleInterval) {
const obsWidth = 40 + Math.random() * 30;
const obsHeight = 20 + Math.random() * 20;
const obsX = Math.random() * (width - obsWidth);
obstacles.push(new Obstacle(obsX, -obsHeight, obsWidth, obsHeight, gameSpeed, "rgba(255, 255, 255, 0.7)"));
lastObstacleTime = time;
// Schwierigkeit erhöht sich allmählich
gameSpeed += 0.1;
}
// Hindernisse aktualisieren und zeichnen
for (let i = obstacles.length - 1; i >= 0; i--) {
const obs = obstacles[i];
obs.update();
obs.draw();
// Entferne Hindernisse, die aus dem Canvas verschwunden sind, und erhöhe den Score
if (obs.y > height) {
obstacles.splice(i, 1);
score += 1;
}
// Kollision prüfen
if (collision(player, obs)) {
gameOver = true;
gameOverElement.style.display = "block";
}
}
scoreElement.textContent = score;
animationFrameId = requestAnimationFrame(update);
}
// Event Listener für Tastatur-Eingaben
window.addEventListener("keydown", (e) => {
if (e.key === "ArrowLeft" || e.key.toLowerCase() === "a") {
player.movingLeft = true;
}
if (e.key === "ArrowRight" || e.key.toLowerCase() === "d") {
player.movingRight = true;
}
// Neustart bei Game Over
if (e.key === " " && gameOver) {
resetGame();
requestAnimationFrame(update);
}
});
window.addEventListener("keyup", (e) => {
if (e.key === "ArrowLeft" || e.key.toLowerCase() === "a") {
player.movingLeft = false;
}
if (e.key === "ArrowRight" || e.key.toLowerCase() === "d") {
player.movingRight = false;
}
});
// Spiel initialisieren
resetGame();
requestAnimationFrame(update);
})();
</script>
</body>
</html>
Erklärung zu einigen Design- und Code-Details:
Modernes Design:
Der Hintergrund verwendet einen sanften Farbverlauf, und der Container hat dank rgba-Werten, backdrop-filter und box-shadow einen Liquid Glass‑Effekt. Dadurch wirkt das Interface modern und minimalistisch.
Animation & Transparenz:
Die Animationen erfolgen über requestAnimationFrame in der JS-Game‑Loop, wodurch flüssige Bewegungen erzielt werden. Transparente Farben bei Spieler und Hindernissen sorgen für einen leichten, modernen Look.
Spielprinzip:
Anstatt an mehreren Levels vorbei zu führen, bleibt das Spiel endlos. Der Spieler sammelt Punkte, indem er Hindernissen ausweicht. Ein Zusammenstoß führt zur Game‑Over-Anzeige, wonach per Leertaste ein Neustart möglich ist.
Viel Spaß beim Ausprobieren und Weiterentwickeln des Spiels!