sagar007 commited on
Commit
d57d3ab
·
verified ·
1 Parent(s): 0934dda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +399 -264
app.py CHANGED
@@ -1,18 +1,69 @@
1
  import gradio as gr
 
2
 
3
- # Updated HTML with fixes and debugging
4
- game_html = """
5
  <!DOCTYPE html>
6
  <html>
7
  <head>
8
  <title>Bird Shooter Game</title>
9
  <style>
10
- body { margin: 0; padding: 0; overflow: hidden; background-color: #87CEEB; display: flex; justify-content: center; align-items: center; height: 100vh; font-family: Arial, sans-serif; }
11
- #game-container { position: relative; width: 800px; height: 600px; border: 2px solid black; background-color: #87CEEB; overflow: hidden; }
12
- #score { position: absolute; top: 10px; left: 10px; font-size: 24px; color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); }
13
- #game-over { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 48px; color: red; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); display: none; }
14
- #restart-button { position: absolute; top: 60%; left: 50%; transform: translate(-50%, -50%); padding: 10px 20px; font-size: 24px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; display: none; }
15
- .cloud { position: absolute; fill: white; opacity: 0.8; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </style>
17
  </head>
18
  <body>
@@ -22,281 +73,365 @@ game_html = """
22
  <div id="game-over">GAME OVER</div>
23
  <button id="restart-button">Restart</button>
24
  </div>
