Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +884 -19
README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: plane-fighter-1
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
+
tags:
|
9 |
+
- deepsite
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
@@ -1,19 +1,884 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Sky Adventure - 飞行游戏</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
overflow: hidden;
|
12 |
+
touch-action: none;
|
13 |
+
}
|
14 |
+
#gameCanvas {
|
15 |
+
display: block;
|
16 |
+
background: linear-gradient(to bottom, #1e3c72 0%, #2a5298 100%);
|
17 |
+
}
|
18 |
+
.game-overlay {
|
19 |
+
position: absolute;
|
20 |
+
top: 0;
|
21 |
+
left: 0;
|
22 |
+
width: 100%;
|
23 |
+
height: 100%;
|
24 |
+
pointer-events: none;
|
25 |
+
}
|
26 |
+
.cloud {
|
27 |
+
position: absolute;
|
28 |
+
background-color: rgba(255, 255, 255, 0.8);
|
29 |
+
border-radius: 50%;
|
30 |
+
}
|
31 |
+
@keyframes float {
|
32 |
+
0% { transform: translateY(0px); }
|
33 |
+
50% { transform: translateY(-10px); }
|
34 |
+
100% { transform: translateY(0px); }
|
35 |
+
}
|
36 |
+
.plane {
|
37 |
+
animation: float 2s ease-in-out infinite;
|
38 |
+
}
|
39 |
+
.star {
|
40 |
+
position: absolute;
|
41 |
+
color: gold;
|
42 |
+
text-shadow: 0 0 10px yellow;
|
43 |
+
animation: twinkle 1s ease-in-out infinite alternate;
|
44 |
+
}
|
45 |
+
@keyframes twinkle {
|
46 |
+
from { opacity: 0.7; transform: scale(0.9); }
|
47 |
+
to { opacity: 1; transform: scale(1.1); }
|
48 |
+
}
|
49 |
+
.obstacle {
|
50 |
+
position: absolute;
|
51 |
+
background-color: #555;
|
52 |
+
border-radius: 5px;
|
53 |
+
}
|
54 |
+
.explosion {
|
55 |
+
position: absolute;
|
56 |
+
width: 60px;
|
57 |
+
height: 60px;
|
58 |
+
background: radial-gradient(circle, rgba(255,100,0,0.8) 0%, rgba(255,200,0,0.6) 50%, rgba(255,255,255,0) 70%);
|
59 |
+
border-radius: 50%;
|
60 |
+
animation: explode 0.5s ease-out forwards;
|
61 |
+
}
|
62 |
+
@keyframes explode {
|
63 |
+
0% { transform: scale(0); opacity: 1; }
|
64 |
+
100% { transform: scale(2); opacity: 0; }
|
65 |
+
}
|
66 |
+
.control-btn {
|
67 |
+
position: absolute;
|
68 |
+
width: 60px;
|
69 |
+
height: 60px;
|
70 |
+
background: rgba(255, 255, 255, 0.2);
|
71 |
+
border-radius: 50%;
|
72 |
+
display: flex;
|
73 |
+
align-items: center;
|
74 |
+
justify-content: center;
|
75 |
+
font-size: 24px;
|
76 |
+
color: white;
|
77 |
+
pointer-events: auto;
|
78 |
+
user-select: none;
|
79 |
+
-webkit-tap-highlight-color: transparent;
|
80 |
+
}
|
81 |
+
.control-btn:active {
|
82 |
+
background: rgba(255, 255, 255, 0.4);
|
83 |
+
transform: scale(0.95);
|
84 |
+
}
|
85 |
+
#leftBtn {
|
86 |
+
bottom: 30px;
|
87 |
+
left: 30px;
|
88 |
+
}
|
89 |
+
#rightBtn {
|
90 |
+
bottom: 30px;
|
91 |
+
left: 110px;
|
92 |
+
}
|
93 |
+
#upBtn {
|
94 |
+
bottom: 100px;
|
95 |
+
right: 30px;
|
96 |
+
}
|
97 |
+
#downBtn {
|
98 |
+
bottom: 30px;
|
99 |
+
right: 30px;
|
100 |
+
}
|
101 |
+
</style>
|
102 |
+
</head>
|
103 |
+
<body class="bg-gray-900 text-white flex flex-col items-center justify-center h-screen">
|
104 |
+
<div class="relative w-full h-full">
|
105 |
+
<canvas id="gameCanvas" class="w-full h-full"></canvas>
|
106 |
+
|
107 |
+
<!-- 开始界面 -->
|
108 |
+
<div id="startScreen" class="game-overlay flex flex-col items-center justify-center bg-black bg-opacity-70">
|
109 |
+
<h1 class="text-5xl font-bold mb-6 text-yellow-300">SKY ADVENTURE</h1>
|
110 |
+
<div class="plane text-6xl mb-8">✈️</div>
|
111 |
+
<p class="text-xl mb-8 text-center max-w-md px-4">控制飞机躲避障碍物<br>收集星星获得高分!</p>
|
112 |
+
<button id="startButton" class="bg-yellow-500 hover:bg-yellow-600 text-black font-bold py-3 px-8 rounded-full text-xl transition-all duration-300 transform hover:scale-105 pointer-events-auto">
|
113 |
+
开始游戏
|
114 |
+
</button>
|
115 |
+
<div class="mt-8 flex space-x-4">
|
116 |
+
<div class="flex items-center">
|
117 |
+
<i class="fas fa-arrow-up text-xl mr-2"></i>
|
118 |
+
<span>上升</span>
|
119 |
+
</div>
|
120 |
+
<div class="flex items-center">
|
121 |
+
<i class="fas fa-arrow-down text-xl mr-2"></i>
|
122 |
+
<span>下降</span>
|
123 |
+
</div>
|
124 |
+
<div class="flex items-center">
|
125 |
+
<i class="fas fa-arrow-left text-xl mr-2"></i>
|
126 |
+
<i class="fas fa-arrow-right text-xl"></i>
|
127 |
+
<span class="ml-2">转向</span>
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
</div>
|
131 |
+
|
132 |
+
<!-- 游戏UI -->
|
133 |
+
<div id="gameUI" class="game-overlay hidden">
|
134 |
+
<div class="absolute top-4 left-4 bg-black bg-opacity-50 px-4 py-2 rounded-lg">
|
135 |
+
<div class="flex items-center">
|
136 |
+
<i class="fas fa-star text-yellow-400 mr-2"></i>
|
137 |
+
<span id="scoreDisplay" class="text-xl">0</span>
|
138 |
+
</div>
|
139 |
+
</div>
|
140 |
+
<div class="absolute top-4 right-4 bg-black bg-opacity-50 px-4 py-2 rounded-lg">
|
141 |
+
<div class="flex items-center">
|
142 |
+
<i class="fas fa-heart text-red-500 mr-2"></i>
|
143 |
+
<span id="livesDisplay" class="text-xl">3</span>
|
144 |
+
</div>
|
145 |
+
</div>
|
146 |
+
<div class="absolute bottom-4 left-4 bg-black bg-opacity-50 px-4 py-2 rounded-lg">
|
147 |
+
<div class="flex items-center">
|
148 |
+
<i class="fas fa-tachometer-alt text-blue-400 mr-2"></i>
|
149 |
+
<span id="speedDisplay" class="text-xl">100</span>
|
150 |
+
<span class="ml-1">km/h</span>
|
151 |
+
</div>
|
152 |
+
</div>
|
153 |
+
|
154 |
+
<!-- 触摸控制按钮 -->
|
155 |
+
<div id="leftBtn" class="control-btn hidden">
|
156 |
+
<i class="fas fa-arrow-left"></i>
|
157 |
+
</div>
|
158 |
+
<div id="rightBtn" class="control-btn hidden">
|
159 |
+
<i class="fas fa-arrow-right"></i>
|
160 |
+
</div>
|
161 |
+
<div id="upBtn" class="control-btn hidden">
|
162 |
+
<i class="fas fa-arrow-up"></i>
|
163 |
+
</div>
|
164 |
+
<div id="downBtn" class="control-btn hidden">
|
165 |
+
<i class="fas fa-arrow-down"></i>
|
166 |
+
</div>
|
167 |
+
</div>
|
168 |
+
|
169 |
+
<!-- 游戏结束界面 -->
|
170 |
+
<div id="gameOverScreen" class="game-overlay hidden flex flex-col items-center justify-center bg-black bg-opacity-70">
|
171 |
+
<h1 class="text-5xl font-bold mb-6 text-red-500">GAME OVER</h1>
|
172 |
+
<div class="text-3xl mb-8">
|
173 |
+
得分: <span id="finalScore" class="text-yellow-400">0</span>
|
174 |
+
</div>
|
175 |
+
<button id="restartButton" class="bg-yellow-500 hover:bg-yellow-600 text-black font-bold py-3 px-8 rounded-full text-xl transition-all duration-300 transform hover:scale-105 pointer-events-auto">
|
176 |
+
再玩一次
|
177 |
+
</button>
|
178 |
+
</div>
|
179 |
+
</div>
|
180 |
+
|
181 |
+
<script>
|
182 |
+
// 游戏状态
|
183 |
+
const gameState = {
|
184 |
+
started: false,
|
185 |
+
gameOver: false,
|
186 |
+
score: 0,
|
187 |
+
lives: 3,
|
188 |
+
speed: 100,
|
189 |
+
plane: {
|
190 |
+
x: 0,
|
191 |
+
y: 0,
|
192 |
+
width: 60,
|
193 |
+
height: 60,
|
194 |
+
velocity: 0, // 左右方向速度
|
195 |
+
verticalVelocity: 0, // 上下方向速度
|
196 |
+
rotation: 0
|
197 |
+
},
|
198 |
+
stars: [],
|
199 |
+
obstacles: [],
|
200 |
+
clouds: [],
|
201 |
+
explosions: [],
|
202 |
+
lastStarTime: 0,
|
203 |
+
lastObstacleTime: 0,
|
204 |
+
lastCloudTime: 0,
|
205 |
+
keys: {
|
206 |
+
ArrowUp: false,
|
207 |
+
ArrowDown: false,
|
208 |
+
ArrowLeft: false,
|
209 |
+
ArrowRight: false
|
210 |
+
},
|
211 |
+
isMobile: false
|
212 |
+
};
|
213 |
+
|
214 |
+
// 获取DOM元素
|
215 |
+
const canvas = document.getElementById('gameCanvas');
|
216 |
+
const ctx = canvas.getContext('2d');
|
217 |
+
const startScreen = document.getElementById('startScreen');
|
218 |
+
const gameUI = document.getElementById('gameUI');
|
219 |
+
const gameOverScreen = document.getElementById('gameOverScreen');
|
220 |
+
const startButton = document.getElementById('startButton');
|
221 |
+
const restartButton = document.getElementById('restartButton');
|
222 |
+
const scoreDisplay = document.getElementById('scoreDisplay');
|
223 |
+
const livesDisplay = document.getElementById('livesDisplay');
|
224 |
+
const speedDisplay = document.getElementById('speedDisplay');
|
225 |
+
const finalScore = document.getElementById('finalScore');
|
226 |
+
const leftBtn = document.getElementById('leftBtn');
|
227 |
+
const rightBtn = document.getElementById('rightBtn');
|
228 |
+
const upBtn = document.getElementById('upBtn');
|
229 |
+
const downBtn = document.getElementById('downBtn');
|
230 |
+
|
231 |
+
// 检测是否移动设备
|
232 |
+
function detectMobile() {
|
233 |
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
234 |
+
}
|
235 |
+
|
236 |
+
// 设置画布大小
|
237 |
+
function resizeCanvas() {
|
238 |
+
canvas.width = window.innerWidth;
|
239 |
+
canvas.height = window.innerHeight;
|
240 |
+
if (gameState.started && !gameState.gameOver) {
|
241 |
+
gameState.plane.x = canvas.width / 2;
|
242 |
+
gameState.plane.y = canvas.height / 2;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
// 初始化���戏
|
247 |
+
function initGame() {
|
248 |
+
gameState.isMobile = detectMobile();
|
249 |
+
resizeCanvas();
|
250 |
+
gameState.started = true;
|
251 |
+
gameState.gameOver = false;
|
252 |
+
gameState.score = 0;
|
253 |
+
gameState.lives = 3;
|
254 |
+
gameState.speed = 100;
|
255 |
+
gameState.plane = {
|
256 |
+
x: canvas.width / 2,
|
257 |
+
y: canvas.height / 2,
|
258 |
+
width: 60,
|
259 |
+
height: 60,
|
260 |
+
velocity: 0,
|
261 |
+
verticalVelocity: 0,
|
262 |
+
rotation: 0
|
263 |
+
};
|
264 |
+
gameState.stars = [];
|
265 |
+
gameState.obstacles = [];
|
266 |
+
gameState.clouds = [];
|
267 |
+
gameState.explosions = [];
|
268 |
+
gameState.lastStarTime = 0;
|
269 |
+
gameState.lastObstacleTime = 0;
|
270 |
+
gameState.lastCloudTime = 0;
|
271 |
+
|
272 |
+
startScreen.classList.add('hidden');
|
273 |
+
gameOverScreen.classList.add('hidden');
|
274 |
+
gameUI.classList.remove('hidden');
|
275 |
+
|
276 |
+
// 显示触摸控制按钮(如果是移动设备)
|
277 |
+
if (gameState.isMobile) {
|
278 |
+
leftBtn.classList.remove('hidden');
|
279 |
+
rightBtn.classList.remove('hidden');
|
280 |
+
upBtn.classList.remove('hidden');
|
281 |
+
downBtn.classList.remove('hidden');
|
282 |
+
}
|
283 |
+
|
284 |
+
updateUI();
|
285 |
+
createInitialClouds();
|
286 |
+
requestAnimationFrame(gameLoop);
|
287 |
+
}
|
288 |
+
|
289 |
+
// 创建初始云朵
|
290 |
+
function createInitialClouds() {
|
291 |
+
for (let i = 0; i < 10; i++) {
|
292 |
+
createCloud(true);
|
293 |
+
}
|
294 |
+
}
|
295 |
+
|
296 |
+
// 创建云朵
|
297 |
+
function createCloud(initial = false) {
|
298 |
+
const size = Math.random() * 60 + 40;
|
299 |
+
const x = initial ? Math.random() * canvas.width : canvas.width + size;
|
300 |
+
const y = Math.random() * canvas.height;
|
301 |
+
const speed = Math.random() * 1 + 0.5;
|
302 |
+
|
303 |
+
gameState.clouds.push({
|
304 |
+
x,
|
305 |
+
y,
|
306 |
+
size,
|
307 |
+
speed,
|
308 |
+
parts: Array(3).fill().map(() => ({
|
309 |
+
size: size * (Math.random() * 0.3 + 0.7),
|
310 |
+
offsetX: (Math.random() - 0.5) * size * 0.6,
|
311 |
+
offsetY: (Math.random() - 0.5) * size * 0.6
|
312 |
+
}))
|
313 |
+
});
|
314 |
+
}
|
315 |
+
|
316 |
+
// 创建星星
|
317 |
+
function createStar() {
|
318 |
+
const size = Math.random() * 20 + 15;
|
319 |
+
const x = canvas.width + size;
|
320 |
+
const y = Math.random() * (canvas.height - size * 2) + size;
|
321 |
+
const speed = Math.random() * 3 + 3 + gameState.speed / 50;
|
322 |
+
|
323 |
+
gameState.stars.push({
|
324 |
+
x,
|
325 |
+
y,
|
326 |
+
size,
|
327 |
+
speed,
|
328 |
+
rotation: 0,
|
329 |
+
rotationSpeed: Math.random() * 0.1 - 0.05
|
330 |
+
});
|
331 |
+
}
|
332 |
+
|
333 |
+
// 创建障碍物
|
334 |
+
function createObstacle() {
|
335 |
+
const width = Math.random() * 80 + 40;
|
336 |
+
const height = Math.random() * 80 + 40;
|
337 |
+
const x = canvas.width + width;
|
338 |
+
const y = Math.random() * (canvas.height - height);
|
339 |
+
const speed = Math.random() * 2 + 2 + gameState.speed / 50;
|
340 |
+
const type = Math.random() > 0.5 ? 'rectangle' : 'circle';
|
341 |
+
|
342 |
+
gameState.obstacles.push({
|
343 |
+
x,
|
344 |
+
y,
|
345 |
+
width,
|
346 |
+
height,
|
347 |
+
speed,
|
348 |
+
type
|
349 |
+
});
|
350 |
+
}
|
351 |
+
|
352 |
+
// 创建爆炸效果
|
353 |
+
function createExplosion(x, y) {
|
354 |
+
gameState.explosions.push({
|
355 |
+
x,
|
356 |
+
y,
|
357 |
+
size: 0,
|
358 |
+
maxSize: Math.random() * 40 + 40,
|
359 |
+
alpha: 1
|
360 |
+
});
|
361 |
+
}
|
362 |
+
|
363 |
+
// 更新UI
|
364 |
+
function updateUI() {
|
365 |
+
scoreDisplay.textContent = gameState.score;
|
366 |
+
livesDisplay.textContent = gameState.lives;
|
367 |
+
speedDisplay.textContent = Math.floor(gameState.speed);
|
368 |
+
}
|
369 |
+
|
370 |
+
// 检测碰撞
|
371 |
+
function checkCollision(rect1, rect2) {
|
372 |
+
return (
|
373 |
+
rect1.x < rect2.x + rect2.width &&
|
374 |
+
rect1.x + rect1.width > rect2.x &&
|
375 |
+
rect1.y < rect2.y + rect2.height &&
|
376 |
+
rect1.y + rect1.height > rect2.y
|
377 |
+
);
|
378 |
+
}
|
379 |
+
|
380 |
+
// 游戏结束
|
381 |
+
function endGame() {
|
382 |
+
gameState.gameOver = true;
|
383 |
+
gameUI.classList.add('hidden');
|
384 |
+
gameOverScreen.classList.remove('hidden');
|
385 |
+
finalScore.textContent = gameState.score;
|
386 |
+
|
387 |
+
// 隐藏触摸控制按钮
|
388 |
+
leftBtn.classList.add('hidden');
|
389 |
+
rightBtn.classList.add('hidden');
|
390 |
+
upBtn.classList.add('hidden');
|
391 |
+
downBtn.classList.add('hidden');
|
392 |
+
}
|
393 |
+
|
394 |
+
// 游戏主循环
|
395 |
+
function gameLoop(timestamp) {
|
396 |
+
if (!gameState.started || gameState.gameOver) return;
|
397 |
+
|
398 |
+
// 清除画布
|
399 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
400 |
+
|
401 |
+
// 更新游戏状态
|
402 |
+
updateGame(timestamp);
|
403 |
+
|
404 |
+
// 绘制游戏元素
|
405 |
+
drawGame();
|
406 |
+
|
407 |
+
// 继续循环
|
408 |
+
requestAnimationFrame(gameLoop);
|
409 |
+
}
|
410 |
+
|
411 |
+
// 更新游戏状态
|
412 |
+
function updateGame(timestamp) {
|
413 |
+
// 更新飞机速度
|
414 |
+
if (gameState.keys.ArrowUp || gameState.keys.ArrowDown) {
|
415 |
+
gameState.speed = Math.max(50,
|
416 |
+
Math.min(200,
|
417 |
+
gameState.speed + (gameState.keys.ArrowUp ? 0.5 : -0.5)
|
418 |
+
)
|
419 |
+
);
|
420 |
+
}
|
421 |
+
|
422 |
+
// 更新水平方向移动
|
423 |
+
if (gameState.keys.ArrowLeft) {
|
424 |
+
gameState.plane.rotation = Math.max(gameState.plane.rotation - 2, -20);
|
425 |
+
gameState.plane.velocity = Math.max(gameState.plane.velocity - 0.5, -5);
|
426 |
+
} else if (gameState.keys.ArrowRight) {
|
427 |
+
gameState.plane.rotation = Math.min(gameState.plane.rotation + 2, 20);
|
428 |
+
gameState.plane.velocity = Math.min(gameState.plane.velocity + 0.5, 5);
|
429 |
+
} else {
|
430 |
+
// 如果没有按左右键,飞机逐渐回正
|
431 |
+
gameState.plane.rotation *= 0.95;
|
432 |
+
gameState.plane.velocity *= 0.95;
|
433 |
+
if (Math.abs(gameState.plane.rotation) < 0.5) gameState.plane.rotation = 0;
|
434 |
+
if (Math.abs(gameState.plane.velocity) < 0.5) gameState.plane.velocity = 0;
|
435 |
+
}
|
436 |
+
|
437 |
+
// 更新垂直方向移动
|
438 |
+
if (gameState.keys.ArrowUp) {
|
439 |
+
gameState.plane.verticalVelocity = Math.max(gameState.plane.verticalVelocity - 0.5, -5);
|
440 |
+
} else if (gameState.keys.ArrowDown) {
|
441 |
+
gameState.plane.verticalVelocity = Math.min(gameState.plane.verticalVelocity + 0.5, 5);
|
442 |
+
} else {
|
443 |
+
// 如果没有按上下键,垂直速度逐渐归零
|
444 |
+
gameState.plane.verticalVelocity *= 0.95;
|
445 |
+
if (Math.abs(gameState.plane.verticalVelocity) < 0.5) gameState.plane.verticalVelocity = 0;
|
446 |
+
}
|
447 |
+
|
448 |
+
// 更新飞机位置
|
449 |
+
gameState.plane.x += gameState.plane.velocity;
|
450 |
+
gameState.plane.y += gameState.plane.verticalVelocity;
|
451 |
+
|
452 |
+
// 限制飞机在屏幕内
|
453 |
+
gameState.plane.x = Math.max(gameState.plane.width / 2, Math.min(gameState.plane.x, canvas.width - gameState.plane.width / 2));
|
454 |
+
gameState.plane.y = Math.max(gameState.plane.height / 2, Math.min(gameState.plane.y, canvas.height - gameState.plane.height / 2));
|
455 |
+
|
456 |
+
// 生成新星星
|
457 |
+
if (timestamp - gameState.lastStarTime > 2000) {
|
458 |
+
createStar();
|
459 |
+
gameState.lastStarTime = timestamp;
|
460 |
+
}
|
461 |
+
|
462 |
+
// 生成新障碍物
|
463 |
+
if (timestamp - gameState.lastObstacleTime > 1500) {
|
464 |
+
createObstacle();
|
465 |
+
gameState.lastObstacleTime = timestamp;
|
466 |
+
}
|
467 |
+
|
468 |
+
// 生成新云朵
|
469 |
+
if (timestamp - gameState.lastCloudTime > 1000) {
|
470 |
+
createCloud();
|
471 |
+
gameState.lastCloudTime = timestamp;
|
472 |
+
}
|
473 |
+
|
474 |
+
// 更新云朵
|
475 |
+
gameState.clouds.forEach(cloud => {
|
476 |
+
cloud.x -= cloud.speed;
|
477 |
+
});
|
478 |
+
gameState.clouds = gameState.clouds.filter(cloud => cloud.x + cloud.size > 0);
|
479 |
+
|
480 |
+
// 更新星星
|
481 |
+
gameState.stars.forEach(star => {
|
482 |
+
star.x -= star.speed;
|
483 |
+
star.rotation += star.rotationSpeed;
|
484 |
+
|
485 |
+
// 检测碰撞
|
486 |
+
const planeRect = {
|
487 |
+
x: gameState.plane.x - gameState.plane.width / 2,
|
488 |
+
y: gameState.plane.y - gameState.plane.height / 2,
|
489 |
+
width: gameState.plane.width,
|
490 |
+
height: gameState.plane.height
|
491 |
+
};
|
492 |
+
|
493 |
+
const starRect = {
|
494 |
+
x: star.x - star.size / 2,
|
495 |
+
y: star.y - star.size / 2,
|
496 |
+
width: star.size,
|
497 |
+
height: star.size
|
498 |
+
};
|
499 |
+
|
500 |
+
if (checkCollision(planeRect, starRect) && !gameState.gameOver) {
|
501 |
+
star.collected = true;
|
502 |
+
gameState.score += 10;
|
503 |
+
updateUI();
|
504 |
+
}
|
505 |
+
});
|
506 |
+
gameState.stars = gameState.stars.filter(star => star.x + star.size > 0 && !star.collected);
|
507 |
+
|
508 |
+
// 更新障碍物
|
509 |
+
gameState.obstacles.forEach(obstacle => {
|
510 |
+
obstacle.x -= obstacle.speed;
|
511 |
+
|
512 |
+
// 检测碰撞
|
513 |
+
const planeRect = {
|
514 |
+
x: gameState.plane.x - gameState.plane.width / 2,
|
515 |
+
y: gameState.plane.y - gameState.plane.height / 2,
|
516 |
+
width: gameState.plane.width,
|
517 |
+
height: gameState.plane.height
|
518 |
+
};
|
519 |
+
|
520 |
+
const obstacleRect = obstacle.type === 'rectangle' ? {
|
521 |
+
x: obstacle.x - obstacle.width / 2,
|
522 |
+
y: obstacle.y - obstacle.height / 2,
|
523 |
+
width: obstacle.width,
|
524 |
+
height: obstacle.height
|
525 |
+
} : {
|
526 |
+
x: obstacle.x - obstacle.width / 2,
|
527 |
+
y: obstacle.y - obstacle.height / 2,
|
528 |
+
width: obstacle.width,
|
529 |
+
height: obstacle.height
|
530 |
+
};
|
531 |
+
|
532 |
+
if (checkCollision(planeRect, obstacleRect) && !gameState.gameOver) {
|
533 |
+
obstacle.hit = true;
|
534 |
+
gameState.lives--;
|
535 |
+
updateUI();
|
536 |
+
createExplosion(gameState.plane.x, gameState.plane.y);
|
537 |
+
|
538 |
+
if (gameState.lives <= 0) {
|
539 |
+
endGame();
|
540 |
+
}
|
541 |
+
}
|
542 |
+
});
|
543 |
+
gameState.obstacles = gameState.obstacles.filter(obstacle => obstacle.x + obstacle.width > 0 && !obstacle.hit);
|
544 |
+
|
545 |
+
// 更新爆炸效果
|
546 |
+
gameState.explosions.forEach(explosion => {
|
547 |
+
explosion.size += 2;
|
548 |
+
explosion.alpha -= 0.02;
|
549 |
+
});
|
550 |
+
gameState.explosions = gameState.explosions.filter(explosion => explosion.alpha > 0);
|
551 |
+
}
|
552 |
+
|
553 |
+
// 绘制游戏元素
|
554 |
+
function drawGame() {
|
555 |
+
// 绘制背景渐变
|
556 |
+
const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
|
557 |
+
gradient.addColorStop(0, '#1e3c72');
|
558 |
+
gradient.addColorStop(1, '#2a5298');
|
559 |
+
ctx.fillStyle = gradient;
|
560 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
561 |
+
|
562 |
+
// 绘制云朵
|
563 |
+
gameState.clouds.forEach(cloud => {
|
564 |
+
cloud.parts.forEach(part => {
|
565 |
+
ctx.beginPath();
|
566 |
+
ctx.arc(
|
567 |
+
cloud.x + part.offsetX,
|
568 |
+
cloud.y + part.offsetY,
|
569 |
+
part.size / 2,
|
570 |
+
0,
|
571 |
+
Math.PI * 2
|
572 |
+
);
|
573 |
+
ctx.fillStyle = `rgba(255, 255, 255, ${0.7 + Math.random() * 0.3})`;
|
574 |
+
ctx.fill();
|
575 |
+
});
|
576 |
+
});
|
577 |
+
|
578 |
+
// 绘制星星
|
579 |
+
gameState.stars.forEach(star => {
|
580 |
+
ctx.save();
|
581 |
+
ctx.translate(star.x, star.y);
|
582 |
+
ctx.rotate(star.rotation);
|
583 |
+
|
584 |
+
ctx.beginPath();
|
585 |
+
for (let i = 0; i < 5; i++) {
|
586 |
+
const angle = (i * 2 * Math.PI / 5) - Math.PI / 2;
|
587 |
+
const innerAngle = angle + Math.PI / 5;
|
588 |
+
const outerRadius = star.size / 2;
|
589 |
+
const innerRadius = star.size / 4;
|
590 |
+
|
591 |
+
if (i === 0) {
|
592 |
+
ctx.moveTo(
|
593 |
+
Math.cos(angle) * outerRadius,
|
594 |
+
Math.sin(angle) * outerRadius
|
595 |
+
);
|
596 |
+
} else {
|
597 |
+
ctx.lineTo(
|
598 |
+
Math.cos(angle) * outerRadius,
|
599 |
+
Math.sin(angle) * outerRadius
|
600 |
+
);
|
601 |
+
}
|
602 |
+
|
603 |
+
ctx.lineTo(
|
604 |
+
Math.cos(innerAngle) * innerRadius,
|
605 |
+
Math.sin(innerAngle) * innerRadius
|
606 |
+
);
|
607 |
+
}
|
608 |
+
ctx.closePath();
|
609 |
+
|
610 |
+
const gradient = ctx.createRadialGradient(0, 0, 0, 0, 0, star.size / 2);
|
611 |
+
gradient.addColorStop(0, 'gold');
|
612 |
+
gradient.addColorStop(1, 'yellow');
|
613 |
+
ctx.fillStyle = gradient;
|
614 |
+
ctx.shadowColor = 'yellow';
|
615 |
+
ctx.shadowBlur = 10;
|
616 |
+
ctx.fill();
|
617 |
+
|
618 |
+
ctx.restore();
|
619 |
+
});
|
620 |
+
|
621 |
+
// 绘制障碍物
|
622 |
+
gameState.obstacles.forEach(obstacle => {
|
623 |
+
ctx.save();
|
624 |
+
ctx.translate(obstacle.x, obstacle.y);
|
625 |
+
|
626 |
+
if (obstacle.type === 'rectangle') {
|
627 |
+
ctx.fillStyle = '#555';
|
628 |
+
ctx.fillRect(
|
629 |
+
-obstacle.width / 2,
|
630 |
+
-obstacle.height / 2,
|
631 |
+
obstacle.width,
|
632 |
+
obstacle.height
|
633 |
+
);
|
634 |
+
|
635 |
+
// 添加一些细节
|
636 |
+
ctx.fillStyle = '#444';
|
637 |
+
ctx.fillRect(
|
638 |
+
-obstacle.width / 2 + 5,
|
639 |
+
-obstacle.height / 2 + 5,
|
640 |
+
obstacle.width - 10,
|
641 |
+
obstacle.height - 10
|
642 |
+
);
|
643 |
+
} else {
|
644 |
+
ctx.beginPath();
|
645 |
+
ctx.arc(0, 0, obstacle.width / 2, 0, Math.PI * 2);
|
646 |
+
ctx.fillStyle = '#555';
|
647 |
+
ctx.fill();
|
648 |
+
|
649 |
+
// 添加一些细节
|
650 |
+
ctx.beginPath();
|
651 |
+
ctx.arc(0, 0, obstacle.width / 2 - 5, 0, Math.PI * 2);
|
652 |
+
ctx.fillStyle = '#444';
|
653 |
+
ctx.fill();
|
654 |
+
}
|
655 |
+
|
656 |
+
ctx.restore();
|
657 |
+
});
|
658 |
+
|
659 |
+
// 绘制飞机
|
660 |
+
ctx.save();
|
661 |
+
ctx.translate(gameState.plane.x, gameState.plane.y);
|
662 |
+
ctx.rotate(gameState.plane.rotation * Math.PI / 180);
|
663 |
+
|
664 |
+
// 飞机主体
|
665 |
+
ctx.beginPath();
|
666 |
+
ctx.moveTo(30, 0);
|
667 |
+
ctx.lineTo(-20, -15);
|
668 |
+
ctx.lineTo(-25, 0);
|
669 |
+
ctx.lineTo(-20, 15);
|
670 |
+
ctx.closePath();
|
671 |
+
ctx.fillStyle = '#e74c3c';
|
672 |
+
ctx.fill();
|
673 |
+
|
674 |
+
// 飞机窗户
|
675 |
+
ctx.beginPath();
|
676 |
+
ctx.arc(10, 0, 5, 0, Math.PI * 2);
|
677 |
+
ctx.fillStyle = '#3498db';
|
678 |
+
ctx.fill();
|
679 |
+
|
680 |
+
// 飞机机翼
|
681 |
+
ctx.beginPath();
|
682 |
+
ctx.moveTo(5, 0);
|
683 |
+
ctx.lineTo(-5, -20);
|
684 |
+
ctx.lineTo(-15, -20);
|
685 |
+
ctx.lineTo(-5, 0);
|
686 |
+
ctx.closePath();
|
687 |
+
ctx.fillStyle = '#c0392b';
|
688 |
+
ctx.fill();
|
689 |
+
|
690 |
+
ctx.beginPath();
|
691 |
+
ctx.moveTo(5, 0);
|
692 |
+
ctx.lineTo(-5, 20);
|
693 |
+
ctx.lineTo(-15, 20);
|
694 |
+
ctx.lineTo(-5, 0);
|
695 |
+
ctx.closePath();
|
696 |
+
ctx.fillStyle = '#c0392b';
|
697 |
+
ctx.fill();
|
698 |
+
|
699 |
+
// 飞机尾翼
|
700 |
+
ctx.beginPath();
|
701 |
+
ctx.moveTo(-20, 0);
|
702 |
+
ctx.lineTo(-25, -10);
|
703 |
+
ctx.lineTo(-30, -10);
|
704 |
+
ctx.lineTo(-25, 0);
|
705 |
+
ctx.closePath();
|
706 |
+
ctx.fillStyle = '#a5281b';
|
707 |
+
ctx.fill();
|
708 |
+
|
709 |
+
ctx.beginPath();
|
710 |
+
ctx.moveTo(-20, 0);
|
711 |
+
ctx.lineTo(-25, 10);
|
712 |
+
ctx.lineTo(-30, 10);
|
713 |
+
ctx.lineTo(-25, 0);
|
714 |
+
ctx.closePath();
|
715 |
+
ctx.fillStyle = '#a5281b';
|
716 |
+
ctx.fill();
|
717 |
+
|
718 |
+
ctx.restore();
|
719 |
+
|
720 |
+
// 绘制爆炸效果
|
721 |
+
gameState.explosions.forEach(explosion => {
|
722 |
+
ctx.save();
|
723 |
+
ctx.translate(explosion.x, explosion.y);
|
724 |
+
|
725 |
+
const gradient = ctx.createRadialGradient(
|
726 |
+
0, 0, 0,
|
727 |
+
0, 0, explosion.size
|
728 |
+
);
|
729 |
+
gradient.addColorStop(0, `rgba(255, 100, 0, ${explosion.alpha})`);
|
730 |
+
gradient.addColorStop(0.5, `rgba(255, 200, 0, ${explosion.alpha * 0.6})`);
|
731 |
+
gradient.addColorStop(1, `rgba(255, 255, 255, 0)`);
|
732 |
+
|
733 |
+
ctx.beginPath();
|
734 |
+
ctx.arc(0, 0, explosion.size, 0, Math.PI * 2);
|
735 |
+
ctx.fillStyle = gradient;
|
736 |
+
ctx.fill();
|
737 |
+
|
738 |
+
ctx.restore();
|
739 |
+
});
|
740 |
+
|
741 |
+
// 绘制速度线
|
742 |
+
if (gameState.speed > 120) {
|
743 |
+
for (let i = 0; i < 10; i++) {
|
744 |
+
const x = Math.random() * canvas.width;
|
745 |
+
const y = Math.random() * canvas.height;
|
746 |
+
const length = Math.random() * 20 + 10;
|
747 |
+
const angle = Math.atan2(
|
748 |
+
gameState.plane.y - y,
|
749 |
+
gameState.plane.x - x
|
750 |
+
);
|
751 |
+
|
752 |
+
ctx.save();
|
753 |
+
ctx.translate(x, y);
|
754 |
+
ctx.rotate(angle);
|
755 |
+
|
756 |
+
ctx.beginPath();
|
757 |
+
ctx.moveTo(0, 0);
|
758 |
+
ctx.lineTo(length, 0);
|
759 |
+
ctx.strokeStyle = `rgba(255, 255, 255, ${Math.random() * 0.5 + 0.3})`;
|
760 |
+
ctx.lineWidth = 1;
|
761 |
+
ctx.stroke();
|
762 |
+
|
763 |
+
ctx.restore();
|
764 |
+
}
|
765 |
+
}
|
766 |
+
}
|
767 |
+
|
768 |
+
// 事件监听
|
769 |
+
window.addEventListener('resize', resizeCanvas);
|
770 |
+
|
771 |
+
// 键盘控制
|
772 |
+
document.addEventListener('keydown', (e) => {
|
773 |
+
if (gameState.keys.hasOwnProperty(e.key)) {
|
774 |
+
gameState.keys[e.key] = true;
|
775 |
+
e.preventDefault();
|
776 |
+
}
|
777 |
+
});
|
778 |
+
|
779 |
+
document.addEventListener('keyup', (e) => {
|
780 |
+
if (gameState.keys.hasOwnProperty(e.key)) {
|
781 |
+
gameState.keys[e.key] = false;
|
782 |
+
e.preventDefault();
|
783 |
+
}
|
784 |
+
});
|
785 |
+
|
786 |
+
// 触摸控制��钮事件
|
787 |
+
leftBtn.addEventListener('touchstart', (e) => {
|
788 |
+
e.preventDefault();
|
789 |
+
gameState.keys.ArrowLeft = true;
|
790 |
+
});
|
791 |
+
leftBtn.addEventListener('touchend', (e) => {
|
792 |
+
e.preventDefault();
|
793 |
+
gameState.keys.ArrowLeft = false;
|
794 |
+
});
|
795 |
+
|
796 |
+
rightBtn.addEventListener('touchstart', (e) => {
|
797 |
+
e.preventDefault();
|
798 |
+
gameState.keys.ArrowRight = true;
|
799 |
+
});
|
800 |
+
rightBtn.addEventListener('touchend', (e) => {
|
801 |
+
e.preventDefault();
|
802 |
+
gameState.keys.ArrowRight = false;
|
803 |
+
});
|
804 |
+
|
805 |
+
upBtn.addEventListener('touchstart', (e) => {
|
806 |
+
e.preventDefault();
|
807 |
+
gameState.keys.ArrowUp = true;
|
808 |
+
});
|
809 |
+
upBtn.addEventListener('touchend', (e) => {
|
810 |
+
e.preventDefault();
|
811 |
+
gameState.keys.ArrowUp = false;
|
812 |
+
});
|
813 |
+
|
814 |
+
downBtn.addEventListener('touchstart', (e) => {
|
815 |
+
e.preventDefault();
|
816 |
+
gameState.keys.ArrowDown = true;
|
817 |
+
});
|
818 |
+
downBtn.addEventListener('touchend', (e) => {
|
819 |
+
e.preventDefault();
|
820 |
+
gameState.keys.ArrowDown = false;
|
821 |
+
});
|
822 |
+
|
823 |
+
// 鼠标控制按钮事件(用于桌面浏览器测试)
|
824 |
+
leftBtn.addEventListener('mousedown', (e) => {
|
825 |
+
e.preventDefault();
|
826 |
+
gameState.keys.ArrowLeft = true;
|
827 |
+
});
|
828 |
+
leftBtn.addEventListener('mouseup', (e) => {
|
829 |
+
e.preventDefault();
|
830 |
+
gameState.keys.ArrowLeft = false;
|
831 |
+
});
|
832 |
+
leftBtn.addEventListener('mouseleave', (e) => {
|
833 |
+
e.preventDefault();
|
834 |
+
gameState.keys.ArrowLeft = false;
|
835 |
+
});
|
836 |
+
|
837 |
+
rightBtn.addEventListener('mousedown', (e) => {
|
838 |
+
e.preventDefault();
|
839 |
+
gameState.keys.ArrowRight = true;
|
840 |
+
});
|
841 |
+
rightBtn.addEventListener('mouseup', (e) => {
|
842 |
+
e.preventDefault();
|
843 |
+
gameState.keys.ArrowRight = false;
|
844 |
+
});
|
845 |
+
rightBtn.addEventListener('mouseleave', (e) => {
|
846 |
+
e.preventDefault();
|
847 |
+
gameState.keys.ArrowRight = false;
|
848 |
+
});
|
849 |
+
|
850 |
+
upBtn.addEventListener('mousedown', (e) => {
|
851 |
+
e.preventDefault();
|
852 |
+
gameState.keys.ArrowUp = true;
|
853 |
+
});
|
854 |
+
upBtn.addEventListener('mouseup', (e) => {
|
855 |
+
e.preventDefault();
|
856 |
+
gameState.keys.ArrowUp = false;
|
857 |
+
});
|
858 |
+
upBtn.addEventListener('mouseleave', (e) => {
|
859 |
+
e.preventDefault();
|
860 |
+
gameState.keys.ArrowUp = false;
|
861 |
+
});
|
862 |
+
|
863 |
+
downBtn.addEventListener('mousedown', (e) => {
|
864 |
+
e.preventDefault();
|
865 |
+
gameState.keys.ArrowDown = true;
|
866 |
+
});
|
867 |
+
downBtn.addEventListener('mouseup', (e) => {
|
868 |
+
e.preventDefault();
|
869 |
+
gameState.keys.ArrowDown = false;
|
870 |
+
});
|
871 |
+
downBtn.addEventListener('mouseleave', (e) => {
|
872 |
+
e.preventDefault();
|
873 |
+
gameState.keys.ArrowDown = false;
|
874 |
+
});
|
875 |
+
|
876 |
+
// 按钮事件
|
877 |
+
startButton.addEventListener('click', initGame);
|
878 |
+
restartButton.addEventListener('click', initGame);
|
879 |
+
|
880 |
+
// 初始调整画布大小
|
881 |
+
resizeCanvas();
|
882 |
+
</script>
|
883 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=zdwalter/plane-fighter-1" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
|
884 |
+
</html>
|