示例示例成品 · 不是你的AI 按示范写的,看个样子
==[代码]==
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>星星跳跃</title>
<style>
body { margin: 0; background: #222; display: flex; justify-content: center; align-items: center; height: 100vh; }
canvas { background: linear-gradient(#1a1a2e, #16213e); border: 2px solid #444; border-radius: 8px; }
</style>
</head>
<body>
<canvas id="game" width="400" height="600"></canvas>
<script>
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
let score = 0, gameOver = false;
const player = { x: 180, y: 500, w: 30, h: 30, vy: 0, speed: 5, jumpPower: -12, gravity: 0.5 };
const keys = {};
const platforms = [
{ x: 0, y: 580, w: 400, h: 20 }, // 地面
{ x: 50, y: 460, w: 80, h: 15 }, { x: 250, y: 370, w: 80, h: 15 },
{ x: 100, y: 270, w: 80, h: 15 }, { x: 280, y: 170, w: 80, h: 15 }
];
const stars = [{ x: 80, y: 430 }, { x: 280, y: 340 }, { x: 130, y: 240 }, { x: 310, y: 140 }];
// 监听键盘
window.addEventListener('keydown', e => keys[e.key] = true);
window.addEventListener('keyup', e => keys[e.key] = false);
function update() {
if (gameOver) return;
// 左右移动
if (keys['ArrowLeft'] && player.x > 0) player.x -= player.speed;
if (keys['Arro