25
- <script>
26
- document.addEventListener('DOMContentLoaded', () => {
27
- const gameCanvas = document.getElementById('game-canvas');
28
- const scoreDisplay = document.getElementById('score');
29
- const gameOverDisplay = document.getElementById('game-over');
30
- const restartButton = document.getElementById('restart-button');
31
- let score = 0;
32
- let gameRunning = true;
33
- let birds = [];
34
- let explosions = [];
35
 
36
- function createClouds() {
37
- const cloudCount = 5;
38
- for (let i = 0; i < cloudCount; i++) {
39
- const cloud = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
40
- cloud.setAttribute("cx", Math.random() * 800);
41
- cloud.setAttribute("cy", 50 + Math.random() * 100);
42
- cloud.setAttribute("rx", 50 + Math.random() * 50);
43
- cloud.setAttribute("ry", 20 + Math.random() * 20);
44
- cloud.setAttribute("fill", "white");
45
- cloud.setAttribute("opacity", "0.8");
46
- cloud.classList.add("cloud");
47
- gameCanvas.appendChild(cloud);
48
- const cloudPart = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
49
- cloudPart.setAttribute("cx", parseFloat(cloud.getAttribute("cx")) + 30);
50
- cloudPart.setAttribute("cy", parseFloat(cloud.getAttribute("cy")) - 5);
51
- cloudPart.setAttribute("rx", 30);
52
- cloudPart.setAttribute("ry", 15);
53
- cloudPart.setAttribute("fill", "white");
54
- cloudPart.setAttribute("opacity", "0.8");
55
- gameCanvas.appendChild(cloudPart);
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
-
59
- class Bird {
60
- constructor() {
61
- this.x = -50;
62
- this.y = 100 + Math.random() * 300;
63
- this.speed = 2 + Math.random() * 3;
64
- this.size = 30 + Math.random() * 20;
65
- this.element = this.createBirdElement();
66
- gameCanvas.appendChild(this.element);
67
- console.log('Bird created at x:', this.x, 'y:', this.y);
68
- }
69
- createBirdElement() {
70
- const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
71
- const body = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
72
- body.setAttribute("cx", "0");
73
- body.setAttribute("cy", "0");
74
- body.setAttribute("rx", this.size / 2);
75
- body.setAttribute("ry", this.size / 3);
76
- body.setAttribute("fill", this.getRandomColor());
77
- group.appendChild(body);
78
- const head = document.createElementNS("http://www.w3.org/2000/svg", "circle");
79
- head.setAttribute("cx", this.size / 2);
80
- head.setAttribute("cy", -this.size / 6);
81
- head.setAttribute("r", this.size / 4);
82
- head.setAttribute("fill", this.getRandomColor());
83
- group.appendChild(head);
84
- const eye = document.createElementNS("http://www.w3.org/2000/svg", "circle");
85
- eye.setAttribute("cx", this.size / 2 + this.size / 8);
86
- eye.setAttribute("cy", -this.size / 6 - this.size / 8);
87
- eye.setAttribute("r", this.size / 10);
88
- eye.setAttribute("fill", "black");
89
- group.appendChild(eye);
90
- const beak = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
91
- beak.setAttribute("points", `${this.size / 2 + this.size / 4},-${this.size / 6} ${this.size},0 ${this.size / 2 + this.size / 4},${this.size / 10}`);
92
- beak.setAttribute("fill", "orange");
93
- group.appendChild(beak);
94
- const wing = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
95
- wing.setAttribute("cx", "0");
96
- wing.setAttribute("cy", this.size / 4);
97
- wing.setAttribute("rx", this.size / 3);
98
- wing.setAttribute("ry", this.size / 6);
99
- wing.setAttribute("fill", this.getRandomColor());
100
- wing.setAttribute("class", "wing");
101
- group.appendChild(wing);
102
- return group;
103
- }
104
- getRandomColor() {
105
- const colors = ["#FF5733", "#33FF57", "#3357FF", "#F3FF33", "#FF33F3", "#33FFF3"];
106
- return colors[Math.floor(Math.random() * colors.length)];
107
- }
108
- update() {
109
- this.x += this.speed;
110
- this.element.setAttribute("transform", `translate(${this.x}, ${this.y})`);
111
- const wing = this.element.querySelector(".wing");
112
- if (wing) {
113
- const wingAngle = 15 * Math.sin(Date.now() / 100);
114
- wing.setAttribute("transform", `rotate(${wingAngle})`);
115
- }
116
- if (this.x > 850) {
117
- this.remove();
118
- console.log('Bird removed, remaining birds:', birds.length);
119
- return false;
120
- }
121
- return true;
122
- }
123
- remove() {
124
- if (this.element.parentNode) {
125
- gameCanvas.removeChild(this.element);
126
- }
127
- }
128
- checkHit(x, y) {
129
- const birdX = this.x;
130
- const birdY = this.y;
131
- const distance = Math.sqrt(Math.pow(birdX - x, 2) + Math.pow(birdY - y, 2));
132
- return distance < this.size;
133
- }
134
  }
135
-
136
- class Explosion {
137
- constructor(x, y, size) {
138
- this.x = x;
139
- this.y = y;
140
- this.size = size;
141
- this.frame = 0;
142
- this.maxFrames = 20;
143
- this.element = this.createExplosionElement();
144
- gameCanvas.appendChild(this.element);
145
- this.playSound();
146
- }
147
- createExplosionElement() {
148
- const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
149
- const colors = ["#FF0000", "#FF7700", "#FFFF00"];
150
- const particleCount = 12;
151
- for (let i = 0; i < particleCount; i++) {
152
- const angle = (i / particleCount) * 2 * Math.PI;
153
- const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
154
- circle.setAttribute("cx", Math.cos(angle) * (this.size / 3));
155
- circle.setAttribute("cy", Math.sin(angle) * (this.size / 3));
156
- circle.setAttribute("r", this.size / 8);
157
- circle.setAttribute("fill", colors[Math.floor(Math.random() * colors.length)]);
158
- circle.setAttribute("class", "particle");
159
- circle.setAttribute("data-angle", angle);
160
- group.appendChild(circle);
161
- }
162
- const center = document.createElementNS("http://www.w3.org/2000/svg", "circle");
163
- center.setAttribute("cx", 0);
164
- center.setAttribute("cy", 0);
165
- center.setAttribute("r", this.size / 2);
166
- center.setAttribute("fill", "#FF0000");
167
- center.setAttribute("class", "center");
168
- group.appendChild(center);
169
- group.setAttribute("transform", `translate(${this.x}, ${this.y})`);
170
- return group;
171
- }
172
- playSound() {
173
- const explosion = new Audio();
174
- explosion.src = "data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////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MXMlmPAJQVgWta7Zx2go+8xJ0UiCb8LHHdftWyLJE0QIAIsI+UbXu67dZMjmgDGCGl1H+vpF4NSDckSIkk7Vd+sxEhBQMRU8j/12UIRhzSaUdQ+rQU5kGeFxm+hb1oh6pWWmv3uvmReDl0UnvtapVaIzo1jZbf/pD6ElLqSX+rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=";
175
- explosion.volume = 0.3;
176
- explosion.play();
177
- }
178
- update() {
179
- this.frame++;
180
- const center = this.element.querySelector(".center");
181
- const sizeMultiplier = 1 + this.frame / 5;
182
- center.setAttribute("r", (this.size / 2) * sizeMultiplier);
183
- center.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
184
- const particles = this.element.querySelectorAll(".particle");
185
- particles.forEach(particle => {
186
- const angle = parseFloat(particle.getAttribute("data-angle"));
187
- const distance = (this.size / 3) + (this.frame * 2);
188
- const x = Math.cos(angle) * distance;
189
- const y = Math.sin(angle) * distance;
190
- particle.setAttribute("cx", x);
191
- particle.setAttribute("cy", y);
192
- particle.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
193
- particle.setAttribute("r", this.size / 8 * (1 - this.frame / this.maxFrames));
194
- });
195
- if (this.frame >= this.maxFrames) {
196
- this.remove();
197
- return false;
198
- }
199
- return true;
200
  }
201
- remove() {
202
- if (this.element.parentNode) {
203
- gameCanvas.removeChild(this.element);
204
- }
 
205
  }
 
206
  }
207
-
208
- function initGame() {
209
- score = 0;
210
- gameRunning = true;
211
- scoreDisplay.textContent = `Score: ${score}`;
212
- gameOverDisplay.style.display = 'none';
213
- restartButton.style.display = 'none';
214
- birds.forEach(bird => bird.remove());
215
- explosions.forEach(explosion => explosion.remove());
216
- birds = [];
217
- explosions = [];
218
- while (gameCanvas.firstChild) {
219
- gameCanvas.removeChild(gameCanvas.firstChild);
220
  }
221
- createClouds();
222
- birds.push(new Bird()); // Start with one bird
223
- console.log('Game initialized');
224
- gameLoop();
225
  }
226
-
227
- function gameLoop() {
228
- if (!gameRunning) {
229
- console.log('Game stopped');
230
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  }
232
- console.log('Game loop running, birds:', birds.length);
233
- if (Math.random() < 0.1) { // Increased spawn rate for testing
234
- birds.push(new Bird());
235
- console.log('New bird spawned');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  }
237
- for (let i = birds.length - 1; i >= 0; i--) {
238
- if (!birds[i].update()) {
239
- birds.splice(i, 1);
240
- }
 
 
241
  }
242
- for (let i = explosions.length - 1; i >= 0; i--) {
243
- if (!explosions[i].update()) {
244
- explosions.splice(i, 1);
245
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  }
247
- requestAnimationFrame(gameLoop); // Ensure continuous looping
248
  }
249
-
250
- gameCanvas.addEventListener('click', (e) => {
251
- if (!gameRunning) return;
252
- const rect = gameCanvas.getBoundingClientRect();
253
- const x = e.clientX - rect.left;
254
- const y = e.clientY - rect.top;
255
- let hit = false;
256
- for (let i = birds.length - 1; i >= 0; i--) {
257
- if (birds[i].checkHit(x, y)) {
258
- const birdX = birds[i].x;
259
- const birdY = birds[i].y;
260
- const birdSize = birds[i].size;
261
- birds[i].remove();
262
- birds.splice(i, 1);
263
- explosions.push(new Explosion(birdX, birdY, birdSize * 2));
264
- score += 10;
265
- scoreDisplay.textContent = `Score: ${score}`;
266
- hit = true;
267
- console.log('Bird hit, score:', score);
268
- }
269
  }
270
- if (!hit) {
271
- const miss = new Audio();
272
- miss.src = "data:audio/wav;base64,UklGRiQDAABXQVZFZm10IBAAAAABAAEAESsAABErAAABAAgAZGF0YQADAABkAGQAZABkAGQAfACEAJwAsAC8AMgA1ADsAOQA7ADkANQA0AC8AKgAnACMAHQAXABMAEQAPABEADwANAA0ADQALAAsACQAHAAUAAwABAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA8AFgAaAB8AIQAnACsAMAAyADMANwA3ADcAMgA0ADAALAApACQAIQAbABYAEQAMAAUAAAAAAAAAAAAAAAAAAAAAAAAAAP//9//x//X/9f/4/wAABwANABYAHAAnADIAOABDAEsAVABdAGQAbQBzAH4AhQCKAJEAlQCYAJ4AnwCgAKIAoQCgAJwAmgCXAJIAjwCIAIMAfQB2AG4AZgBeAFQATABGAD4ANQAvACgAIgAaABUADAAIAAQAAQD+//r/9//0//H/7//u/+z/6//r/+r/6v/p/+n/6v/q/+v/7P/u/+//8f/z//X/+P/7//7/AQADAAYACQALABAAEQAUABYAGAAZAB0AHQAfACEAIgAkACUAJQAmACcAJwAoACkAKQAqACsAKwAsACwALQAtAC0ALQAuAC4ALgAuAC4ALgAtAC0ALQAsACwALAAqACkAKQAnACYAJgAkACMAIgAgAB8AHgAcABoAGQAYABYAFAAQAA4ADAAJAAcABQADAAEA//89//7//f/8//v/+v/5//j/9//2//X/9P/z//P/8v/x//D/8P/v/+7/7v/t/+3/7P/s/+v/6//q/+r/6v/p/+n/6f/p/+n/6f/p/+n/6f/p/+n/6v/q/+v/6//s/+z/7f/u/+7/7//w//H/8v/z//T/9f/2//f/+P/5//v//P/9/wAAAgADAAUABgAIAAkACwAMAA4AEAARACMACwAEAP//+//4//X/8v/v/+v/6P/l/+L/4P/e/9v/2f/X/9X/1P/S/9H/z//O/83/zf/M/8v/y//K/8r/yv/K/8v/y//L/8z/zf/O/8//0P/S/9P/1f/X/9j/2v/c/97/4f/j/+X/6P/q/+3/8P/z//X/+P/7//7/AQA=";
273
- miss.volume = 0.2;
274
- miss.play();
275
- console.log('Missed shot');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  }
277
- });
278
-
279
- restartButton.addEventListener('click', () => {
280
- initGame();
281
- console.log('Game restarted');
282
- });
283
-
284
- initGame(); // Start the game
 
 
 
 
 
 
285
  });
 
 
 
286
  </script>
287
  </body>
288
  </html>
289
  """
290
 
291
- # Define the Gradio interface
292
- def launch_game():
293
- return game_html
 
 
 
 
 
 
 
294
 
295
- # Create the Gradio app
296
- with gr.Blocks(title="Bird Shooter Game") as demo:
297
- gr.Markdown("# Bird Shooter Game")
298
- gr.Markdown("Click on the birds to shoot them and earn points! If birds stop appearing, check the browser console (F12) for errors.")
299
- game_output = gr.HTML(label="Game", value=launch_game())
300
-
301
- # Launch the app
302
- demo.launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
 
4
+ # HTML content for the game
5
+ html_content = """
6
  <!DOCTYPE html>
7
  <html>
8
  <head>
9
  <title>Bird Shooter Game</title>
10
  <style>
11
+ body {
12
+ margin: 0;
13
+ padding: 0;
14
+ overflow: hidden;
15
+ background-color: #87CEEB;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ height: 100vh;
20
+ font-family: Arial, sans-serif;
21
+ }
22
+ #game-container {
23
+ position: relative;
24
+ width: 800px;
25
+ height: 600px;
26
+ border: 2px solid black;
27
+ background-color: #87CEEB;
28
+ overflow: hidden;
29
+ }
30
+ #score {
31
+ position: absolute;
32
+ top: 10px;
33
+ left: 10px;
34
+ font-size: 24px;
35
+ color: white;
36
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
37
+ }
38
+ #game-over {
39
+ position: absolute;
40
+ top: 50%;
41
+ left: 50%;
42
+ transform: translate(-50%, -50%);
43
+ font-size: 48px;
44
+ color: red;
45
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
46
+ display: none;
47
+ }
48
+ #restart-button {
49
+ position: absolute;
50
+ top: 60%;
51
+ left: 50%;
52
+ transform: translate(-50%, -50%);
53
+ padding: 10px 20px;
54
+ font-size: 24px;
55
+ background-color: #4CAF50;
56
+ color: white;
57
+ border: none;
58
+ border-radius: 5px;
59
+ cursor: pointer;
60
+ display: none;
61
+ }
62
+ .cloud {
63
+ position: absolute;
64
+ fill: white;
65
+ opacity: 0.8;
66
+ }
67
  </style>
