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d18e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef2f59c
c8d18e3
 
 
 
 
 
 
 
 
 
 
ef2f59c
c8d18e3
d57d3ab
c8d18e3
 
 
 
d57d3ab
c8d18e3
d57d3ab
c8d18e3
eeed6b8
 
 
 
c8d18e3
 
 
 
 
 
 
 
 
 
596ac16
dacd0b6
c8d18e3
 
 
dacd0b6
 
 
 
 
d57d3ab
dacd0b6
d57d3ab
dacd0b6
 
 
 
 
d57d3ab
dacd0b6
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
import gradio as gr
import tempfile
import os

# Create a temporary HTML file with the game
def create_game_html():
    html_content = """
<!DOCTYPE html>
<html>
<head>
  <title>Bird Shooter Game</title>
  <style>
    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;
    }
    #game-container {
      position: relative;
      width: 800px;
      height: 600px;
      border: 2px solid black;
      background-color: #87CEEB;
      overflow: hidden;
    }
    #score {
      position: absolute;
      top: 10px;
      left: 10px;
      font-size: 24px;
      color: white;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    }
    #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;
    }
    #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;
    }
    .cloud {
      position: absolute;
      fill: white;
      opacity: 0.8;
    }
  </style>
</head>
<body>
  <div id="game-container">
    <svg id="game-canvas" width="800" height="600"></svg>
    <div id="score">Score: 0</div>
    <div id="game-over">GAME OVER</div>
    <button id="restart-button">Restart</button>
  </div>

  <script>
    // Wait for window to fully load before initializing game
    window.onload = function() {
      const gameCanvas = document.getElementById('game-canvas');
      const scoreDisplay = document.getElementById('score');
      const gameOverDisplay = document.getElementById('game-over');
      const restartButton = document.getElementById('restart-button');
      
      let score = 0;
      let gameRunning = true;
      let birds = [];
      let explosions = [];
      
      // Create clouds in the background
      function createClouds() {
        const cloudCount = 5;
        for (let i = 0; i < cloudCount; i++) {
          const cloud = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
          cloud.setAttribute("cx", Math.random() * 800);
          cloud.setAttribute("cy", 50 + Math.random() * 100);
          cloud.setAttribute("rx", 50 + Math.random() * 50);
          cloud.setAttribute("ry", 20 + Math.random() * 20);
          cloud.setAttribute("fill", "white");
          cloud.setAttribute("opacity", "0.8");
          cloud.classList.add("cloud");
          gameCanvas.appendChild(cloud);
          
          // Create smaller ellipse attached to the cloud
          const cloudPart = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
          cloudPart.setAttribute("cx", parseFloat(cloud.getAttribute("cx")) + 30);
          cloudPart.setAttribute("cy", parseFloat(cloud.getAttribute("cy")) - 5);
          cloudPart.setAttribute("rx", 30);
          cloudPart.setAttribute("ry", 15);
          cloudPart.setAttribute("fill", "white");
          cloudPart.setAttribute("opacity", "0.8");
          gameCanvas.appendChild(cloudPart);
        }
      }
      
      // Bird class
      class Bird {
        constructor() {
          this.x = -50;
          this.y = 100 + Math.random() * 300;
          this.speed = 2 + Math.random() * 3;
          this.size = 30 + Math.random() * 20;
          this.element = this.createBirdElement();
          gameCanvas.appendChild(this.element);
        }
        
        createBirdElement() {
          const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
          
          // Bird body
          const body = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
          body.setAttribute("cx", "0");
          body.setAttribute("cy", "0");
          body.setAttribute("rx", this.size / 2);
          body.setAttribute("ry", this.size / 3);
          body.setAttribute("fill", this.getRandomColor());
          group.appendChild(body);
          
          // Bird head
          const head = document.createElementNS("http://www.w3.org/2000/svg", "circle");
          head.setAttribute("cx", this.size / 2);
          head.setAttribute("cy", -this.size / 6);
          head.setAttribute("r", this.size / 4);
          head.setAttribute("fill", this.getRandomColor());
          group.appendChild(head);
          
          // Bird eye
          const eye = document.createElementNS("http://www.w3.org/2000/svg", "circle");
          eye.setAttribute("cx", this.size / 2 + this.size / 8);
          eye.setAttribute("cy", -this.size / 6 - this.size / 8);
          eye.setAttribute("r", this.size / 10);
          eye.setAttribute("fill", "black");
          group.appendChild(eye);
          
          // Bird beak
          const beak = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
          beak.setAttribute("points", 
            `${this.size / 2 + this.size / 4},-${this.size / 6} 
             ${this.size},0 
             ${this.size / 2 + this.size / 4},${this.size / 10}`);
          beak.setAttribute("fill", "orange");
          group.appendChild(beak);
          
          // Bird wings
          const wing = document.createElementNS("http://www.w3.org/2000/svg", "ellipse");
          wing.setAttribute("cx", "0");
          wing.setAttribute("cy", this.size / 4);
          wing.setAttribute("rx", this.size / 3);
          wing.setAttribute("ry", this.size / 6);
          wing.setAttribute("fill", this.getRandomColor());
          wing.setAttribute("class", "wing");
          group.appendChild(wing);
          
          return group;
        }
        
        getRandomColor() {
          const colors = ["#FF5733", "#33FF57", "#3357FF", "#F3FF33", "#FF33F3", "#33FFF3"];
          return colors[Math.floor(Math.random() * colors.length)];
        }
        
        update() {
          this.x += this.speed;
          this.element.setAttribute("transform", `translate(${this.x}, ${this.y})`);
          
          // Animate wings
          const wing = this.element.querySelector(".wing");
          if (wing) {
            const wingAngle = 15 * Math.sin(Date.now() / 100);
            wing.setAttribute("transform", `rotate(${wingAngle})`);
          }
          
          // Check if bird has left the screen
          if (this.x > 850) {
            this.remove();
            return false;
          }
          return true;
        }
        
        remove() {
          if (this.element.parentNode) {
            gameCanvas.removeChild(this.element);
          }
        }
        
        checkHit(x, y) {
          const birdX = this.x;
          const birdY = this.y;
          const distance = Math.sqrt(Math.pow(birdX - x, 2) + Math.pow(birdY - y, 2));
          return distance < this.size;
        }
      }
      
      // Explosion class
      class Explosion {
        constructor(x, y, size) {
          this.x = x;
          this.y = y;
          this.size = size;
          this.frame = 0;
          this.maxFrames = 20;
          this.element = this.createExplosionElement();
          gameCanvas.appendChild(this.element);
          this.playSound();
        }
        
        createExplosionElement() {
          const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
          
          // Create explosion particles
          const colors = ["#FF0000", "#FF7700", "#FFFF00"];
          const particleCount = 12;
          
          for (let i = 0; i < particleCount; i++) {
            const angle = (i / particleCount) * 2 * Math.PI;
            const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
            circle.setAttribute("cx", Math.cos(angle) * (this.size / 3));
            circle.setAttribute("cy", Math.sin(angle) * (this.size / 3));
            circle.setAttribute("r", this.size / 8);
            circle.setAttribute("fill", colors[Math.floor(Math.random() * colors.length)]);
            circle.setAttribute("class", "particle");
            circle.setAttribute("data-angle", angle);
            group.appendChild(circle);
          }
          
          // Add central explosion
          const center = document.createElementNS("http://www.w3.org/2000/svg", "circle");
          center.setAttribute("cx", 0);
          center.setAttribute("cy", 0);
          center.setAttribute("r", this.size / 2);
          center.setAttribute("fill", "#FF0000");
          center.setAttribute("class", "center");
          group.appendChild(center);
          
          group.setAttribute("transform", `translate(${this.x}, ${this.y})`);
          return group;
        }
        
        playSound() {
          try {
            // Create explosion sound
            const explosion = new Audio();
            explosion.src = "data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fh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8j/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=";
            explosion.volume = 0.3;
            explosion.play();
          } catch (e) {
            console.log("Sound error:", e);
          }
        }
        
        update() {
          this.frame++;
          
          // Update explosion size and opacity
          const center = this.element.querySelector(".center");
          const sizeMultiplier = 1 + this.frame / 5;
          center.setAttribute("r", (this.size / 2) * sizeMultiplier);
          center.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
          
          // Update particles
          const particles = this.element.querySelectorAll(".particle");
          particles.forEach(particle => {
            const angle = parseFloat(particle.getAttribute("data-angle"));
            const distance = (this.size / 3) + (this.frame * 2);
            
            const x = Math.cos(angle) * distance;
            const y = Math.sin(angle) * distance;
            
            particle.setAttribute("cx", x);
            particle.setAttribute("cy", y);
            particle.setAttribute("opacity", 1 - (this.frame / this.maxFrames));
            particle.setAttribute("r", this.size / 8 * (1 - this.frame / this.maxFrames));
          });
          
          // Check if explosion is finished
          if (this.frame >= this.maxFrames) {
            this.remove();
            return false;
          }
          return true;
        }
        
        remove() {
          if (this.element.parentNode) {
            gameCanvas.removeChild(this.element);
          }
        }
      }
      
      // Initialize the game
      function initGame() {
        console.log("Initializing game...");
        score = 0;
        gameRunning = true;
        scoreDisplay.textContent = `Score: ${score}`;
        gameOverDisplay.style.display = 'none';
        restartButton.style.display = 'none';
        
        // Remove all birds and explosions
        birds.forEach(bird => bird.remove());
        explosions.forEach(explosion => explosion.remove());
        birds = [];
        explosions = [];
        
        // Clear any existing elements
        while (gameCanvas.firstChild) {
          gameCanvas.removeChild(gameCanvas.firstChild);
        }
        
        // Create clouds
        createClouds();
        
        // Immediately create first bird to make sure something appears
        birds.push(new Bird());
        
        // Start game loop
        gameLoop();
        console.log("Game loop started");
      }
      
      // Game loop
      function gameLoop() {
        if (!gameRunning) return;
        
        // Create new birds randomly
        if (Math.random() < 0.02) {
          birds.push(new Bird());
        }
        
        // Update birds
        for (let i = birds.length - 1; i >= 0; i--) {
          if (!birds[i].update()) {
            birds.splice(i, 1);
          }
        }
        
        // Update explosions
        for (let i = explosions.length - 1; i >= 0; i--) {
          if (!explosions[i].update()) {
            explosions.splice(i, 1);
          }
        }
        
        requestAnimationFrame(gameLoop);
      }
      
      // Handle mouse clicks
      gameCanvas.addEventListener('click', (e) => {
        if (!gameRunning) return;
        
        const rect = gameCanvas.getBoundingClientRect();
        const x = e.clientX - rect.left;
        const y = e.clientY - rect.top;
        
        let hit = false;
        
        // Check if any bird was hit
        for (let i = birds.length - 1; i >= 0; i--) {
          if (birds[i].checkHit(x, y)) {
            // Create explosion
            const birdX = birds[i].x;
            const birdY = birds[i].y;
            const birdSize = birds[i].size;
            
            // Remove the bird
            birds[i].remove();
            birds.splice(i, 1);
            
            // Create explosion
            explosions.push(new Explosion(birdX, birdY, birdSize * 2));
            
            // Increment score
            score += 10;
            scoreDisplay.textContent = `Score: ${score}`;
            
            hit = true;
          }
        }
        
        // Play miss sound if no bird was hit
        if (!hit) {
          try {
            const miss = new Audio();
            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=";
            miss.volume = 0.2;
            miss.play();
          } catch (e) {
            console.log("Sound error:", e);
          }
        }
      });
      
      // Restart game when button is clicked
      restartButton.addEventListener('click', () => {
        initGame();
      });
      
      // Initialize the game
      initGame();
    };
  </script>
</body>
</html>
"""
    
    # Create a temporary file to serve the HTML
    temp_dir = tempfile.mkdtemp()
    html_path = os.path.join(temp_dir, "game.html")
    
    with open(html_path, "w") as f:
        f.write(html_content)
    
    # Return the path to be used in the iframe
    return html_path

def create_game():
    html_path = create_game_html()
    iframe_html = f'<iframe src="file://{html_path}" width="820" height="650" frameborder="0"></iframe>'
    return gr.HTML(iframe_html)

# Create Gradio interface
with gr.Blocks(title="Bird Shooter Game") as demo:
    gr.Markdown("# 🎮 Bird Shooter Game")
    gr.Markdown("Click on the birds to shoot them and score points!")
    
    game_interface = create_game()
    
    gr.Markdown("""
    ## How to Play
    - Click on birds to shoot them
    - Each hit earns you 10 points
    - Try to get the highest score possible!
    
    ## About
    This is a simple bird shooter game created with SVG and JavaScript, embedded in a Gradio app for Hugging Face Spaces.
    """)

# Launch the app
if __name__ == "__main__":
    demo.launch()