This model didn't return a displayable web page for this challenge.
View raw output
<!DOCTYPE html>
<html>
<head>
<title>Super Mario Bros. Level</title>
>
<style>
body {
margin: 0;
overflow: hidden;
background: #87CEEB;
font-family: 'Press Start 2P', system-ui, -apple-system, sans-serif;
}
#gameCanvas {
display: block;
margin: 0 auto;
background: #87CEEB;
}
#score {
position: absolute;
top: 20px;
left: 20px;
color: white;
font-size: 20px;
text-shadow: 2px 2px 0 #000;
}
#instructions {
position: absolute;
bottom: 20px;
left: 20px;
color: white;
font-size: 14px;
text-shadow: 1px 1px 0 #000;
}
</style>
>
</head>
<body<body>
<div id="score">SCORE: 0</div>
<div id="instructions">←→ TO MOVE | ↑ TO JUMP | REACH THE FLAG!!</div>
<canvas id="gameCanvas" width="800" height="600">"></canvas>
>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let score = 0;
const gravity = 0.5;
const friction = 0.8;
// Game objects
const mario = {
x: 50,
y: 450,
width: 40,
height: 60,
speed: 5,
velX: 0,
velY: 0,
grounded: false,
jumping: false,
color: '#FF0000'
};
const platforms = [
{ x: 0, y: 550, width: 800, height: 50, color: '#8B4513' }, // Ground
{ x: 200, y: 450, width: 100, height: 20, color: '#8B4513' }, // Platform 1
{ x: 400, y: 350, width: 100, height: 20, color: '#8B4513' }, // Platform 2
{ x: 600, y: 250, width: 100, height: 20, color: '#8B4513' } // Platform 3
];
const enemies = [
{ x: 250, y: 430, width: 30, height: 30, velX: 2, color: '#000000' },
{ x: 450, y: 330, width: 30, height: 30, velX: 2, color: '#000000' },
{ x: 650, y: 230, width: 30, height: 30, velX: 2, color: '#000000' }
];
const coins = [
{ x: 220, y: 430, width: 20, height: 20, collected: false, color: '#FFD700' },
{ x: 420, y: 330, width: 20, height: 20, collected: false, color: '#FFD700' },
{ x: 620, y: 230, width: 20, height: 20, collected: false, color: '#FFD700' }
];
const flag = { x: 700, y: 200, width: 30, height: 50, color: '#00FF00' };
// Input handling
const keys = {};
document.addEventListener('keydown', e => keys[e.key] = true);
document.addEventListener('keyup', e => keys[e.key] = false);
// Game loop
function gameLoop() {
// Clear canvas
ctx.fillStyle = '#87CEEB';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw clouds
drawClouds();
// Update Mario
updateMario();
// Update enemies
updateEnemies();
// Check collisions
checkCollisions();
// Draw game elements
drawGameElements();
requestAnimationFrame(gameLoop);
}
function updateMario() {
// Movement
if (keys['ArrowLeft']) mario.velX = -mario.speed;
if (keys['ArrowRight']) mario.velX = mario.speed;
if (keys['ArrowUp'] && mario.grounded) {
mario.velY = -12;
mario.grounded = false;
}
// Physics
mario.velX *= friction;
mario.velY += gravity;
mario.x += mario.velX;
mario.y += mario.velY;
// Boundaries
if (mario.x < 0) mario.x = 0;
if (mario.x + mario.width > canvas.width) mario.x = canvas.width - mario.width;
// Reset if fallen off
if (mario.y > canvas.height) {
mario.x = 50;
mario.y = 450;
mario.velY = 0;
}
// Platform collision
mario.grounded = false;
platforms.forEach(p => {
if (mario.x + mario.width > p.x &&
mario.x < p.x + p.width &&
mario.y + mario.height >= p.y &&
mario.y + mario.height <= p.y + 10 &&
mario.velY > 0) {
mario.grounded = true;
mario.y = p.y - mario.height;
mario.velY = 0;
}
});
}
function updateEnemies() {
enemies.forEach((e, index) => {
e.x += e.velX;
// Platform collision
platforms.forEach(p => {
if (e.x + e.width > p.x &&
e.x < p.x + p.width &&
e.y + e.height >= p.y &&
e.y + e.height <= p.y + 5) {
if (e.x <= p.x || e.x + e.width >= p.x + p.width) {
e.velX *= -1;
}
}
});
});
}
function checkCollisions() {
// Enemy collision
enemies.forEach((e, index) => {
if (mario.x + mario.width > e.x &&
mario.x < e.x + e.width &&
mario.y + mario.height > e.y &&
mario.y < e.y + e.height) {
if (mario.velY > 0 && mario.y + mario.height < e.y + e.height) {
enemies.splice(index, 1);
mario.velY = -10;
score += 20;
} else {
mario.x = 50;
mario.y = 450;
mario.velY = 0;
}
}
});
// Coin collection
coins.forEach(c => {
if (!c.collected &&
mario.x + mario.width > c.x &&
mario.x < c.x + c.width &&
mario.y + mario.height > c.y &&
mario.y < c.y + c.height) {
c.collected = true;
score += 10;
}
});
// Flag collision (win condition)
if (mario.x + mario.width > flag.x &&
mario.x < flag.x + flag.width &&
mario.y + mario.height > flag.y &&
mario.y < flag.y + flag.height) {
alert('YOU WIN!\nSCORE: ' + score + '');
resetGame();
}
// Update score display
document.getElementById('score').textContent = 'SCORE: ' + score + '';
}
function drawGameElements() {
// Draw platforms
platforms.forEach(p => {
ctx.fillStyle = p.color;
ctx.fillRect(p.x, p.y, p.width, p.height);
});
// Draw coins
coins.forEach(c => {
if (!c.collected) {
ctx.fillStyle = c.color;
ctx.beginPath();
ctx.arc(c.x + 10, c.y + 10, 10, 0, Math.PI * 2);
ctx.fill();
}
});
// Draw enemies
enemies.forEach(e => {
ctx.fillStyle = e.color;
ctx.fillRect(e.x, e.y, e.width, e.height);
// Draw eyes
ctx.fillStyle = 'white';
ctx.fillRect(e.x + 7, e.y + 8, 5, 5);
ctx.fillRect(e.x + 18, e.y + 8, 5, 5);
});
// Draw flag
ctx.fillStyle = flag.color;
ctx.fillRect(flag.x, flag.y, flag.width, flag.height);
// Flag pole
ctx.strokeStyle = '#654321';
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(flag.x, 250);
ctx.lineTo(flag.x, flag.y);
ctx.stroke();
// Draw Mario
ctx.fillStyle = mario.color;
ctx.fillRect(mario.x, mario.y, mario.width, mario.height);
// Mario eyes
ctx.fillStyle = 'white';
ctx.fillRect(mario.x + 10, mario.y + 15, 8, 8);
ctx.fillRect(mario.x + 22, mario.y + 15, 8, 8);
}
function drawClouds() {
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
// Cloud 1
ctx.beginPath();
ctx.arc(100, 100, 20, 0, Math.PI * 2);
ctx.arc(130, 90, 20, 0, Math.PI * 2);
ctx.arc(160, 100, 20, 0, Math.PI * 2);
ctx.fill();
// Cloud 2
ctx.beginPath();
ctx.arc(600, 150, 20, 0, Math.PI * 2);
ctx.arc(630, 140, 20, 0, Math.PI * 2);
ctx.arc(660, 150, 20, 0, Math.PI * 2);
ctx.fill();
}
function resetGame() {
mario.x = 50;
mario.y = 450;
mario.velY = 0;
coins.forEach(c => c.collected = false);
score = 0;
enemies.push(
{ x: 250, y: 430, width: 30, height: 30, velX: 2, color: '#000000' },
{ x: 450, y: 330, width: 30, height: 30, velX: 2, color: '#000000' },
{ x: 650, y: 230, width: 30, height: 30, velX: 2, color: '#000000' }
);
}
// Start game
gameLoop();
</script>
>
</body>
</htmlhtml>