68
  </head>
69
  <body>
 
73
  <div id="game-over">GAME OVER</div>
74
  <button id="restart-button">Restart</button>
75
  </div>
 
 
 
 
 
 
 
 
 
 
76
 
77
+ <script>
78
+ const gameCanvas = document.getElementById('game-canvas');
79
+ const scoreDisplay = document.getElementById('score');
80
+ const gameOverDisplay = document.getElementById('game-over');
81
+ const restartButton = document.getElementById('restart-button');
82
+
83
+ let score = 0;
84
+ let gameRunning = true;
85
+ let birds = [];
86
+ let explosions = [];
87
+
88
+ // Create clouds in the background
89
+ function createClouds() {
90
+ const cloudCount = 5;
91
+ for (let i = 0; i < cloudCount; i++) {
92
+ const cloud = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
93
+ cloud.setAttribute("cx", Math.random() * 800);
94
+ cloud.setAttribute("cy", 50 + Math.random() * 100);
95
+ cloud.setAttribute("rx", 50 + Math.random() * 50);
96
+ cloud.setAttribute("ry", 20 + Math.random() * 20);
97
+ cloud.setAttribute("fill", "white");
98
+ cloud.setAttribute("opacity", "0.8");
99
+ cloud.classList.add("cloud");
100
+ gameCanvas.appendChild(cloud);
101
+
102
+ // Create smaller ellipse attached to the cloud
103
+ const cloudPart = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
104
+ cloudPart.setAttribute("cx", parseFloat(cloud.getAttribute("cx")) + 30);
105
+ cloudPart.setAttribute("cy", parseFloat(cloud.getAttribute("cy")) - 5);
106
+ cloudPart.setAttribute("rx", 30);
107
+ cloudPart.setAttribute("ry", 15);
108
+ cloudPart.setAttribute("fill", "white");
109
+ cloudPart.setAttribute("opacity", "0.8");
110
+ gameCanvas.appendChild(cloudPart);
111
  }
112
+ }
113
+
114
+ // Bird class
115
+ class Bird {
116
+ constructor() {
117
+ this.x = -50;
118
+ this.y = 100 + Math.random() * 300;
119
+ this.speed = 2 + Math.random() * 3;
120
+ this.size = 30 + Math.random() * 20;
121
+ this.element = this.createBirdElement();
122
+ gameCanvas.appendChild(this.element);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
+
125
+ createBirdElement() {
126
+ const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
127
+
128
+ // Bird body
129
+ const body = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
130
+ body.setAttribute("cx", "0");
131
+ body.setAttribute("cy", "0");
132
+ body.setAttribute("rx", this.size / 2);
133
+ body.setAttribute("ry", this.size / 3);
134
+ body.setAttribute("fill", this.getRandomColor());
135
+ group.appendChild(body);
136
+
137
+ // Bird head
138
+ const head = document.createElementNS("http://www.w3.org/2000/svg", "circle");
139
+ head.setAttribute("cx", this.size / 2);
140
+ head.setAttribute("cy", -this.size / 6);
141
+ head.setAttribute("r", this.size / 4);
142
+ head.setAttribute("fill", this.getRandomColor());
143
+ group.appendChild(head);
144
+
145
+ // Bird eye
146
+ const eye = document.createElementNS("http://www.w3.org/2000/svg", "circle");
147
+ eye.setAttribute("cx", this.size / 2 + this.size / 8);
148
+ eye.setAttribute("cy", -this.size / 6 - this.size / 8);
149
+ eye.setAttribute("r", this.size / 10);
150
+ eye.setAttribute("fill", "black");
151
+ group.appendChild(eye);
152
+
153
+ // Bird beak
154
+ const beak = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
155
+ beak.setAttribute("points",
156
+ `${this.size / 2 + this.size / 4},-${this.size / 6}
157
+ ${this.size},0
158
+ ${this.size / 2 + this.size / 4},${this.size / 10}`);
159
+ beak.setAttribute("fill", "orange");
160
+ group.appendChild(beak);
161
+
162
+ // Bird wings
163
+ const wing = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
164
+ wing.setAttribute("cx", "0");
165
+ wing.setAttribute("cy", this.size / 4);
166
+ wing.setAttribute("rx", this.size / 3);
167
+ wing.setAttribute("ry", this.size / 6);
168
+ wing.setAttribute("fill", this.getRandomColor());
169
+ wing.setAttribute("class", "wing");
170
+ group.appendChild(wing);
171
+
172
+ return group;
173
+ }
174
+
175
+ getRandomColor() {
176
+ const colors = ["#FF5733", "#33FF57", "#3357FF", "#F3FF33", "#FF33F3", "#33FFF3"];
177
+ return colors[Math.floor(Math.random() * colors.length)];
178
+ }
179
+
180
+ update() {
181
+ this.x += this.speed;
182
+ this.element.setAttribute("transform", `translate(${this.x}, ${this.y})`);
183
+
184
+ // Animate wings
185
+ const wing = this.element.querySelector(".wing");
186
+ if (wing) {
187
+ const wingAngle = 15 * Math.sin(Date.now() / 100);
188
+ wing.setAttribute("transform", `rotate(${wingAngle})`);
189
  }
190
+
191
+ // Check if bird has left the screen
192
+ if (this.x > 850) {
193
+ this.remove();
194
+ return false;
195
  }
196
+ return true;
197
  }
198
+
199
+ remove() {
200
+ if (this.element.parentNode) {
201
+ gameCanvas.removeChild(this.element);
 
 
 
 
 
 
 
 
 
202
  }
 
 
 
 
203
  }
204
+
205
+ checkHit(x, y) {
206
+ const birdX = this.x;
207
+ const birdY = this.y;
208
+ const distance = Math.sqrt(Math.pow(birdX - x, 2) + Math.pow(birdY - y, 2));
209
+ return distance < this.size;
210
+ }
211
+ }
212
+
213
+ // Explosion class
214
+ class Explosion {
215
+ constructor(x, y, size) {
216
+ this.x = x;
217
+ this.y = y;
218
+ this.size = size;
219
+ this.frame = 0;
220
+ this.maxFrames = 20;
221
+ this.element = this.createExplosionElement();
222
+ gameCanvas.appendChild(this.element);
223
+ this.playSound();
224
+ }
225
+
226
+ createExplosionElement() {
227
+ const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
228
+
229
+ // Create explosion particles
230
+ const colors = ["#FF0000", "#FF7700", "#FFFF00"];
231
+ const particleCount = 12;
232
+
233
+ for (let i = 0; i < particleCount; i++) {
234
+ const angle = (i / particleCount) * 2 * Math.PI;
235
+ const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
236
+ circle.setAttribute("cx", Math.cos(angle) * (this.size / 3));
237
+ circle.setAttribute("cy", Math.sin(angle) * (this.size / 3));
238
+ circle.setAttribute("r", this.size / 8);
239
+ circle.setAttribute("fill", colors[Math.floor(Math.random() * colors.length)]);
240
+ circle.setAttribute("class", "particle");
241
+ circle.setAttribute("data-angle", angle);
242
+ group.appendChild(circle);
243
  }
244
+
245
+ // Add central explosion
246
+ const center = document.createElementNS("http://www.w3.org/2000/svg", "circle");
247
+ center.setAttribute("cx", 0);
248
+ center.setAttribute("cy", 0);
249
+ center.setAttribute("r", this.size / 2);
250
+ center.setAttribute("fill", "#FF0000");
251
+ center.setAttribute("class", "center");
252
+ group.appendChild(center);
253
+
254
+ group.setAttribute("transform", `translate(${this.x}, ${this.y})`);
255
+ return group;
256
+ }
257
+
258
+ playSound() {
259
+ // Create explosion sound
260
+ const explosion = new Audio();
261
+ explosion.src = "data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZ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gShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=";
262
+ explosion.volume = 0.3;
263
+ explosion.play();
264
+ }
265
+
266
+ update() {
267
+ this.frame++;
268
+
269
+ // Update explosion size and opacity
270
+ const center = this.element.querySelector(".center");
271
+ const sizeMultiplier = 1 + this.frame / 5;
272
+ center.setAttribute("r", (this.size / 2) * sizeMultiplier);
273
+ center.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
274
+
275
+ // Update particles
276
+ const particles = this.element.querySelectorAll(".particle");
277
+ particles.forEach(particle => {
278
+ const angle = parseFloat(particle.getAttribute("data-angle"));
279
+ const distance = (this.size / 3) + (this.frame * 2);
280
+
281
+ const x = Math.cos(angle) * distance;
282
+ const y = Math.sin(angle) * distance;
283
+
284
+ particle.setAttribute("cx", x);
285
+ particle.setAttribute("cy", y);
286
+ particle.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
287
+ particle.setAttribute("r", this.size / 8 * (1 - this.frame / this.maxFrames));
288
+ });
289
+
290
+ // Check if explosion is finished
291
+ if (this.frame >= this.maxFrames) {
292
+ this.remove();
293
+ return false;
294
  }
295
+ return true;
296
+ }
297
+
298
+ remove() {
299
+ if (this.element.parentNode) {
300
+ gameCanvas.removeChild(this.element);
301
  }
302
+ }
303
+ }
304
+
305
+ // Initialize the game
306
+ function initGame() {
307
+ score = 0;
308
+ gameRunning = true;
309
+ scoreDisplay.textContent = `Score: ${score}`;
310
+ gameOverDisplay.style.display = 'none';
311
+ restartButton.style.display = 'none';
312
+
313
+ // Remove all birds and explosions
314
+ birds.forEach(bird => bird.remove());
315
+ explosions.forEach(explosion => explosion.remove());
316
+ birds = [];
317
+ explosions = [];
318
+
319
+ // Clear any existing elements
320
+ while (gameCanvas.firstChild) {
321
+ gameCanvas.removeChild(gameCanvas.firstChild);
322
+ }
323
+
324
+ // Create clouds
325
+ createClouds();
326
+
327
+ // Start game loop
328
+ gameLoop();
329
+ }
330
+
331
+ // Game loop
332
+ function gameLoop() {
333
+ if (!gameRunning) return;
334
+
335
+ // Create new birds randomly
336
+ if (Math.random() < 0.02) {
337
+ birds.push(new Bird());
338
+ }
339
+
340
+ // Update birds
341
+ for (let i = birds.length - 1; i >= 0; i--) {
342
+ if (!birds[i].update()) {
343
+ birds.splice(i, 1);
344
  }
 
345
  }
346
+
347
+ // Update explosions
348
+ for (let i = explosions.length - 1; i >= 0; i--) {
349
+ if (!explosions[i].update()) {
350
+ explosions.splice(i, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  }
352
+ }
353
+
354
+ requestAnimationFrame(gameLoop);
355
+ }
356
+
357
+ // Handle mouse clicks
358
+ gameCanvas.addEventListener('click', (e) => {
359
+ if (!gameRunning) return;
360
+
361
+ const rect = gameCanvas.getBoundingClientRect();
362
+ const x = e.clientX - rect.left;
363
+ const y = e.clientY - rect.top;
364
+
365
+ let hit = false;
366
+
367
+ // Check if any bird was hit
368
+ for (let i = birds.length - 1; i >= 0; i--) {
369
+ if (birds[i].checkHit(x, y)) {
370
+ // Create explosion
371
+ const birdX = birds[i].x;
372
+ const birdY = birds[i].y;
373
+ const birdSize = birds[i].size;
374
+
375
+ // Remove the bird
376
+ birds[i].remove();
377
+ birds.splice(i, 1);
378
+
379
+ // Create explosion
380
+ explosions.push(new Explosion(birdX, birdY, birdSize * 2));
381
+
382
+ // Increment score
383
+ score += 10;
384
+ scoreDisplay.textContent = `Score: ${score}`;
385
+
386
+ hit = true;
387
  }
388
+ }
389
+
390
+ // Play miss sound if no bird was hit
391
+ if (!hit) {
392
+ const miss = new Audio();
393
+ miss.src = "data:audio/wav;base64,UklGRiQDAABXQVZFZm10IBAAAAABAAEAESsAABErAAABAAgAZGF0YQADAABkAGQAZABkAGQAfACEAJwAsAC8AMgA1ADsAOQA7ADkANQA0AC8AKgAnACMAHQAXABMAEQAPABEADwANAA0ADQALAAsACQAHAAUAAwABAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA8AFgAaAB8AIQAnACsAMAAyADMANwA3ADcAMgA0ADAALAApACQAIQAbABYAEQAMAAUAAAAAAAAAAAAAAAAAAAAAAAAAAP//9//x//X/9f/4/wAABwANABYAHAAnADIAOABDAEsAVABdAGQAbQBzAH4AhQCKAJEAlQCYAJ4AnwCgAKIAoQCgAJwAmgCXAJIAjwCIAIMAfQB2AG4AZgBeAFQATABGAD4ANQAvACgAIgAaABUADAAIAAQAAQD+//r/9//0//H/7//u/+z/6//r/+r/6v/p/+n/6v/q/+v/7P/u/+//8f/z//X/+P/7//7/AQADAAYACQALABAAEQAUABYAGAAZAB0AHQAfACEAIgAkACUAJQAmACcAJwAoACkAKQAqACsAKwAsACwALQAtAC0ALQAuAC4ALgAuAC4ALgAtAC0ALQAsACwALAAqACkAKQAnACYAJgAkACMAIgAgAB8AHgAcABoAGQAYABYAFAAQAA4ADAAJAAcABQADAAEA//89//7//f/8//v/+v/5//j/9//2//X/9P/z//P/8v/x//D/8P/v/+7/7v/t/+3/7P/s/+v/6//q/+r/6v/p/+n/6f/p/+n/6f/p/+n/6f/p/+n/6v/q/+v/6//s/+z/7f/u/+7/7//w//H/8v/z//T/9f/2//f/+P/5//v//P/9/wAAAgADAAUABgAIAAkACwAMAA4AEAARACMACwAEAP//+//4//X/8v/v/+v/6P/l/+L/4P/e/9v/2f/X/9X/1P/S/9H/z//O/83/zf/M/8v/y//K/8r/yv/K/8v/y//L/8z/zf/O/8//0P/S/9P/1f/X/9j/2v/c/97/4f/j/+X/6P/q/+3/8P/z//X/+P/7//7/AQA=";
394
+ miss.volume = 0.2;
395
+ miss.play();
396
+ }
397
+ });
398
+
399
+ // Restart game when button is clicked
400
+ restartButton.addEventListener('click', () => {
401
+ initGame();
402
  });
403
+
404
+ // Initialize the game
405
+ initGame();
406
  </script>
407
  </body>
408
  </html>
409
  """
410
 
411
+ # Function to create an HTML file
412
+ def create_html_file():
413
+ # Make sure the app directory exists
414
+ os.makedirs("app", exist_ok=True)
415
+
416
+ # Write the HTML content to a file
417
+ with open("app/index.html", "w") as f:
418
+ f.write(html_content)
419
+
420
+ return "app/index.html"
421
 
422
+ # Gradio interface
423
+ def create_interface():
424
+ html_path = create_html_file()
425
+
426
+ # Create a Gradio interface with HTML
427
+ demo = gr.Interface(
428
+ fn=lambda: None, # No-op function as we're just displaying static HTML
429
+ inputs=None,
430
+ outputs=gr.HTML(value=open(html_path, "r").read(), elem_id="bird-game"),
431
+ title="Bird Shooter Game",
432
+ description="Click on the birds to shoot them and earn points!",
433
+ css="""
434
+ .gradio-container {
435
+ max-width: 850px !important;
436
+ }
437
+ #