zclcz commited on
Commit
e9e8d93
·
verified ·
1 Parent(s): 09de2d9

我想设计一个纯H5的坦克大战小游戏 要求有无敌铁壁、无限生命、最高等级子弹的开关 - Initial Deployment

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +1061 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Aaa
3
- emoji: 🌖
4
- colorFrom: blue
5
- colorTo: yellow
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: aaa
3
+ emoji: 🐳
4
+ colorFrom: gray
5
+ colorTo: pink
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,1061 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>坦克大战</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
+ #gameCanvas {
11
+ background-color: #333;
12
+ display: block;
13
+ margin: 0 auto;
14
+ border: 4px solid #555;
15
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
16
+ }
17
+
18
+ .toggle-switch {
19
+ position: relative;
20
+ display: inline-block;
21
+ width: 60px;
22
+ height: 30px;
23
+ }
24
+
25
+ .toggle-switch input {
26
+ opacity: 0;
27
+ width: 0;
28
+ height: 0;
29
+ }
30
+
31
+ .slider {
32
+ position: absolute;
33
+ cursor: pointer;
34
+ top: 0;
35
+ left: 0;
36
+ right: 0;
37
+ bottom: 0;
38
+ background-color: #ccc;
39
+ transition: .4s;
40
+ border-radius: 34px;
41
+ }
42
+
43
+ .slider:before {
44
+ position: absolute;
45
+ content: "";
46
+ height: 22px;
47
+ width: 22px;
48
+ left: 4px;
49
+ bottom: 4px;
50
+ background-color: white;
51
+ transition: .4s;
52
+ border-radius: 50%;
53
+ }
54
+
55
+ input:checked + .slider {
56
+ background-color: #4CAF50;
57
+ }
58
+
59
+ input:checked + .slider:before {
60
+ transform: translateX(30px);
61
+ }
62
+
63
+ @keyframes explosion {
64
+ 0% { transform: scale(0.1); opacity: 1; }
65
+ 50% { opacity: 0.7; }
66
+ 100% { transform: scale(1.5); opacity: 0; }
67
+ }
68
+
69
+ .explosion {
70
+ position: absolute;
71
+ width: 40px;
72
+ height: 40px;
73
+ background: radial-gradient(circle, #ffcc00, #ff6600);
74
+ border-radius: 50%;
75
+ animation: explosion 0.5s ease-out forwards;
76
+ pointer-events: none;
77
+ }
78
+
79
+ .powerup {
80
+ position: absolute;
81
+ width: 20px;
82
+ height: 20px;
83
+ border-radius: 50%;
84
+ animation: float 2s ease-in-out infinite;
85
+ }
86
+
87
+ @keyframes float {
88
+ 0%, 100% { transform: translateY(0); }
89
+ 50% { transform: translateY(-10px); }
90
+ }
91
+
92
+ .bullet-powerup {
93
+ background: radial-gradient(circle, #00ccff, #0066ff);
94
+ }
95
+
96
+ .health-powerup {
97
+ background: radial-gradient(circle, #ff3366, #cc0033);
98
+ }
99
+
100
+ .shield-powerup {
101
+ background: radial-gradient(circle, #66ff66, #00cc00);
102
+ }
103
+ </style>
104
+ </head>
105
+ <body class="bg-gray-900 text-white min-h-screen">
106
+ <div class="container mx-auto px-4 py-8">
107
+ <header class="text-center mb-8">
108
+ <h1 class="text-4xl font-bold text-yellow-400 mb-2">坦克大战</h1>
109
+ <p class="text-gray-300">经典街机游戏 - HTML5重制版</p>
110
+ </header>
111
+
112
+ <div class="flex flex-col lg:flex-row gap-8">
113
+ <!-- 游戏控制面板 -->
114
+ <div class="lg:w-1/4 bg-gray-800 p-6 rounded-lg shadow-lg">
115
+ <h2 class="text-2xl font-semibold mb-4 text-yellow-300 flex items-center">
116
+ <i class="fas fa-gamepad mr-2"></i> 游戏控制
117
+ </h2>
118
+
119
+ <div class="mb-6">
120
+ <h3 class="text-lg font-medium mb-2 flex items-center">
121
+ <i class="fas fa-keyboard mr-2"></i> 操作方式
122
+ </h3>
123
+ <ul class="space-y-2 text-gray-300">
124
+ <li><i class="fas fa-arrow-up mr-2"></i> 上箭头: 向上移动</li>
125
+ <li><i class="fas fa-arrow-down mr-2"></i> 下箭头: 向下移动</li>
126
+ <li><i class="fas fa-arrow-left mr-2"></i> 左箭头: 向左移动</li>
127
+ <li><i class="fas fa-arrow-right mr-2"></i> 右箭头: 向右移动</li>
128
+ <li><i class="fas fa-space-shuttle mr-2"></i> 空格键: 发射子弹</li>
129
+ </ul>
130
+ </div>
131
+
132
+ <div class="mb-6">
133
+ <h3 class="text-lg font-medium mb-2 flex items-center">
134
+ <i class="fas fa-cogs mr-2"></i> 游戏设置
135
+ </h3>
136
+ <div class="space-y-4">
137
+ <div class="flex items-center justify-between">
138
+ <span class="flex items-center">
139
+ <i class="fas fa-shield-alt mr-2 text-blue-400"></i> 无敌铁壁
140
+ </span>
141
+ <label class="toggle-switch">
142
+ <input type="checkbox" id="invincibleToggle">
143
+ <span class="slider"></span>
144
+ </label>
145
+ </div>
146
+
147
+ <div class="flex items-center justify-between">
148
+ <span class="flex items-center">
149
+ <i class="fas fa-heart mr-2 text-red-400"></i> 无限生命
150
+ </span>
151
+ <label class="toggle-switch">
152
+ <input type="checkbox" id="infiniteLivesToggle">
153
+ <span class="slider"></span>
154
+ </label>
155
+ </div>
156
+
157
+ <div class="flex items-center justify-between">
158
+ <span class="flex items-center">
159
+ <i class="fas fa-bolt mr-2 text-yellow-400"></i> 最高等级子弹
160
+ </span>
161
+ <label class="toggle-switch">
162
+ <input type="checkbox" id="maxBulletToggle">
163
+ <span class="slider"></span>
164
+ </label>
165
+ </div>
166
+ </div>
167
+ </div>
168
+
169
+ <div class="flex flex-col space-y-4">
170
+ <button id="startBtn" class="bg-green-600 hover:bg-green-700 text-white py-2 px-4 rounded-lg font-medium transition flex items-center justify-center">
171
+ <i class="fas fa-play mr-2"></i> 开始游戏
172
+ </button>
173
+ <button id="pauseBtn" class="bg-yellow-600 hover:bg-yellow-700 text-white py-2 px-4 rounded-lg font-medium transition flex items-center justify-center">
174
+ <i class="fas fa-pause mr-2"></i> 暂停游戏
175
+ </button>
176
+ <button id="resetBtn" class="bg-red-600 hover:bg-red-700 text-white py-2 px-4 rounded-lg font-medium transition flex items-center justify-center">
177
+ <i class="fas fa-redo mr-2"></i> 重新开始
178
+ </button>
179
+ </div>
180
+ </div>
181
+
182
+ <!-- 游戏区域 -->
183
+ <div class="lg:w-3/4">
184
+ <div class="bg-gray-800 p-4 rounded-lg shadow-lg">
185
+ <div class="flex justify-between items-center mb-4">
186
+ <div class="flex items-center space-x-4">
187
+ <div class="flex items-center">
188
+ <i class="fas fa-heart text-red-500 mr-2"></i>
189
+ <span id="livesDisplay" class="font-bold">3</span>
190
+ </div>
191
+ <div class="flex items-center">
192
+ <i class="fas fa-bolt text-yellow-500 mr-2"></i>
193
+ <span id="bulletLevelDisplay" class="font-bold">1</span>
194
+ </div>
195
+ <div class="flex items-center">
196
+ <i class="fas fa-shield-alt text-blue-500 mr-2"></i>
197
+ <span id="shieldDisplay" class="font-bold">0</span>
198
+ </div>
199
+ </div>
200
+ <div class="flex items-center">
201
+ <i class="fas fa-star text-yellow-300 mr-2"></i>
202
+ <span id="scoreDisplay" class="font-bold text-xl">0</span>
203
+ </div>
204
+ </div>
205
+
206
+ <div class="relative">
207
+ <canvas id="gameCanvas" width="800" height="500"></canvas>
208
+ <div id="gameOverlay" class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-70 hidden">
209
+ <div class="text-center p-8 bg-gray-900 rounded-lg max-w-md">
210
+ <h2 id="gameOverText" class="text-4xl font-bold mb-4 text-red-500">游戏结束</h2>
211
+ <p id="finalScore" class="text-2xl mb-6">得分: <span class="text-yellow-400">0</span></p>
212
+ <button id="restartBtn" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-6 rounded-lg font-medium transition">
213
+ <i class="fas fa-redo mr-2"></i> 再玩一次
214
+ </button>
215
+ </div>
216
+ </div>
217
+ </div>
218
+ </div>
219
+
220
+ <!-- 游戏说明 -->
221
+ <div class="mt-6 bg-gray-800 p-6 rounded-lg shadow-lg">
222
+ <h2 class="text-2xl font-semibold mb-4 text-yellow-300 flex items-center">
223
+ <i class="fas fa-info-circle mr-2"></i> 游戏说明
224
+ </h2>
225
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
226
+ <div>
227
+ <h3 class="text-lg font-medium mb-2 text-blue-300">游戏目标</h3>
228
+ <ul class="list-disc pl-5 space-y-1 text-gray-300">
229
+ <li>消灭敌方坦克获得分数</li>
230
+ <li>尽可能长时间生存</li>
231
+ <li>收集道具增强能力</li>
232
+ </ul>
233
+ </div>
234
+ <div>
235
+ <h3 class="text-lg font-medium mb-2 text-green-300">道具说明</h3>
236
+ <ul class="list-disc pl-5 space-y-1 text-gray-300">
237
+ <li><span class="text-blue-400">蓝色</span>: 子弹升级</li>
238
+ <li><span class="text-red-400">红色</span>: 恢复生命</li>
239
+ <li><span class="text-green-400">绿色</span>: 无敌护盾</li>
240
+ </ul>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ </div>
246
+ </div>
247
+
248
+ <script>
249
+ document.addEventListener('DOMContentLoaded', () => {
250
+ // 游戏常量
251
+ const TANK_SIZE = 40;
252
+ const BULLET_SIZE = 8;
253
+ const ENEMY_TANK_SIZE = 36;
254
+ const POWERUP_SIZE = 20;
255
+ const GAME_WIDTH = 800;
256
+ const GAME_HEIGHT = 500;
257
+
258
+ // 游戏变量
259
+ let canvas, ctx;
260
+ let gameRunning = false;
261
+ let gamePaused = false;
262
+ let score = 0;
263
+ let lives = 3;
264
+ let bulletLevel = 1;
265
+ let shieldTime = 0;
266
+ let invincible = false;
267
+ let infiniteLives = false;
268
+ let maxBullet = false;
269
+
270
+ // 玩家坦克
271
+ let player = {
272
+ x: GAME_WIDTH / 2 - TANK_SIZE / 2,
273
+ y: GAME_HEIGHT - TANK_SIZE - 10,
274
+ width: TANK_SIZE,
275
+ height: TANK_SIZE,
276
+ speed: 5,
277
+ direction: 'up',
278
+ color: '#3498db',
279
+ lastShot: 0,
280
+ shootDelay: 300
281
+ };
282
+
283
+ // 子弹数组
284
+ let bullets = [];
285
+
286
+ // 敌方坦克数组
287
+ let enemies = [];
288
+
289
+ // 道具数组
290
+ let powerups = [];
291
+
292
+ // 爆炸效果数组
293
+ let explosions = [];
294
+
295
+ // 敌方坦克生成计时器
296
+ let enemySpawnTimer = 0;
297
+ const ENEMY_SPAWN_RATE = 1500;
298
+
299
+ // 道具生成计时器
300
+ let powerupSpawnTimer = 0;
301
+ const POWERUP_SPAWN_RATE = 10000;
302
+
303
+ // 游戏主循环ID
304
+ let gameLoopId;
305
+
306
+ // 初始化游戏
307
+ function initGame() {
308
+ canvas = document.getElementById('gameCanvas');
309
+ ctx = canvas.getContext('2d');
310
+
311
+ // 设置事件监听器
312
+ document.addEventListener('keydown', handleKeyDown);
313
+ document.addEventListener('keyup', handleKeyUp);
314
+
315
+ // 按钮事件
316
+ document.getElementById('startBtn').addEventListener('click', startGame);
317
+ document.getElementById('pauseBtn').addEventListener('click', togglePause);
318
+ document.getElementById('resetBtn').addEventListener('click', resetGame);
319
+ document.getElementById('restartBtn').addEventListener('click', resetGame);
320
+
321
+ // 开关事件
322
+ document.getElementById('invincibleToggle').addEventListener('change', (e) => {
323
+ invincible = e.target.checked;
324
+ if (invincible) {
325
+ shieldTime = Infinity;
326
+ updateShieldDisplay();
327
+ } else {
328
+ shieldTime = 0;
329
+ updateShieldDisplay();
330
+ }
331
+ });
332
+
333
+ document.getElementById('infiniteLivesToggle').addEventListener('change', (e) => {
334
+ infiniteLives = e.target.checked;
335
+ });
336
+
337
+ document.getElementById('maxBulletToggle').addEventListener('change', (e) => {
338
+ maxBullet = e.target.checked;
339
+ if (maxBullet) {
340
+ bulletLevel = 3;
341
+ updateBulletLevelDisplay();
342
+ }
343
+ });
344
+
345
+ // 初始化游戏状态显示
346
+ updateScoreDisplay();
347
+ updateLivesDisplay();
348
+ updateBulletLevelDisplay();
349
+ updateShieldDisplay();
350
+ }
351
+
352
+ // 开始游戏
353
+ function startGame() {
354
+ if (gameRunning) return;
355
+
356
+ // 重置游戏状态
357
+ score = 0;
358
+ lives = 3;
359
+ bulletLevel = maxBullet ? 3 : 1;
360
+ shieldTime = invincible ? Infinity : 0;
361
+ bullets = [];
362
+ enemies = [];
363
+ powerups = [];
364
+ explosions = [];
365
+
366
+ // 更新显示
367
+ updateScoreDisplay();
368
+ updateLivesDisplay();
369
+ updateBulletLevelDisplay();
370
+ updateShieldDisplay();
371
+
372
+ // 重置玩家位置
373
+ player.x = GAME_WIDTH / 2 - TANK_SIZE / 2;
374
+ player.y = GAME_HEIGHT - TANK_SIZE - 10;
375
+ player.direction = 'up';
376
+
377
+ // 隐藏游戏结束覆盖层
378
+ document.getElementById('gameOverlay').classList.add('hidden');
379
+
380
+ gameRunning = true;
381
+ gamePaused = false;
382
+
383
+ // 开始游戏循环
384
+ gameLoopId = requestAnimationFrame(gameLoop);
385
+ }
386
+
387
+ // 暂停/继续游戏
388
+ function togglePause() {
389
+ if (!gameRunning) return;
390
+
391
+ gamePaused = !gamePaused;
392
+
393
+ if (gamePaused) {
394
+ cancelAnimationFrame(gameLoopId);
395
+ document.getElementById('pauseBtn').innerHTML = '<i class="fas fa-play mr-2"></i> 继续游戏';
396
+ } else {
397
+ gameLoopId = requestAnimationFrame(gameLoop);
398
+ document.getElementById('pauseBtn').innerHTML = '<i class="fas fa-pause mr-2"></i> 暂停游戏';
399
+ }
400
+ }
401
+
402
+ // 重置游戏
403
+ function resetGame() {
404
+ cancelAnimationFrame(gameLoopId);
405
+ gameRunning = false;
406
+ document.getElementById('gameOverlay').classList.add('hidden');
407
+ document.getElementById('pauseBtn').innerHTML = '<i class="fas fa-pause mr-2"></i> 暂停游戏';
408
+ startGame();
409
+ }
410
+
411
+ // 游戏结束
412
+ function gameOver() {
413
+ gameRunning = false;
414
+ cancelAnimationFrame(gameLoopId);
415
+
416
+ document.getElementById('gameOverText').textContent = '游戏结束';
417
+ document.getElementById('finalScore').innerHTML = `得分: <span class="text-yellow-400">${score}</span>`;
418
+ document.getElementById('gameOverlay').classList.remove('hidden');
419
+ }
420
+
421
+ // 游戏主循环
422
+ function gameLoop(timestamp) {
423
+ if (gamePaused) return;
424
+
425
+ // 清除画布
426
+ ctx.clearRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
427
+
428
+ // 更新游戏状态
429
+ updateGame(timestamp);
430
+
431
+ // 绘制游戏元素
432
+ drawGame();
433
+
434
+ // 继续游戏循环
435
+ gameLoopId = requestAnimationFrame(gameLoop);
436
+ }
437
+
438
+ // 更新游戏状态
439
+ function updateGame(timestamp) {
440
+ // 生成敌方坦克
441
+ if (timestamp - enemySpawnTimer > ENEMY_SPAWN_RATE) {
442
+ spawnEnemy();
443
+ enemySpawnTimer = timestamp;
444
+ }
445
+
446
+ // 生成道具
447
+ if (timestamp - powerupSpawnTimer > POWERUP_SPAWN_RATE) {
448
+ spawnPowerup();
449
+ powerupSpawnTimer = timestamp;
450
+ }
451
+
452
+ // 更新玩家位置
453
+ updatePlayerPosition();
454
+
455
+ // 更新子弹位置
456
+ updateBullets();
457
+
458
+ // 更新敌方坦克
459
+ updateEnemies(timestamp);
460
+
461
+ // 更新道具
462
+ updatePowerups();
463
+
464
+ // 更新爆炸效果
465
+ updateExplosions();
466
+
467
+ // 更新护盾时间
468
+ if (shieldTime > 0 && !invincible) {
469
+ shieldTime -= 16; // 大约每帧减少16ms
470
+ if (shieldTime <= 0) {
471
+ shieldTime = 0;
472
+ updateShieldDisplay();
473
+ }
474
+ }
475
+ }
476
+
477
+ // 绘制游戏元素
478
+ function drawGame() {
479
+ // 绘制背景网格
480
+ drawGrid();
481
+
482
+ // 绘制玩家坦克
483
+ drawTank(player.x, player.y, player.width, player.height, player.direction, player.color, shieldTime > 0 || invincible);
484
+
485
+ // 绘制子弹
486
+ bullets.forEach(bullet => {
487
+ ctx.fillStyle = bullet.color;
488
+ ctx.beginPath();
489
+ ctx.arc(bullet.x, bullet.y, bullet.size / 2, 0, Math.PI * 2);
490
+ ctx.fill();
491
+ });
492
+
493
+ // 绘制敌方坦克
494
+ enemies.forEach(enemy => {
495
+ drawTank(enemy.x, enemy.y, enemy.width, enemy.height, enemy.direction, enemy.color, false);
496
+ });
497
+
498
+ // 绘制道具
499
+ powerups.forEach(powerup => {
500
+ ctx.fillStyle = powerup.color;
501
+ ctx.beginPath();
502
+ ctx.arc(powerup.x, powerup.y, powerup.size / 2, 0, Math.PI * 2);
503
+ ctx.fill();
504
+
505
+ // 绘制道具图标
506
+ ctx.fillStyle = 'white';
507
+ ctx.font = '12px Arial';
508
+ ctx.textAlign = 'center';
509
+ ctx.textBaseline = 'middle';
510
+
511
+ switch(powerup.type) {
512
+ case 'bullet':
513
+ ctx.fillText('↑', powerup.x, powerup.y);
514
+ break;
515
+ case 'health':
516
+ ctx.fillText('♥', powerup.x, powerup.y);
517
+ break;
518
+ case 'shield':
519
+ ctx.fillText('⛨', powerup.x, powerup.y);
520
+ break;
521
+ }
522
+ });
523
+
524
+ // 绘制爆炸效果
525
+ explosions.forEach(explosion => {
526
+ ctx.fillStyle = explosion.color;
527
+ ctx.globalAlpha = explosion.opacity;
528
+ ctx.beginPath();
529
+ ctx.arc(explosion.x, explosion.y, explosion.size / 2, 0, Math.PI * 2);
530
+ ctx.fill();
531
+ ctx.globalAlpha = 1;
532
+ });
533
+ }
534
+
535
+ // 绘制背景网格
536
+ function drawGrid() {
537
+ ctx.strokeStyle = '#444';
538
+ ctx.lineWidth = 1;
539
+
540
+ // 水平线
541
+ for (let y = 0; y < GAME_HEIGHT; y += 40) {
542
+ ctx.beginPath();
543
+ ctx.moveTo(0, y);
544
+ ctx.lineTo(GAME_WIDTH, y);
545
+ ctx.stroke();
546
+ }
547
+
548
+ // 垂直线
549
+ for (let x = 0; x < GAME_WIDTH; x += 40) {
550
+ ctx.beginPath();
551
+ ctx.moveTo(x, 0);
552
+ ctx.lineTo(x, GAME_HEIGHT);
553
+ ctx.stroke();
554
+ }
555
+ }
556
+
557
+ // 绘制坦克
558
+ function drawTank(x, y, width, height, direction, color, hasShield) {
559
+ // 坦克主体
560
+ ctx.fillStyle = color;
561
+ ctx.fillRect(x, y, width, height);
562
+
563
+ // 坦克炮管
564
+ ctx.fillStyle = '#555';
565
+ switch(direction) {
566
+ case 'up':
567
+ ctx.fillRect(x + width/2 - 4, y - 10, 8, 15);
568
+ break;
569
+ case 'down':
570
+ ctx.fillRect(x + width/2 - 4, y + height - 5, 8, 15);
571
+ break;
572
+ case 'left':
573
+ ctx.fillRect(x - 10, y + height/2 - 4, 15, 8);
574
+ break;
575
+ case 'right':
576
+ ctx.fillRect(x + width - 5, y + height/2 - 4, 15, 8);
577
+ break;
578
+ }
579
+
580
+ // 坦克履带标记
581
+ ctx.fillStyle = '#222';
582
+ ctx.fillRect(x + 5, y + 5, width - 10, 5);
583
+ ctx.fillRect(x + 5, y + height - 10, width - 10, 5);
584
+
585
+ // 如果有护盾,绘制护盾效果
586
+ if (hasShield) {
587
+ ctx.strokeStyle = '#00ff00';
588
+ ctx.lineWidth = 3;
589
+ ctx.beginPath();
590
+ ctx.arc(x + width/2, y + height/2, width/2 + 5, 0, Math.PI * 2);
591
+ ctx.stroke();
592
+ }
593
+ }
594
+
595
+ // 生成敌方坦克
596
+ function spawnEnemy() {
597
+ const x = Math.random() * (GAME_WIDTH - ENEMY_TANK_SIZE);
598
+ const y = 10;
599
+ const direction = Math.random() > 0.5 ? 'left' : 'right';
600
+ const speed = 1 + Math.random() * 2;
601
+
602
+ enemies.push({
603
+ x: x,
604
+ y: y,
605
+ width: ENEMY_TANK_SIZE,
606
+ height: ENEMY_TANK_SIZE,
607
+ speed: speed,
608
+ direction: direction,
609
+ color: '#e74c3c',
610
+ lastShot: 0,
611
+ shootDelay: 1500 + Math.random() * 1500,
612
+ moveTimer: 0,
613
+ moveDuration: 1000 + Math.random() * 2000
614
+ });
615
+ }
616
+
617
+ // 生成道具
618
+ function spawnPowerup() {
619
+ const x = 20 + Math.random() * (GAME_WIDTH - 40);
620
+ const y = 20 + Math.random() * (GAME_HEIGHT - 40);
621
+ const types = ['bullet', 'health', 'shield'];
622
+ const type = types[Math.floor(Math.random() * types.length)];
623
+
624
+ let color;
625
+ switch(type) {
626
+ case 'bullet':
627
+ color = '#3498db';
628
+ break;
629
+ case 'health':
630
+ color = '#e74c3c';
631
+ break;
632
+ case 'shield':
633
+ color = '#2ecc71';
634
+ break;
635
+ }
636
+
637
+ powerups.push({
638
+ x: x,
639
+ y: y,
640
+ size: POWERUP_SIZE,
641
+ type: type,
642
+ color: color,
643
+ duration: 10000 // 10秒后消失
644
+ });
645
+
646
+ // 创建视觉效果
647
+ const powerupElement = document.createElement('div');
648
+ powerupElement.className = `powerup ${type}-powerup`;
649
+ powerupElement.style.left = `${x - POWERUP_SIZE/2}px`;
650
+ powerupElement.style.top = `${y - POWERUP_SIZE/2}px`;
651
+ document.getElementById('gameCanvas').parentNode.appendChild(powerupElement);
652
+
653
+ // 10秒后移除视觉效果
654
+ setTimeout(() => {
655
+ powerupElement.remove();
656
+ }, 10000);
657
+ }
658
+
659
+ // 更新玩家位置
660
+ function updatePlayerPosition() {
661
+ // 边界检查
662
+ if (player.x < 0) player.x = 0;
663
+ if (player.x > GAME_WIDTH - player.width) player.x = GAME_WIDTH - player.width;
664
+ if (player.y < 0) player.y = 0;
665
+ if (player.y > GAME_HEIGHT - player.height) player.y = GAME_HEIGHT - player.height;
666
+ }
667
+
668
+ // 更新子弹位置
669
+ function updateBullets() {
670
+ for (let i = bullets.length - 1; i >= 0; i--) {
671
+ const bullet = bullets[i];
672
+
673
+ // 移动子弹
674
+ switch(bullet.direction) {
675
+ case 'up':
676
+ bullet.y -= bullet.speed;
677
+ break;
678
+ case 'down':
679
+ bullet.y += bullet.speed;
680
+ break;
681
+ case 'left':
682
+ bullet.x -= bullet.speed;
683
+ break;
684
+ case 'right':
685
+ bullet.x += bullet.speed;
686
+ break;
687
+ }
688
+
689
+ // 检查子弹是否超出边界
690
+ if (bullet.x < 0 || bullet.x > GAME_WIDTH || bullet.y < 0 || bullet.y > GAME_HEIGHT) {
691
+ bullets.splice(i, 1);
692
+ continue;
693
+ }
694
+
695
+ // 检查子弹与敌方坦克碰撞
696
+ if (bullet.owner === 'player') {
697
+ for (let j = enemies.length - 1; j >= 0; j--) {
698
+ const enemy = enemies[j];
699
+ if (checkCollision(bullet, enemy)) {
700
+ // 创建爆炸效果
701
+ createExplosion(enemy.x + enemy.width/2, enemy.y + enemy.height/2);
702
+
703
+ // 移除子弹和敌方坦克
704
+ bullets.splice(i, 1);
705
+ enemies.splice(j, 1);
706
+
707
+ // 增加分数
708
+ score += 100;
709
+ updateScoreDisplay();
710
+ break;
711
+ }
712
+ }
713
+ }
714
+ // 检查子弹与玩家坦克碰撞
715
+ else if (bullet.owner === 'enemy') {
716
+ if (checkCollision(bullet, player) && shieldTime <= 0 && !invincible) {
717
+ // 创建爆炸效果
718
+ createExplosion(player.x + player.width/2, player.y + player.height/2);
719
+
720
+ // 移除子弹
721
+ bullets.splice(i, 1);
722
+
723
+ // 减少生命
724
+ if (!infiniteLives) {
725
+ lives--;
726
+ updateLivesDisplay();
727
+ }
728
+
729
+ // 检查游戏是否结束
730
+ if (lives <= 0) {
731
+ gameOver();
732
+ return;
733
+ }
734
+
735
+ // 重置玩家位置
736
+ player.x = GAME_WIDTH / 2 - TANK_SIZE / 2;
737
+ player.y = GAME_HEIGHT - TANK_SIZE - 10;
738
+ player.direction = 'up';
739
+
740
+ // 短暂无敌时间
741
+ if (!invincible) {
742
+ shieldTime = 2000;
743
+ updateShieldDisplay();
744
+ }
745
+ }
746
+ }
747
+ }
748
+ }
749
+
750
+ // 更新敌方坦克
751
+ function updateEnemies(timestamp) {
752
+ for (let i = enemies.length - 1; i >= 0; i--) {
753
+ const enemy = enemies[i];
754
+
755
+ // 移动敌方坦克
756
+ if (timestamp - enemy.moveTimer > enemy.moveDuration) {
757
+ // 改变方向
758
+ const directions = ['left', 'right', 'down'];
759
+ enemy.direction = directions[Math.floor(Math.random() * directions.length)];
760
+ enemy.moveTimer = timestamp;
761
+ enemy.moveDuration = 1000 + Math.random() * 2000;
762
+ }
763
+
764
+ switch(enemy.direction) {
765
+ case 'left':
766
+ enemy.x -= enemy.speed;
767
+ break;
768
+ case 'right':
769
+ enemy.x += enemy.speed;
770
+ break;
771
+ case 'down':
772
+ enemy.y += enemy.speed;
773
+ break;
774
+ }
775
+
776
+ // 边界检查
777
+ if (enemy.x < 0) {
778
+ enemy.x = 0;
779
+ enemy.direction = 'right';
780
+ }
781
+ if (enemy.x > GAME_WIDTH - enemy.width) {
782
+ enemy.x = GAME_WIDTH - enemy.width;
783
+ enemy.direction = 'left';
784
+ }
785
+ if (enemy.y > GAME_HEIGHT - enemy.height) {
786
+ enemy.y = GAME_HEIGHT - enemy.height;
787
+ enemy.direction = 'up';
788
+ }
789
+
790
+ // 敌方坦克射击
791
+ if (timestamp - enemy.lastShot > enemy.shootDelay) {
792
+ shoot(enemy, 'enemy');
793
+ enemy.lastShot = timestamp;
794
+ enemy.shootDelay = 1500 + Math.random() * 1500;
795
+ }
796
+
797
+ // 检查敌方坦克与玩家坦克碰撞
798
+ if (checkCollision(enemy, player) && shieldTime <= 0 && !invincible) {
799
+ // 创建爆炸效果
800
+ createExplosion(player.x + player.width/2, player.y + player.height/2);
801
+
802
+ // 移除敌方坦克
803
+ enemies.splice(i, 1);
804
+
805
+ // 减少生命
806
+ if (!infiniteLives) {
807
+ lives--;
808
+ updateLivesDisplay();
809
+ }
810
+
811
+ // 检查游戏是否结束
812
+ if (lives <= 0) {
813
+ gameOver();
814
+ return;
815
+ }
816
+
817
+ // 重置玩家位置
818
+ player.x = GAME_WIDTH / 2 - TANK_SIZE / 2;
819
+ player.y = GAME_HEIGHT - TANK_SIZE - 10;
820
+ player.direction = 'up';
821
+
822
+ // 短暂无敌时间
823
+ if (!invincible) {
824
+ shieldTime = 2000;
825
+ updateShieldDisplay();
826
+ }
827
+ }
828
+ }
829
+ }
830
+
831
+ // 更新道具
832
+ function updatePowerups() {
833
+ for (let i = powerups.length - 1; i >= 0; i--) {
834
+ const powerup = powerups[i];
835
+
836
+ // 检查玩家是否收集道具
837
+ if (checkCollision(player, powerup)) {
838
+ // 应用道具效果
839
+ switch(powerup.type) {
840
+ case 'bullet':
841
+ if (!maxBullet) {
842
+ bulletLevel = Math.min(bulletLevel + 1, 3);
843
+ updateBulletLevelDisplay();
844
+ }
845
+ break;
846
+ case 'health':
847
+ if (!infiniteLives) {
848
+ lives = Math.min(lives + 1, 5);
849
+ updateLivesDisplay();
850
+ }
851
+ break;
852
+ case 'shield':
853
+ shieldTime = 5000; // 5秒护盾
854
+ if (invincible) shieldTime = Infinity;
855
+ updateShieldDisplay();
856
+ break;
857
+ }
858
+
859
+ // 移除道具
860
+ powerups.splice(i, 1);
861
+ }
862
+ }
863
+ }
864
+
865
+ // 更新爆炸效果
866
+ function updateExplosions() {
867
+ for (let i = explosions.length - 1; i >= 0; i--) {
868
+ const explosion = explosions[i];
869
+
870
+ // 更新爆炸大小和透明度
871
+ explosion.size += 2;
872
+ explosion.opacity -= 0.02;
873
+
874
+ // 移除消失的爆炸
875
+ if (explosion.opacity <= 0) {
876
+ explosions.splice(i, 1);
877
+ }
878
+ }
879
+ }
880
+
881
+ // 创建爆炸效果
882
+ function createExplosion(x, y) {
883
+ explosions.push({
884
+ x: x,
885
+ y: y,
886
+ size: 10,
887
+ color: `rgb(255, ${Math.floor(Math.random() * 156) + 100}, 0)`,
888
+ opacity: 1
889
+ });
890
+
891
+ // 创建视觉效果
892
+ const explosionElement = document.createElement('div');
893
+ explosionElement.className = 'explosion';
894
+ explosionElement.style.left = `${x - 20}px`;
895
+ explosionElement.style.top = `${y - 20}px`;
896
+ document.getElementById('gameCanvas').parentNode.appendChild(explosionElement);
897
+
898
+ // 动画结束后移除
899
+ setTimeout(() => {
900
+ explosionElement.remove();
901
+ }, 500);
902
+ }
903
+
904
+ // 射击
905
+ function shoot(shooter, owner) {
906
+ const now = Date.now();
907
+
908
+ // 检查射击冷却
909
+ if (now - shooter.lastShot < shooter.shootDelay && owner === 'player') {
910
+ return;
911
+ }
912
+
913
+ let bulletX, bulletY;
914
+
915
+ // 根据方向确定子弹初始位置
916
+ switch(shooter.direction) {
917
+ case 'up':
918
+ bulletX = shooter.x + shooter.width/2;
919
+ bulletY = shooter.y - BULLET_SIZE/2;
920
+ break;
921
+ case 'down':
922
+ bulletX = shooter.x + shooter.width/2;
923
+ bulletY = shooter.y + shooter.height + BULLET_SIZE/2;
924
+ break;
925
+ case 'left':
926
+ bulletX = shooter.x - BULLET_SIZE/2;
927
+ bulletY = shooter.y + shooter.height/2;
928
+ break;
929
+ case 'right':
930
+ bulletX = shooter.x + shooter.width + BULLET_SIZE/2;
931
+ bulletY = shooter.y + shooter.height/2;
932
+ break;
933
+ }
934
+
935
+ // 设置子弹属性
936
+ const bullet = {
937
+ x: bulletX,
938
+ y: bulletY,
939
+ size: BULLET_SIZE,
940
+ speed: owner === 'player' ? 8 : 5,
941
+ direction: shooter.direction,
942
+ color: owner === 'player' ? '#f1c40f' : '#e74c3c',
943
+ owner: owner
944
+ };
945
+
946
+ // 如果是玩家射击且子弹等级高,可以发射多个子弹
947
+ if (owner === 'player') {
948
+ if (bulletLevel >= 2) {
949
+ // 第二颗子弹
950
+ const bullet2 = {...bullet};
951
+ if (bulletLevel >= 2) {
952
+ if (shooter.direction === 'up' || shooter.direction === 'down') {
953
+ bullet2.x = shooter.x + shooter.width/4;
954
+ bullet.x = shooter.x + 3*shooter.width/4;
955
+ } else {
956
+ bullet2.y = shooter.y + shooter.height/4;
957
+ bullet.y = shooter.y + 3*shooter.height/4;
958
+ }
959
+ bullets.push(bullet2);
960
+ }
961
+
962
+ // 第三颗子弹
963
+ if (bulletLevel >= 3) {
964
+ const bullet3 = {...bullet};
965
+ if (shooter.direction === 'up' || shooter.direction === 'down') {
966
+ bullet3.x = shooter.x + shooter.width/2;
967
+ bullet3.y = shooter.y - BULLET_SIZE;
968
+ } else {
969
+ bullet3.x = shooter.x - BULLET_SIZE;
970
+ bullet3.y = shooter.y + shooter.height/2;
971
+ }
972
+ bullets.push(bullet3);
973
+ }
974
+ }
975
+ }
976
+
977
+ bullets.push(bullet);
978
+ shooter.lastShot = now;
979
+ }
980
+
981
+ // 检查碰撞
982
+ function checkCollision(obj1, obj2) {
983
+ return obj1.x < obj2.x + obj2.width &&
984
+ obj1.x + obj1.width > obj2.x &&
985
+ obj1.y < obj2.y + obj2.height &&
986
+ obj1.y + obj1.height > obj2.y;
987
+ }
988
+
989
+ // 键盘控制
990
+ let keys = {};
991
+
992
+ function handleKeyDown(e) {
993
+ keys[e.key] = true;
994
+
995
+ // 空格键射击
996
+ if (e.key === ' ' && gameRunning && !gamePaused) {
997
+ shoot(player, 'player');
998
+ }
999
+ }
1000
+
1001
+ function handleKeyUp(e) {
1002
+ keys[e.key] = false;
1003
+ }
1004
+
1005
+ // 更新玩家移动
1006
+ function updatePlayerPosition() {
1007
+ if (keys['ArrowUp'] || keys['w']) {
1008
+ player.y -= player.speed;
1009
+ player.direction = 'up';
1010
+ }
1011
+ if (keys['ArrowDown'] || keys['s']) {
1012
+ player.y += player.speed;
1013
+ player.direction = 'down';
1014
+ }
1015
+ if (keys['ArrowLeft'] || keys['a']) {
1016
+ player.x -= player.speed;
1017
+ player.direction = 'left';
1018
+ }
1019
+ if (keys['ArrowRight'] || keys['d']) {
1020
+ player.x += player.speed;
1021
+ player.direction = 'right';
1022
+ }
1023
+
1024
+ // 边界检查
1025
+ player.x = Math.max(0, Math.min(GAME_WIDTH - player.width, player.x));
1026
+ player.y = Math.max(0, Math.min(GAME_HEIGHT - player.height, player.y));
1027
+ }
1028
+
1029
+ // 更新分数显示
1030
+ function updateScoreDisplay() {
1031
+ document.getElementById('scoreDisplay').textContent = score;
1032
+ }
1033
+
1034
+ // 更新生命显示
1035
+ function updateLivesDisplay() {
1036
+ document.getElementById('livesDisplay').textContent = lives;
1037
+ }
1038
+
1039
+ // 更新子弹等级显示
1040
+ function updateBulletLevelDisplay() {
1041
+ document.getElementById('bulletLevelDisplay').textContent = bulletLevel;
1042
+ }
1043
+
1044
+ // 更新护盾显示
1045
+ function updateShieldDisplay() {
1046
+ const shieldDisplay = document.getElementById('shieldDisplay');
1047
+ if (shieldTime > 0 || invincible) {
1048
+ shieldDisplay.textContent = invincible ? '∞' : Math.ceil(shieldTime / 1000);
1049
+ shieldDisplay.classList.add('text-green-500');
1050
+ } else {
1051
+ shieldDisplay.textContent = '0';
1052
+ shieldDisplay.classList.remove('text-green-500');
1053
+ }
1054
+ }
1055
+
1056
+ // 初始化游戏
1057
+ initGame();
1058
+ });
1059
+ </script>
1060
+ <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=zclcz/aaa" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
1061
+ </html>