"滚动跳跃"听起来就很带感:玩家控制一个小角色,不断在屏幕上奔跑,通过跳跃来避开滚动而来的障碍物。障碍物越来越快、越来越多,你的反应速度就是唯一的生存法则。
如果放在以前,要写这样一款小游戏可没那么轻松------障碍物的滚动算法、跳跃物理曲线、碰撞检测、速度递增逻辑、UI 动画 ......都得自己写。 可现在,用 Trae IDE,所有这些逻辑一句话就能生成。
💡 我想要的玩法
这次我的设想很直接:
- 滚动的障碍物:各种方块、石头从右边滚来,速度要逐渐变快。
- 精准的跳跃:玩家点击或按空格,就能让角色跳跃,跳跃高度自然。
- 碰撞即结束:一旦被障碍物撞上,游戏立刻结束,简单粗暴。
- 节奏感强:背景轻快,操作直观,适合"想玩两分钟打发时间"的人。
于是我在 Trae 输入:
"生成一个滚动跳跃游戏,玩家控制角色跳跃,避开滚动的障碍物。"

✨ Trae 怎么生成
几秒钟后,Trae 就直接生成了一个能马上玩的小游戏:
✅ 角色跳跃逻辑 :点击或按空格,小角色自然弹起,落地后还能马上接下一个跳跃。 ✅ 障碍物滚动系统 :各种形状的障碍物会随机生成,从右边滚来,还会越来越快。 ✅ 碰撞检测 :只要角色碰到障碍物,游戏瞬间结束,并弹出"再来一局"的提示。 ✅ 简洁 UI:干净的背景、小巧的角色、流畅的动画,清晰易懂,看着就想点开玩一局。

🧩 试玩体验
试玩的第一分钟我就感受到那种"街机式的紧张":
🎮 障碍物缓慢滚来 ,一开始我跳得轻松; ⚠ 速度越来越快 ,障碍物一波接一波,我开始慌张乱点; 💥 不小心撞到方块 ,屏幕闪红,Game Over,瞬间想重来一把。
这种 简单、直接、上瘾 的感觉,正是小游戏的精髓。
🛠 想加点料?一句话就够
Trae 的魔力在于,任何想法都能随时追加,比如:
- "加个双跳功能" → 允许连续跳两次,能越过更高的障碍。
- "加入金币" → 跳过障碍时还能顺便收集金币加分。
- "让障碍物有不同类型" → 有的方块能跳,有的必须躲,让玩法更丰富。
- "加一个背景音乐" → 随着速度加快,音乐节奏也越来越紧张。

