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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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Flappy Bird Clone</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            overflow: hidden;
            touch-action: manipulation;
            -webkit-tap-highlight-color: transparent;
            font-family: 'Arial', sans-serif;
        }
        
        #gameCanvas {
            display: block;
            background-color: #70c5ce;
            touch-action: none;
        }
        
        #gameContainer {
            position: relative;
            width: 100%;
            height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        
        #startScreen, #gameOverScreen {
            position: absolute;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background-color: rgba(0, 0, 0, 0.5);
            color: white;
            z-index: 10;
        }
        
        .btn {
            background-color: #f8d347;
            color: #333;
            border: none;
            padding: 12px 24px;
            font-size: 18px;
            border-radius: 30px;
            cursor: pointer;
            margin-top: 20px;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            transition: all 0.2s;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
        }
        
        .btn:active {
            transform: translateY(1px);
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }
        
        .title {
            font-size: 3rem;
            font-weight: bold;
            margin-bottom: 20px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
            color: #f8d347;
        }
        
        .score-display {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 2rem;
            font-weight: bold;
            color: white;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
            z-index: 5;
        }
        
        .instructions {
            text-align: center;
            margin-bottom: 20px;
            font-size: 1.2rem;
            max-width: 80%;
        }
        
        @media (max-width: 600px) {
            .title {
                font-size: 2rem;
            }
            
            .btn {
                padding: 10px 20px;
                font-size: 16px;
            }
            
            .instructions {
                font-size: 1rem;
            }
        }
    </style>
