ChuckNoriss commited on
Commit
c0dba68
·
verified ·
1 Parent(s): 0f4bc7f

make a game like agar.io but its not multiplayer - Initial Deployment

Browse files
Files changed (3) hide show
  1. README.md +6 -4
  2. index.html +373 -18
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Blobio
3
- emoji: 🔥
4
  colorFrom: pink
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: blobio
3
+ emoji: 🐳
4
  colorFrom: pink
5
+ colorTo: purple
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,374 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Blob.io - Single Player Agar.io Clone</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
9
+ <script src="https://unpkg.com/feather-icons"></script>
10
+ <style>
11
+ body {
12
+ margin: 0;
13
+ overflow: hidden;
14
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
15
+ }
16
+ canvas {
17
+ display: block;
18
+ background-color: #f0f9ff;
19
+ }
20
+ #gameUI {
21
+ position: absolute;
22
+ top: 0;
23
+ left: 0;
24
+ width: 100%;
25
+ pointer-events: none;
26
+ }
27
+ #scoreContainer {
28
+ background-color: rgba(255, 255, 255, 0.8);
29
+ border-radius: 9999px;
30
+ padding: 0.5rem 1rem;
31
+ margin: 1rem;
32
+ display: inline-flex;
33
+ align-items: center;
34
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
35
+ }
36
+ #startScreen, #gameOverScreen {
37
+ position: absolute;
38
+ top: 0;
39
+ left: 0;
40
+ width: 100%;
41
+ height: 100%;
42
+ display: flex;
43
+ flex-direction: column;
44
+ justify-content: center;
45
+ align-items: center;
46
+ background-color: rgba(0, 0, 0, 0.5);
47
+ color: white;
48
+ }
49
+ .btn {
50
+ pointer-events: auto;
51
+ background-color: #3b82f6;
52
+ color: white;
53
+ border: none;
54
+ padding: 0.75rem 1.5rem;
55
+ border-radius: 0.375rem;
56
+ font-weight: 600;
57
+ cursor: pointer;
58
+ transition: all 0.2s;
59
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
60
+ }
61
+ .btn:hover {
62
+ background-color: #2563eb;
63
+ transform: translateY(-2px);
64
+ }
65
+ .btn:active {
66
+ transform: translateY(0);
67
+ }
68
+ .hidden {
69
+ display: none !important;
70
+ }
71
+ </style>
72
+ </head>
73
+ <body>
74
+ <canvas id="gameCanvas"></canvas>
75
+
76
+ <div id="gameUI">
77
+ <div id="scoreContainer" class="flex items-center">
78
+ <i data-feather="award" class="mr-2"></i>
79
+ <span id="score">0</span>
80
+ </div>
81
+ </div>
82
+
83
+ <div id="startScreen">
84
+ <h1 class="text-4xl font-bold mb-6">Blob.io</h1>
85
+ <p class="text-xl mb-8 text-center max-w-md px-4">Eat smaller blobs to grow bigger. Avoid larger blobs!</p>
86
+ <button id="startBtn" class="btn">Start Game</button>
87
+ </div>
88
+
89
+ <div id="gameOverScreen" class="hidden">
90
+ <h1 class="text-4xl font-bold mb-4">Game Over</h1>
91
+ <p class="text-xl mb-2">Your score: <span id="finalScore">0</span></p>
92
+ <p class="text-lg mb-8">High score: <span id="highScore">0</span></p>
93
+ <button id="restartBtn" class="btn">Play Again</button>
94
+ </div>
95
+
96
+ <script>
97
+ feather.replace();
98
+
99
+ // Game variables
100
+ const canvas = document.getElementById('gameCanvas');
101
+ const ctx = canvas.getContext('2d');
102
+ const scoreElement = document.getElementById('score');
103
+ const finalScoreElement = document.getElementById('finalScore');
104
+ const highScoreElement = document.getElementById('highScore');
105
+ const startScreen = document.getElementById('startScreen');
106
+ const gameOverScreen = document.getElementById('gameOverScreen');
107
+ const startBtn = document.getElementById('startBtn');
108
+ const restartBtn = document.getElementById('restartBtn');
109
+
110
+ // Set canvas size
111
+ function resizeCanvas() {
112
+ canvas.width = window.innerWidth;
113
+ canvas.height = window.innerHeight;
114
+ }
115
+ resizeCanvas();
116
+ window.addEventListener('resize', resizeCanvas);
117
+
118
+ // Game state
119
+ let gameRunning = false;
120
+ let score = 0;
121
+ let highScore = localStorage.getItem('highScore') || 0;
122
+ highScoreElement.textContent = highScore;
123
+
124
+ // Player blob
125
+ const player = {
126
+ x: canvas.width / 2,
127
+ y: canvas.height / 2,
128
+ radius: 20,
129
+ color: '#3b82f6',
130
+ speed: 5
131
+ };
132
+
133
+ // Food blobs
134
+ let food = [];
135
+ const foodColors = ['#ef4444', '#f59e0b', '#10b981', '#3b82f6', '#8b5cf6', '#ec4899'];
136
+
137
+ // Enemy blobs
138
+ let enemies = [];
139
+ const enemyColors = ['#dc2626', '#ea580c', '#059669', '#1d4ed8', '#7e22ce', '#be185d'];
140
+
141
+ // Mouse position
142
+ let mouseX = player.x;
143
+ let mouseY = player.y;
144
+
145
+ // Initialize game
146
+ function initGame() {
147
+ score = 0;
148
+ scoreElement.textContent = score;
149
+ player.radius = 20;
150
+ player.x = canvas.width / 2;
151
+ player.y = canvas.height / 2;
152
+ food = [];
153
+ enemies = [];
154
+
155
+ // Create initial food
156
+ for (let i = 0; i < 50; i++) {
157
+ createFood();
158
+ }
159
+
160
+ // Create initial enemies
161
+ for (let i = 0; i < 5; i++) {
162
+ createEnemy();
163
+ }
164
+ }
165
+
166
+ // Create food blob
167
+ function createFood() {
168
+ const radius = Math.random() * 10 + 5;
169
+ food.push({
170
+ x: Math.random() * canvas.width,
171
+ y: Math.random() * canvas.height,
172
+ radius: radius,
173
+ color: foodColors[Math.floor(Math.random() * foodColors.length)],
174
+ speedX: (Math.random() - 0.5) * 2,
175
+ speedY: (Math.random() - 0.5) * 2
176
+ });
177
+ }
178
+
179
+ // Create enemy blob
180
+ function createEnemy() {
181
+ const radius = Math.random() * 30 + 20;
182
+ enemies.push({
183
+ x: Math.random() * canvas.width,
184
+ y: Math.random() * canvas.height,
185
+ radius: radius,
186
+ color: enemyColors[Math.floor(Math.random() * enemyColors.length)],
187
+ speedX: (Math.random() - 0.5) * 2,
188
+ speedY: (Math.random() - 0.5) * 2
189
+ });
190
+ }
191
+
192
+ // Check collision between two circles
193
+ function checkCollision(circle1, circle2) {
194
+ const dx = circle1.x - circle2.x;
195
+ const dy = circle1.y - circle2.y;
196
+ const distance = Math.sqrt(dx * dx + dy * dy);
197
+ return distance < circle1.radius + circle2.radius;
198
+ }
199
+
200
+ // Game loop
201
+ function gameLoop() {
202
+ if (!gameRunning) return;
203
+
204
+ // Clear canvas
205
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
206
+
207
+ // Move player toward mouse
208
+ const dx = mouseX - player.x;
209
+ const dy = mouseY - player.y;
210
+ const distance = Math.sqrt(dx * dx + dy * dy);
211
+
212
+ if (distance > 5) {
213
+ player.x += dx / distance * player.speed;
214
+ player.y += dy / distance * player.speed;
215
+ }
216
+
217
+ // Draw player
218
+ ctx.beginPath();
219
+ ctx.arc(player.x, player.y, player.radius, 0, Math.PI * 2);
220
+ ctx.fillStyle = player.color;
221
+ ctx.fill();
222
+ ctx.closePath();
223
+
224
+ // Draw food
225
+ for (let i = 0; i < food.length; i++) {
226
+ const blob = food[i];
227
+
228
+ // Move food
229
+ blob.x += blob.speedX;
230
+ blob.y += blob.speedY;
231
+
232
+ // Bounce off walls
233
+ if (blob.x - blob.radius < 0 || blob.x + blob.radius > canvas.width) {
234
+ blob.speedX = -blob.speedX;
235
+ }
236
+ if (blob.y - blob.radius < 0 || blob.y + blob.radius > canvas.height) {
237
+ blob.speedY = -blob.speedY;
238
+ }
239
+
240
+ // Draw food
241
+ ctx.beginPath();
242
+ ctx.arc(blob.x, blob.y, blob.radius, 0, Math.PI * 2);
243
+ ctx.fillStyle = blob.color;
244
+ ctx.fill();
245
+ ctx.closePath();
246
+
247
+ // Check collision with player
248
+ if (checkCollision(player, blob)) {
249
+ // Player can only eat smaller or equal size food
250
+ if (player.radius >= blob.radius) {
251
+ // Increase player size and score
252
+ player.radius += blob.radius * 0.2;
253
+ score += Math.floor(blob.radius);
254
+ scoreElement.textContent = score;
255
+
256
+ // Remove food and create new one
257
+ food.splice(i, 1);
258
+ createFood();
259
+ i--;
260
+ }
261
+ }
262
+ }
263
+
264
+ // Draw enemies
265
+ for (let i = 0; i < enemies.length; i++) {
266
+ const enemy = enemies[i];
267
+
268
+ // Move enemy
269
+ enemy.x += enemy.speedX;
270
+ enemy.y += enemy.speedY;
271
+
272
+ // Bounce off walls
273
+ if (enemy.x - enemy.radius < 0 || enemy.x + enemy.radius > canvas.width) {
274
+ enemy.speedX = -enemy.speedX;
275
+ }
276
+ if (enemy.y - enemy.radius < 0 || enemy.y + enemy.radius > canvas.height) {
277
+ enemy.speedY = -enemy.speedY;
278
+ }
279
+
280
+ // Draw enemy
281
+ ctx.beginPath();
282
+ ctx.arc(enemy.x, enemy.y, enemy.radius, 0, Math.PI * 2);
283
+ ctx.fillStyle = enemy.color;
284
+ ctx.fill();
285
+ ctx.closePath();
286
+
287
+ // Check collision with player
288
+ if (checkCollision(player, enemy)) {
289
+ // Enemy can eat player if larger
290
+ if (enemy.radius > player.radius * 1.1) {
291
+ gameOver();
292
+ return;
293
+ }
294
+ // Player can eat enemy if significantly larger
295
+ else if (player.radius > enemy.radius * 1.5) {
296
+ // Increase player size and score
297
+ player.radius += enemy.radius * 0.3;
298
+ score += Math.floor(enemy.radius * 2);
299
+ scoreElement.textContent = score;
300
+
301
+ // Remove enemy and create new one
302
+ enemies.splice(i, 1);
303
+ createEnemy();
304
+ i--;
305
+ }
306
+ }
307
+
308
+ // Check collision with food
309
+ for (let j = 0; j < food.length; j++) {
310
+ if (checkCollision(enemy, food[j]) && enemy.radius > food[j].radius) {
311
+ // Enemy eats food
312
+ enemy.radius += food[j].radius * 0.1;
313
+ food.splice(j, 1);
314
+ createFood();
315
+ j--;
316
+ }
317
+ }
318
+ }
319
+
320
+ // Occasionally add more food and enemies
321
+ if (Math.random() < 0.01) {
322
+ createFood();
323
+ }
324
+ if (Math.random() < 0.005) {
325
+ createEnemy();
326
+ }
327
+
328
+ requestAnimationFrame(gameLoop);
329
+ }
330
+
331
+ // Game over
332
+ function gameOver() {
333
+ gameRunning = false;
334
+ finalScoreElement.textContent = score;
335
+
336
+ // Update high score
337
+ if (score > highScore) {
338
+ highScore = score;
339
+ highScoreElement.textContent = highScore;
340
+ localStorage.setItem('highScore', highScore);
341
+ }
342
+
343
+ gameOverScreen.classList.remove('hidden');
344
+ }
345
+
346
+ // Event listeners
347
+ canvas.addEventListener('mousemove', (e) => {
348
+ mouseX = e.clientX;
349
+ mouseY = e.clientY;
350
+ });
351
+
352
+ // Touch support for mobile
353
+ canvas.addEventListener('touchmove', (e) => {
354
+ e.preventDefault();
355
+ mouseX = e.touches[0].clientX;
356
+ mouseY = e.touches[0].clientY;
357
+ }, { passive: false });
358
+
359
+ startBtn.addEventListener('click', () => {
360
+ startScreen.classList.add('hidden');
361
+ gameRunning = true;
362
+ initGame();
363
+ gameLoop();
364
+ });
365
+
366
+ restartBtn.addEventListener('click', () => {
367
+ gameOverScreen.classList.add('hidden');
368
+ gameRunning = true;
369
+ initGame();
370
+ gameLoop();
371
+ });
372
+ </script>
373
+ </body>
374
  </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ make a game like agar.io but its not multiplayer