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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69d3766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Space Cylinder Defender</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        @keyframes bombExplosion {
            0% { transform: scale(0); opacity: 1; }
            100% { transform: scale(20); opacity: 0; }
        }
        
        .bomb-effect {
            animation: bombExplosion 2s forwards;
            background-color: #f5f5f5;
            border-radius: 50%;
            position: absolute;
            mix-blend-mode: screen;
            pointer-events: none;
        }
        
        body {
            overflow: hidden;
            touch-action: none;
            background-color: #000;
        }
        
        #gameCanvas {
            display: block;
            background-color: #111;
        }
        
        #gameContainer {
            position: relative;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
        }
        
        #scoreDisplay {
            position: absolute;
            top: 20px;
            left: 20px;
            color: white;
            font-family: 'Arial', sans-serif;
            font-size: 24px;
            z-index: 10;
        }
        
        #startScreen, #gameOverScreen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background-color: rgba(0, 0, 0, 0.7);
            color: white;
            z-index: 20;
        }
        
        .hidden {
            display: none !important;
        }
        
        .btn {
            background-color: #4f46e5;
            color: white;
            padding: 12px 24px;
            border-radius: 8px;
            font-size: 18px;
            margin-top: 20px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .btn:hover {
            background-color: #6366f1;
            transform: scale(1.05);
        }
        
        .title {
            font-size: 48px;
            margin-bottom: 20px;
            text-shadow: 0 0 10px #6366f1;
        }
        
        .instructions {
            max-width: 500px;
            text-align: center;
            margin-bottom: 30px;
            line-height: 1.6;
        }
    </style>
</head>
<body>
    <div id="gameContainer">
        <canvas id="gameCanvas"></canvas>
        <div id="scoreDisplay">Score: 0</div>
        
        <div id="startScreen">
            <h1 class="title">Space Cylinder Defender</h1>
            <p class="instructions">
                Defend against the egg invasion! Your cylinder body can shoot white blasters from its dome-shaped front.
                Reach 100 points to unleash a devastating bomb that will wipe out all eggs!
            </p>
            <button id="startBtn" class="btn">Start Game</button>
        </div>
        
        <div id="gameOverScreen" class="hidden">
            <h1 class="title">Game Over</h1>
            <p id="finalScore" class="instructions">Your score: 0</p>
            <button id="restartBtn" class="btn">Play Again</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const canvas = document.getElementById('gameCanvas');
            const ctx = canvas.getContext('2d');
            const scoreDisplay = document.getElementById('scoreDisplay');
            const startScreen = document.getElementById('startScreen');
            const gameOverScreen = document.getElementById('gameOverScreen');
            const finalScore = document.getElementById('finalScore');
            const startBtn = document.getElementById('startBtn');
            const restartBtn = document.getElementById('restartBtn');
            
            // Set canvas size
            function resizeCanvas() {
                canvas.width = window.innerWidth;
                canvas.height = window.innerHeight;
            }
            
            resizeCanvas();
            window.addEventListener('resize', resizeCanvas);
            
            // Game variables
            let score = 0;
            let gameRunning = false;
            let animationId;
            let lastTime = 0;
            
            // Player
            const player = {
                x: 100,
                y: canvas.height / 2,
                width: 40,
                height: 30,
              
                speed: 5,
                blasters: [],
                lastShot: 0,
                shootDelay: 300,
                color: '#e2c8a8',
                hit: false
            };
            
            // Enemies
            const enemies = [];
            const enemyColors = ['#ffb6c1', '#ffc0cb', '#ff69b4', '#db7093', '#ff1493']; // Pink colors for eggs
            let enemySpawnTimer = 0;
            const enemySpawnDelay = 1000;
            
            // Game state
            let keys = {
                ArrowUp: false,
                ArrowDown: false,
                ArrowLeft: false,
                ArrowRight: false,
                Space: false
            };
            
            // Event listeners
            document.addEventListener('keydown', (e) => {
                if (keys.hasOwnProperty(e.code)) {
                    keys[e.code] = true;
                }
            });
            
            document.addEventListener('keyup', (e) => {
                if (keys.hasOwnProperty(e.code)) {
                    keys[e.code] = false;
                }
            });
            
            // Touch controls for mobile
            canvas.addEventListener('touchstart', handleTouch);
            canvas.addEventListener('touchmove', handleTouch);
            
            function handleTouch(e) {
                e.preventDefault();
                if (!gameRunning) return;
                
                const touch = e.touches[0];
                const touchY = touch.clientY;
                
                // Move player to touch position
                player.y = touchY;
                
                // Shoot if not recently shot
                const now = Date.now();
                if (now - player.lastShot > player.shootDelay) {
                    shootBlaster();
                    player.lastShot = now;
                }
            }
            
            startBtn.addEventListener('click', startGame);
            restartBtn.addEventListener('click', startGame);
            
            function startGame() {
                score = 0;
                scoreDisplay.textContent = `Score: ${score}`;
                player.x = 100;
                player.y = canvas.height / 2;
                player.blasters = [];
                enemies.length = 0;
                player.hit = false;
                
                startScreen.classList.add('hidden');
                gameOverScreen.classList.add('hidden');
                gameRunning = true;
                
                lastTime = performance.now();
                gameLoop(lastTime);
            }
            
            function gameLoop(timestamp) {
                if (!gameRunning) return;
                
                const deltaTime = timestamp - lastTime;
                lastTime = timestamp;
                
                update(deltaTime);
                render();
                
                animationId = requestAnimationFrame(gameLoop);
            }
            
            function update(deltaTime) {
                // Player movement
                if (keys.ArrowUp) player.y -= player.speed;
                if (keys.ArrowDown) player.y += player.speed;
                if (keys.ArrowLeft) player.x -= player.speed;
                if (keys.ArrowRight) player.x += player.speed;
                
                // Keep player in bounds
                player.x = Math.max(0, Math.min(canvas.width - player.width, player.x));
                player.y = Math.max(0, Math.min(canvas.height - player.height, player.y));
                
                // Shooting
                if (keys.Space && Date.now() - player.lastShot > player.shootDelay) {
                    shootBlaster();
                    player.lastShot = Date.now();
                }
                
                // Update blasters
                for (let i = player.blasters.length - 1; i >= 0; i--) {
                    player.blasters[i].x += player.blasters[i].speed;
                    
                    // Remove blasters that go off screen
                    if (player.blasters[i].x > canvas.width) {
                        player.blasters.splice(i, 1);
                        continue;
                    }
                    
                    // Check for collisions with enemies (ignore babies)
                    for (let j = enemies.length - 1; j >= 0; j--) {
                        if (!enemies[j].isBaby && checkCollision(player.blasters[i], enemies[j])) {
                            // Create baby from destroyed egg
                            const baby = {
                                x: enemies[j].x,
                                y: enemies[j].y,
                                width: enemies[j].width / 2,
                                height: enemies[j].height / 2,
                                speed: 1,
                                color: '#ffcccb',
                                isBaby: true,
                                phrase: '',
                                showPhrase: false
                            };
                            
                            // Set random phrase after 1 seconds
                            setTimeout(() => {
                                const phrases = ['daddy', 'dad', 'duhduh', 'child support', 'milky'];
                                baby.phrase = phrases[Math.floor(Math.random() * phrases.length)];
                                baby.showPhrase = true;
                                
                                // Hide phrase after 2 seconds
                                setTimeout(() => {
                                    baby.showPhrase = false;
                                }, 3000);
                            }, 2000);
                            
                            player.blasters.splice(i, 1);
                            enemies.splice(j, 1);
                            enemies.push(baby);
                            score++;
                            scoreDisplay.textContent = `Score: ${score}`;
                            
                            // Check for bomb condition
                            if (score >= 100) {
                                triggerBomb();
                                score = 100; // Cap at 100
                                scoreDisplay.textContent = `Score: ${score}`;
                            }
                            break;
                        }
                    }
                }
                
                // Spawn enemies
                enemySpawnTimer += deltaTime;
                if (enemySpawnTimer > enemySpawnDelay) {
                    spawnEnemy();
                    enemySpawnTimer = 0;
                }
                
                // Update enemies
                for (let i = enemies.length - 1; i >= 0; i--) {
                    enemies[i].x -= enemies[i].speed;
                    
                    // Remove enemies that go off screen
                    if (enemies[i].x + enemies[i].width < 0) {
                        enemies.splice(i, 1);
                        continue;
                    }
                    
                    // Check for collision with player (only non-baby enemies)
                    if (!enemies[i].isBaby && checkCollision(player, enemies[i])) {
                        gameOver();
                        break;
                    }
                }
            }
            
            function render() {
                // Clear canvas
                ctx.clearRect(0, 0, canvas.width, canvas.height);
                
                // Draw stars (background)
                drawStars();
                
                // Draw player
                drawPlayer();
                
                // Draw blasters
                player.blasters.forEach(blaster => {
                    ctx.fillStyle = blaster.color;
                    ctx.beginPath();
                    ctx.arc(blaster.x, blaster.y, blaster.radius, 0, Math.PI * 2);
                    ctx.fill();
                });
                
                // Draw enemies
                enemies.forEach(enemy => {
                    drawEnemy(enemy);
                });
            }
            
            function drawStars() {
                ctx.fillStyle = 'white';
                for (let i = 0; i < 100; i++) {
                    const x = Math.random() * canvas.width;
                    const y = Math.random() * canvas.height;
                    const size = Math.random() * 2;
                    ctx.fillRect(x, y, size, size);
                }
            }
            
            function drawPlayer() {
                // Main cylinder body (longer section)
                ctx.fillStyle = player.color;
                const cylinderLength = player.width * 1.2; // Make cylinder slightly longer but proportional
                ctx.fillRect(player.x, player.y, cylinderLength, player.height);
                
                // Smaller dome-shaped front
                ctx.beginPath();
                ctx.ellipse(
                    player.x + cylinderLength, 
                    player.y + player.height / 2, 
                    player.width / 2,  // Smaller width
                    player.height / 2, // Smaller height
                    0, 
                    -Math.PI / 2, 
                    Math.PI / 2
                );
                ctx.fill();
                
                // Two bigger circles on the back with single connecting cylinder
                const backX = player.x - 10; // Position circles closer due to smaller cylinder
                ctx.fillStyle = player.color;
                
                // Single connecting cylinder from main body to both balls
                ctx.fillRect(backX + 10, player.y + player.height / 4, 10, player.height / 2);
                
                // Draw the two bigger balls
                ctx.beginPath();
                ctx.arc(backX, player.y + player.height / 8, 18, 0, Math.PI * 2); // Bigger radius
                ctx.fill();
                
                ctx.beginPath();
                ctx.arc(backX, player.y + (player.height / 3) * 3, 18, 0, Math.PI * 2); // Bigger radius
                ctx.fill();
                
                // If hit, flash red
                if (player.hit) {
                    ctx.fillStyle = 'rgba(255, 0, 0, 0.5)';
                    ctx.fillRect(player.x, player.y, player.width, player.height);
                    player.hit = false;
                }
            }
            
            function drawEnemy(enemy) {
                if (enemy.isBaby) {
                    // Draw baby only
                    ctx.fillStyle = enemy.color;
                    ctx.beginPath();
                    ctx.ellipse(
                        enemy.x + enemy.width / 2,
                        enemy.y + enemy.height / 2,
                        enemy.width / 2,
                        enemy.height / 2,
                        0,
                        0,
                        Math.PI * 2
                    );
                    ctx.fill();
                    
                    // Baby eyes
                    ctx.fillStyle = 'black';
                    ctx.beginPath();
                    ctx.arc(enemy.x + enemy.width / 3, enemy.y + enemy.height / 3, 2, 0, Math.PI * 2);
                    ctx.fill();
                    
                    ctx.beginPath();
                    ctx.arc(enemy.x + (enemy.width / 3) * 2, enemy.y + enemy.height / 3, 2, 0, Math.PI * 2);
                    ctx.fill();
                    
                    // Baby mouth (smile)
                    ctx.strokeStyle = 'black';
                    ctx.lineWidth = 1;
                    ctx.beginPath();
                    ctx.arc(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, enemy.width / 4, 0, Math.PI);
                    ctx.stroke();
                    
                    // Show phrase if active
                    if (enemy.showPhrase) {
                        ctx.font = '12px Arial';
                        ctx.fillStyle = 'white';
                        ctx.textAlign = 'center';
                        ctx.fillText(enemy.phrase, enemy.x + enemy.width / 2, enemy.y - 10);
                    }
                } else {
                    // Draw egg with baby inside
                    ctx.fillStyle = enemy.color;
                    ctx.beginPath();
                    ctx.ellipse(
                        enemy.x + enemy.width / 2,
                        enemy.y + enemy.height / 2,
                        enemy.width / 2,
                        enemy.height / 2,
                        0,
                        0,
                        Math.PI * 2
                    );
                    ctx.fill();
                    
                    // Egg shell pattern
                    ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
                    ctx.lineWidth = 2;
                    ctx.beginPath();
                    ctx.ellipse(
                        enemy.x + enemy.width / 2,
                        enemy.y + enemy.height / 2,
                        enemy.width / 3,
                        enemy.height / 3,
                        0,
                        0,
                        Math.PI * 2
                    );
                    ctx.stroke();
                    
                    // Baby inside
                    ctx.fillStyle = '#ffcccb';
                    ctx.beginPath();
                    ctx.ellipse(
                        enemy.x + enemy.width / 2,
                        enemy.y + enemy.height / 2,
                        enemy.width / 4,
                        enemy.height / 4,
                        0,
                        0,
                        Math.PI * 2
                    );
                    ctx.fill();
                    
                    // Baby eyes
                    ctx.fillStyle = 'black';
                    ctx.beginPath();
                    ctx.arc(enemy.x + enemy.width / 2.5, enemy.y + enemy.height / 2.5, 2, 0, Math.PI * 2);
                    ctx.fill();
                    
                    ctx.beginPath();
                    ctx.arc(enemy.x + (enemy.width / 2.5) * 1.5, enemy.y + enemy.height / 2.5, 2, 0, Math.PI * 2);
                    ctx.fill();
                }
            }
            
            function shootBlaster() {
                player.blasters.push({
                    x: player.x + player.width,
                    y: player.y + player.height / 2,
                    radius: 5,
                    speed: 10,
                    color: 'white'
                });
            }
            
            function spawnEnemy() {
                const size = 30 + Math.random() * 30;
                enemies.push({
                    x: canvas.width,
                    y: Math.random() * (canvas.height - size),
                    width: size,
                    height: size,
                    speed: 2 + Math.random() * 3,
                    color: enemyColors[Math.floor(Math.random() * enemyColors.length)]
                });
            }
            
            function checkCollision(obj1, obj2) {
                return obj1.x < obj2.x + obj2.width &&
                       obj1.x + (obj1.width || obj1.radius * 2) > obj2.x &&
                       obj1.y < obj2.y + obj2.height &&
                       obj1.y + (obj1.height || obj1.radius * 2) > obj2.y;
            }
            
            function triggerBomb() {
                // Create bomb effect
                const bomb = document.createElement('div');
                bomb.className = 'bomb-effect';
                bomb.style.width = '20px';
                bomb.style.height = '20px';
                bomb.style.left = `${player.x + player.width / 2 - 10}px`;
                bomb.style.top = `${player.y + player.height / 2 - 10}px`;
                document.getElementById('gameContainer').appendChild(bomb);
                
                // Remove all enemies
                enemies.length = 0;
                
                // Remove bomb element after animation
                setTimeout(() => {
                    bomb.remove();
                }, 2000);
            }
            
            function gameOver() {
                gameRunning = false;
                cancelAnimationFrame(animationId);
                
                player.hit = true;
                render(); // Show final frame with hit effect
                
                setTimeout(() => {
                    finalScore.textContent = `Your score: ${score}`;
                    gameOverScreen.classList.remove('hidden');
                }, 500);
            }
        });
    </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=AILOS/dome-blaster" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>