</head>
<body class="bg-gray-900">
    <div id="gameContainer" class="w-full h-screen">
        <div id="score" class="score-display">0</div>
        
        <canvas id="gameCanvas"></canvas>
        
        <div id="startScreen">
            <h1 class="title">FLAPPY BIRD</h1>
            <p class="instructions text-white">Toque na tela para fazer o pássaro voar e passar pelos canos!</p>
            <button id="startBtn" class="btn">COMEÇAR</button>
        </div>
        
        <div id="gameOverScreen" style="display: none;">
            <h1 class="title">GAME OVER</h1>
            <p id="finalScore" class="text-white text-2xl mb-4">Pontuação: 0</p>
            <p id="highScore" class="text-white text-xl mb-6">Recorde: 0</p>
            <button id="restartBtn" class="btn">JOGAR NOVAMENTE</button>
        </div>
    </div>

    <script>
        // Game variables
        const canvas = document.getElementById('gameCanvas');
        const ctx = canvas.getContext('2d');
        const startScreen = document.getElementById('startScreen');
        const gameOverScreen = document.getElementById('gameOverScreen');
        const startBtn = document.getElementById('startBtn');
        const restartBtn = document.getElementById('restartBtn');
        const scoreDisplay = document.getElementById('score');
        const finalScoreDisplay = document.getElementById('finalScore');
        const highScoreDisplay = document.getElementById('highScore');
        
        // Set canvas size
        function resizeCanvas() {
            const container = document.getElementById('gameContainer');
            canvas.width = container.clientWidth;
            canvas.height = container.clientHeight;
        }
        
        resizeCanvas();
        window.addEventListener('resize', resizeCanvas);
        
        // Game state
        let gameRunning = false;
        let score = 0;
        let highScore = localStorage.getItem('flappyHighScore') || 0;
        let animationId;
        
        // Bird properties
        const bird = {
            x: 100,
            y: canvas.height / 2,
            width: 40,
            height: 30,
            velocity: 0,
            gravity: 0.5,
            jumpForce: -10,
            color: '#f8d347',
            
            update: function() {
                this.velocity += this.gravity;
                this.y += this.velocity;
                
                // Check if bird hits the ground or ceiling
                if (this.y + this.height > canvas.height) {
                    this.y = canvas.height - this.height;
                    gameOver();
                }
                
                if (this.y < 0) {
                    this.y = 0;
                    gameOver();
                }
            },
            
            jump: function() {
                this.velocity = this.jumpForce;
            },
            
            draw: function() {
                ctx.fillStyle = this.color;
                
                // Draw bird body
                ctx.beginPath();
                ctx.ellipse(this.x + this.width/2, this.y + this.height/2, 
                            this.width/2, this.height/2, 0, 0, Math.PI * 2);
                ctx.fill();
                
                // Draw beak
                ctx.fillStyle = '#f39c12';
                ctx.beginPath();
                ctx.moveTo(this.x + this.width, this.y + this.height/2);
                ctx.lineTo(this.x + this.width + 15, this.y + this.height/2);
                ctx.lineTo(this.x + this.width, this.y + this.height/2 + 8);
                ctx.fill();
                
                // Draw eye
                ctx.fillStyle = 'black';
                ctx.beginPath();
                ctx.arc(this.x + this.width/2 + 5, this.y + this.height/2 - 5, 3, 0, Math.PI * 2);
                ctx.fill();
                
                // Draw wings (animated based on velocity)
                ctx.fillStyle = '#f1c40f';
                const wingY = this.y + this.height/2;
                const wingHeight = Math.abs(this.velocity) * 2 + 5;
                
                ctx.beginPath();
                ctx.ellipse(this.x + this.width/2, wingY, 
                            this.width/2, wingHeight, Math.PI/4, 0, Math.PI * 2);
                ctx.fill();
            },
            
            getBounds: function() {
                return {
                    x: this.x,
                    y: this.y,
                    width: this.width,
                    height: this.height
                };
            }
        };
        
        // Pipes
        const pipes = {
            list: [],
            width: 60,
            gap: 150,
            speed: 3,
            frequency: 1500, // ms
            lastPipeTime: 0,
            
            update: function(timestamp) {
                // Add new pipes
                if (timestamp - this.lastPipeTime > this.frequency) {
                    this.addPipe();
                    this.lastPipeTime = timestamp;
                }
                
                // Move and remove off-screen pipes
                for (let i = this.list.length - 1; i >= 0; i--) {
                    this.list[i].x -= this.speed;
                    
                    // Check if pipe is passed by bird (for scoring)
                    if (!this.list[i].passed && this.list[i].x + this.width < bird.x) {
                        this.list[i].passed = true;
                        score++;
                        scoreDisplay.textContent = score;
                    }
                    
                    // Remove pipes that are off screen
                    if (this.list[i].x + this.width < 0) {
                        this.list.splice(i, 1);
                    }
                }
            },
            
            addPipe: function() {
                const minHeight = 50;
                const maxHeight = canvas.height - this.gap - minHeight;
                const height = Math.floor(Math.random() * (maxHeight - minHeight + 1)) + minHeight;
                
                this.list.push({
                    x: canvas.width,
                    height: height,
                    passed: false
                });
            },
            
            draw: function() {
                ctx.fillStyle = '#27ae60';
                
                for (const pipe of this.list) {
                    // Top pipe
                    ctx.fillRect(pipe.x, 0, this.width, pipe.height);
                    
                    // Bottom pipe
                    const bottomY = pipe.height + this.gap;
                    ctx.fillRect(pipe.x, bottomY, this.width, canvas.height - bottomY);
                    
                    // Pipe edges
                    ctx.fillStyle = '#2ecc71';
                    ctx.fillRect(pipe.x - 5, pipe.height - 20, this.width + 10, 20);
                    ctx.fillRect(pipe.x - 5, bottomY, this.width + 10, 20);
                    
                    ctx.fillStyle = '#27ae60';
                }
            },
            
            checkCollision: function() {
                const birdBounds = bird.getBounds();
                
                for (const pipe of this.list) {
                    const bottomY = pipe.height + this.gap;
                    
                    // Check collision with top pipe
                    if (birdBounds.x + birdBounds.width > pipe.x && 
                        birdBounds.x < pipe.x + this.width &&
                        birdBounds.y < pipe.height) {
                        return true;
                    }
                    
                    // Check collision with bottom pipe
                    if (birdBounds.x + birdBounds.width > pipe.x && 
                        birdBounds.x < pipe.x + this.width &&
                        birdBounds.y + birdBounds.height > bottomY) {
                        return true;
                    }
                }
                
                return false;
            }
        };
        
        // Background elements
        const background = {
            clouds: [],
            lastCloudTime: 0,
            cloudFrequency: 3000,
            
            init: function() {
                // Create initial clouds
                for (let i = 0; i < 3; i++) {
                    this.addCloud(Math.random() * canvas.width);
                }
            },
            
            addCloud: function(x) {
                const size = Math.random() * 30 + 20;
                const y = Math.random() * (canvas.height / 3);
                const speed = Math.random() * 0.5 + 0.5;
                
                this.clouds.push({
                    x: x,
                    y: y,
                    size: size,
                    speed: speed
                });
            },
            
            update: function(timestamp) {
                // Add new clouds
                if (timestamp - this.lastCloudTime > this.cloudFrequency) {
                    this.addCloud(canvas.width);
                    this.lastCloudTime = timestamp;
                }
                
                // Move clouds
                for (let i = this.clouds.length - 1; i >= 0; i--) {
                    this.clouds[i].x -= this.clouds[i].speed;
                    
                    // Remove off-screen clouds
                    if (this.clouds[i].x + this.clouds[i].size * 2 < 0) {
                        this.clouds.splice(i, 1);
                    }
                }
            },
            
            draw: function() {
                // Draw sky gradient
                const skyGradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
                skyGradient.addColorStop(0, '#70c5ce');
                skyGradient.addColorStop(1, '#2980b9');
                ctx.fillStyle = skyGradient;
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                
                // Draw clouds
                ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
                for (const cloud of this.clouds) {
                    // Draw multiple circles to form a cloud
                    ctx.beginPath();
                    ctx.arc(cloud.x, cloud.y, cloud.size, 0, Math.PI * 2);
                    ctx.arc(cloud.x + cloud.size * 0.6, cloud.y - cloud.size * 0.2, cloud.size * 0.8, 0, Math.PI * 2);
                    ctx.arc(cloud.x + cloud.size * 1.3, cloud.y, cloud.size * 0.7, 0, Math.PI * 2);
                    ctx.arc(cloud.x + cloud.size * 0.8, cloud.y + cloud.size * 0.3, cloud.size * 0.6, 0, Math.PI * 2);
                    ctx.fill();
                }
                
                // Draw ground
                ctx.fillStyle = '#27ae60';
                ctx.fillRect(0, canvas.height - 20, canvas.width, 20);
            }
        };
        
        // Game functions
        function startGame() {
            startScreen.style.display = 'none';
            gameOverScreen.style.display = 'none';
            gameRunning = true;
            
            // Reset game state
            score = 0;
            scoreDisplay.textContent = '0';
            bird.y = canvas.height / 2;
            bird.velocity = 0;
            pipes.list = [];
            pipes.lastPipeTime = 0;
            
            background.init();
            
            // Start game loop
            lastTime = 0;
            animationId = requestAnimationFrame(gameLoop);
        }
        
        function gameOver() {
            gameRunning = false;
            cancelAnimationFrame(animationId);
            
            // Update high score
            if (score > highScore) {
                highScore = score;
                localStorage.setItem('flappyHighScore', highScore);
            }
            
            // Show game over screen
            finalScoreDisplay.textContent = `Pontuação: ${score}`;
            highScoreDisplay.textContent = `Recorde: ${highScore}`;
            gameOverScreen.style.display = 'flex';
        }
        
        function gameLoop(timestamp) {
            // Clear canvas
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            
            // Update and draw background
            background.update(timestamp);
            background.draw();
            
            // Update and draw pipes
            pipes.update(timestamp);
            pipes.draw();
            
            // Update and draw bird
            bird.update();
            bird.draw();
            
            // Check collisions
            if (pipes.checkCollision()) {
                gameOver();
                return;
            }
            
            // Continue game loop
            if (gameRunning) {
                animationId = requestAnimationFrame(gameLoop);
            }
        }
        
        // Event listeners
        startBtn.addEventListener('click', startGame);
        restartBtn.addEventListener('click', startGame);
        
        // Touch and click controls
        canvas.addEventListener('click', function() {
            if (gameRunning) {
                bird.jump();
            }
        });
        
        canvas.addEventListener('touchstart', function(e) {
            e.preventDefault();
            if (gameRunning) {
                bird.jump();
            }
        }, { passive: false });
        
        // Prevent scrolling on touch
        document.addEventListener('touchmove', function(e) {
            if (gameRunning) {
                e.preventDefault();
            }
        }, { passive: false });
    </script>
<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=Matheusxtx/games" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>