Trae 会自动补全这些逻辑,游戏体验直接升级。
🎮 开发小游戏的"新常态"
过去要做这种小游戏,流程是这样的:
- 手写物理跳跃曲线;
- 写障碍物随机生成逻辑;
- 调整碰撞检测范围;
- 再慢慢美化 UI、调试体验。
不仅麻烦,而且费时间。
而现在有 Trae: 👉 说一句话 → 游戏立刻可玩; 👉 想改玩法 → 再说一句话,逻辑就自动补上。
从敲代码变成了 **"给游戏发指令"**,轻松又高效。
✅ 结语
如果你也想做一款"考验反应速度"的小游戏,打开 Trae,只要输入:
"生成一个滚动跳跃游戏,玩家控制角色跳跃,避开滚动的障碍物。"
几秒后,一个完整的小游戏就能跑起来:角色跳跃自然、障碍物滚动流畅,节奏感十足,还能随时扩展新玩法。
这就是 Trae 的魅力 ------ 让写游戏像玩游戏一样简单又有趣。
html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>滚动跳跃游戏</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
.game-container {
position: relative;
width: 800px;
height: 400px;
background: linear-gradient(to bottom, #87CEEB, #e0e0e0);
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.score-container {
position: absolute;
top: 20px;
left: 20px;
background-color: rgba(255, 255, 255, 0.7);
padding: 10px 15px;
border-radius: 5px;
font-size: 18px;
font-weight: bold;
color: #333;
z-index: 10;
}
.player {
position: absolute;
width: 50px;
height: 50px;
background-color: #4CAF50;
border-radius: 5px;
bottom: 50px;
left: 100px;
z-index: 5;
transition: transform 0.1s;
}
.player-running {
animation: run 0.4s infinite alternate;
}
@keyframes run {
0% { transform: translateY(0); }
100% { transform: translateY(-5px); }
}
.player-jumping {
animation: none;
}
.ground {
position: absolute;
width: 100%;
height: 50px;
background: linear-gradient(to bottom, #8B4513, #654321);
bottom: 0;
z-index: 2;
}
.obstacle {
position: absolute;
background-color: #FF5722;
z-index: 3;
bottom: 50px;
}
.obstacle-small {
width: 30px;
height: 30px;
border-radius: 5px;
}
.obstacle-tall {
width: 30px;
height: 60px;
border-radius: 5px;
}
.obstacle-long {
width: 60px;
height: 30px;
border-radius: 5px;
}
.cloud {
position: absolute;
background-color: rgba(255, 255, 255, 0.8);
border-radius: 50px;
z-index: 1;
}
.game-over {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 20;
display: none;
}
.game-over-title {
font-size: 48px;
font-weight: bold;
color: white;
margin-bottom: 20px;
text-align: center;
}
.final-score {
font-size: 36px;
color: white;
margin-bottom: 30px;
text-align: center;
}
.restart-button {
padding: 15px 30px;
font-size: 20px;
font-weight: bold;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.restart-button:hover {
background-color: #45a049;
transform: scale(1.05);
}
.start-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 20;
}
.start-screen-title {
font-size: 48px;
font-weight: bold;
color: white;
margin-bottom: 20px;
text-align: center;
}
.start-screen-subtitle {
font-size: 24px;
color: white;
margin-bottom: 30px;
text-align: center;
max-width: 80%;
line-height: 1.4;
}
.start-button {
padding: 15px 30px;
font-size: 20px;
font-weight: bold;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.start-button:hover {
background-color: #45a049;
transform: scale(1.05);
}
</style>
</head>
<body>
<div class="game-container" id="game-container">
<div class="score-container">
分数: <span id="score">0</span>
</div>
<div class="player" id="player"></div>
<div class="ground"></div>
<div class="game-over" id="game-over">
<div class="game-over-title">游戏结束</div>
<div class="final-score">最终得分: <span id="final-score">0</span></div>
<button class="restart-button" id="restart-button">再玩一次</button>
</div>
<div class="start-screen" id="start-screen">
<div class="start-screen-title">滚动跳跃游戏</div>
<div class="start-screen-subtitle">按空格键或点击屏幕让角色跳跃,避开滚动的障碍物。</div>
<button class="start-button" id="start-button">开始游戏</button>
</div>
</div>
<script>
// 游戏元素
const gameContainer = document.getElementById('game-container');
const player = document.getElementById('player');
const scoreElement = document.getElementById('score');
const gameOver = document.getElementById('game-over');
const finalScore = document.getElementById('final-score');
const restartButton = document.getElementById('restart-button');
const startScreen = document.getElementById('start-screen');
const startButton = document.getElementById('start-button');
// 游戏配置
const containerWidth = gameContainer.offsetWidth;
const containerHeight = gameContainer.offsetHeight;
const playerWidth = 50;
const playerHeight = 50;
const groundHeight = 50;
const gravity = 1;
const jumpStrength = -15;
const obstacleSpeed = 5;
const obstacleGenerationInterval = 1500; // 毫秒
// 游戏状态
let playerY = containerHeight - groundHeight - playerHeight;
let playerVelocityY = 0;
let isJumping = false;
let score = 0;
let obstacles = [];
let clouds = [];
let gameRunning = false;
let gameLoop;
let obstacleInterval;
let scoreInterval;
let difficultyInterval;
let currentObstacleSpeed = obstacleSpeed;
// 初始化游戏
function initGame() {
// 隐藏开始屏幕
startScreen.style.display = 'none';
// 重置游戏状态
playerY = containerHeight - groundHeight - playerHeight;
playerVelocityY = 0;
isJumping = false;
score = 0;
obstacles = [];
currentObstacleSpeed = obstacleSpeed;
// 清除所有障碍物
const existingObstacles = document.querySelectorAll('.obstacle');
existingObstacles.forEach(obstacle => obstacle.remove());
// 更新显示
scoreElement.textContent = score;
player.style.bottom = `${groundHeight}px`;
player.classList.add('player-running');
player.classList.remove('player-jumping');
// 创建云朵背景
createClouds();
// 开始游戏循环
gameRunning = true;
gameLoop = setInterval(updateGame, 16); // 约60帧每秒
// 开始生成障碍物
obstacleInterval = setInterval(generateObstacle, obstacleGenerationInterval);
// 开始计分
scoreInterval = setInterval(() => {
if (gameRunning) {
score++;
scoreElement.textContent = score;
}
}, 100);
// 随着时间增加难度
difficultyInterval = setInterval(() => {
if (gameRunning && currentObstacleSpeed < 15) {
currentObstacleSpeed += 0.5;
}
}, 10000); // 每10秒增加一次难度
}
// 创建云朵背景
function createClouds() {
// 清除现有云朵
const existingClouds = document.querySelectorAll('.cloud');
existingClouds.forEach(cloud => cloud.remove());
// 创建新云朵
for (let i = 0; i < 5; i++) {
const cloud = document.createElement('div');
cloud.className = 'cloud';
const width = Math.random() * 100 + 50;
const height = width / 2;
const x = Math.random() * containerWidth;
const y = Math.random() * (containerHeight / 2);
cloud.style.width = `${width}px`;
cloud.style.height = `${height}px`;
cloud.style.left = `${x}px`;
cloud.style.top = `${y}px`;
cloud.style.opacity = Math.random() * 0.5 + 0.3;
gameContainer.appendChild(cloud);
clouds.push({
element: cloud,
x: x,
speed: Math.random() * 0.5 + 0.2
});
}
}
// 生成障碍物
function generateObstacle() {
if (!gameRunning) return;
const obstacle = document.createElement('div');
obstacle.className = 'obstacle';
// 随机选择障碍物类型
const obstacleType = Math.floor(Math.random() * 3);
let obstacleWidth, obstacleHeight;
if (obstacleType === 0) {
// 小型障碍物
obstacle.classList.add('obstacle-small');
obstacleWidth = 30;
obstacleHeight = 30;
} else if (obstacleType === 1) {
// 高型障碍物
obstacle.classList.add('obstacle-tall');
obstacleWidth = 30;
obstacleHeight = 60;
} else {
// 长型障碍物
obstacle.classList.add('obstacle-long');
obstacleWidth = 60;
obstacleHeight = 30;
}
obstacle.style.width = `${obstacleWidth}px`;
obstacle.style.height = `${obstacleHeight}px`;
obstacle.style.left = `${containerWidth}px`;
obstacle.style.bottom = `${groundHeight}px`;
gameContainer.appendChild(obstacle);
obstacles.push({
element: obstacle,
x: containerWidth,
width: obstacleWidth,
height: obstacleHeight,
passed: false
});
}
// 更新游戏状态
function updateGame() {
if (!gameRunning) return;
// 更新玩家位置
if (isJumping) {
playerVelocityY += gravity;
playerY += playerVelocityY;
// 检查是否落地
if (playerY >= containerHeight - groundHeight - playerHeight) {
playerY = containerHeight - groundHeight - playerHeight;
isJumping = false;
playerVelocityY = 0;
player.classList.add('player-running');
player.classList.remove('player-jumping');
}
player.style.bottom = `${containerHeight - playerY - playerHeight}px`;
}
// 更新障碍物位置
obstacles.forEach((obstacle, index) => {
obstacle.x -= currentObstacleSpeed;
obstacle.element.style.left = `${obstacle.x}px`;
// 检查碰撞
if (!obstacle.passed &&
obstacle.x < 100 + playerWidth &&
obstacle.x + obstacle.width > 100 &&
containerHeight - playerY - playerHeight < groundHeight + obstacle.height) {
endGame();
return;
}
// 移除屏幕外的障碍物
if (obstacle.x + obstacle.width < 0) {
obstacle.element.remove();
obstacles.splice(index, 1);
}
});
// 移动云朵
clouds.forEach(cloud => {
cloud.x -= cloud.speed;
if (cloud.x + parseInt(cloud.element.style.width) < 0) {
cloud.x = containerWidth;
}
cloud.element.style.left = `${cloud.x}px`;
});
}
// 玩家跳跃
function jump() {
if (!isJumping && gameRunning) {
isJumping = true;
playerVelocityY = jumpStrength;
player.classList.remove('player-running');
player.classList.add('player-jumping');
}
}
// 结束游戏
function endGame() {
gameRunning = false;
clearInterval(gameLoop);
clearInterval(obstacleInterval);
clearInterval(scoreInterval);
clearInterval(difficultyInterval);
// 显示游戏结束界面
gameOver.style.display = 'flex';
document.getElementById('final-score').textContent = score;
}
// 键盘控制
document.addEventListener('keydown', (e) => {
if (e.code === 'Space' || e.key === ' ') {
jump();
e.preventDefault(); // 防止空格键滚动页面
}
});
// 触摸控制(移动设备)
gameContainer.addEventListener('touchstart', () => {
jump();
});
// 鼠标控制
gameContainer.addEventListener('click', () => {
jump();
});
// 事件监听
restartButton.addEventListener('click', () => {
gameOver.style.display = 'none';
initGame();
});
startButton.addEventListener('click', () => {
initGame();
});
</script>
</body>
</html>