summaryrefslogtreecommitdiff
path: root/lemmings/index.html
blob: c85be4bfa8e7d892de1dc48a224d912ce4a1675e (plain)
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
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lemmings</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=VT323&family=Fredoka:wght@400;600&display=swap"
        rel="stylesheet">
    <script src="https://cdn.usefathom.com/script.js" data-site="YZVJPTBZ" defer></script>
    <style>
        body,
        html {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            background-color: #c1a5e8;
            font-family: 'Fredoka', sans-serif;
        }

        .game-container {
            width: 100%;
            height: 100%;
            position: relative;
            background: linear-gradient(to bottom, #7873f5 0%, #c1a5e8 100%);
            overflow: hidden;
        }

        .ground {
            position: absolute;
            bottom: 0;
            width: 100%;
            height: 100px;
            background-color: #5a3d5c;
            image-rendering: pixelated;
        }

        .platform {
            position: absolute;
            height: 20px;
            background-color: #ff6ec4;
            border-top: 3px solid #ffd6e0;
            image-rendering: pixelated;
        }

        .lemming {
            position: absolute;
            width: 20px;
            height: 30px;
            background-color: #5b9bd5;
            /* Blue body */
            border-radius: 10px 10px 0 0;
            z-index: 10;
            image-rendering: pixelated;
        }

        /* Add a tail */
        .lemming::after {
            content: '';
            position: absolute;
            width: 8px;
            height: 8px;
            background-color: #5b9bd5;
            /* Blue tail to match body */
            border-radius: 0 0 50% 50%;
            bottom: -6px;
            left: 6px;
            z-index: -1;
        }

        .lemming::before {
            content: '';
            position: absolute;
            width: 16px;
            height: 16px;
            background-color: #70ad47;
            /* Green head */
            border-radius: 50%;
            top: -10px;
            left: 2px;
        }

        /* Move eye to be a separate element since we used ::after for the tail */
        .lemming .eye {
            position: absolute;
            width: 4px;
            height: 4px;
            background-color: #000000;
            /* Black eye */
            border-radius: 50%;
            top: -5px;
            left: 8px;
        }

        .lemming .hair {
            position: absolute;
            width: 10px;
            height: 5px;
            background-color: #4a7a31;
            /* Darker green hair */
            top: -15px;
            left: 5px;
        }

        /* Add whiskers */
        .lemming .whisker {
            position: absolute;
            height: 1px;
            width: 6px;
            background-color: #ffffff;
            top: -2px;
        }

        .lemming .whisker.left {
            left: -4px;
            transform: rotate(-15deg);
        }

        .lemming .whisker.right {
            right: -4px;
            transform: rotate(15deg);
        }

        .lemming .arm {
            position: absolute;
            width: 8px;
            height: 12px;
            background-color: #5b9bd5;
            border-radius: 4px;
        }

        .lemming .arm.left {
            left: -6px;
            top: 5px;
            transform-origin: top right;
        }

        .lemming .arm.right {
            right: -6px;
            top: 5px;
            transform-origin: top left;
        }

        .lemming .leg {
            position: absolute;
            width: 8px;
            height: 12px;
            background-color: #5b9bd5;
            border-radius: 4px;
            bottom: -10px;
        }

        .lemming .leg.left {
            left: 2px;
        }

        .lemming .leg.right {
            right: 2px;
        }

        .lemming.walking .leg.left {
            animation: legWalk 0.5s infinite alternate;
        }

        .lemming.walking .leg.right {
            animation: legWalk 0.5s infinite alternate-reverse;
        }

        .lemming.walking .arm.left {
            animation: armSwing 0.5s infinite alternate;
        }

        .lemming.walking .arm.right {
            animation: armSwing 0.5s infinite alternate-reverse;
        }

        .lemming.falling .arm.left {
            transform: rotate(45deg);
        }

        .lemming.falling .arm.right {
            transform: rotate(-45deg);
        }

        @keyframes legWalk {
            0% {
                transform: translateY(0);
            }

            100% {
                transform: translateY(-5px);
            }
        }

        @keyframes armSwing {
            0% {
                transform: rotate(-15deg);
            }

            100% {
                transform: rotate(15deg);
            }
        }

        .back-link {
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 100;
            color: #5a3d5c;
            text-decoration: none;
            background: rgba(255, 255, 255, 0.8);
            padding: 10px 15px;
            border-radius: 10px;
            font-family: 'VT323', monospace;
            font-size: 18px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 5px;
            border: 3px solid #ff6ec4;
            box-shadow: 3px 3px 0px #7873f5;
        }

        .back-link:hover {
            background: rgba(255, 255, 255, 1);
            transform: translateY(-3px);
            box-shadow: 5px 5px 0px #7873f5;
        }

        .back-link::before {
            content: "←";
            font-size: 22px;
        }

        .title {
            position: absolute;
            top: 20px;
            left: 0;
            right: 0;
            text-align: center;
            font-family: 'VT323', monospace;
            font-size: 3rem;
            color: #5a3d5c;
            text-shadow: 3px 3px 0px rgba(255, 110, 196, 0.5);
            z-index: 100;
        }

        .subtitle {
            position: absolute;
            top: 100px;
            left: 0;
            right: 0;
            text-align: center;
            font-family: 'VT323', monospace;
            font-size: 1.5rem;
            color: #5a3d5c;
            text-shadow: 3px 3px 0px rgba(255, 110, 196, 0.5);
            z-index: 100;
        }
    </style>
</head>

<body>
    <div class="game-container">
        <a href="../index.html" class="back-link">Back to Home</a>
        <h1 class="title">Lemmings</h1>
        <p class="subtitle">Watch these cute green & blue lemmings explore their world!</p>
        <div class="ground"></div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const gameContainer = document.querySelector('.game-container');
            const ground = document.querySelector('.ground');
            const containerWidth = gameContainer.clientWidth;
            const containerHeight = gameContainer.clientHeight;

            // Create platforms
            const platformCount = 5;
            const platforms = [];

            for (let i = 0; i < platformCount; i++) {
                const platform = document.createElement('div');
                platform.className = 'platform';

                const width = 100 + Math.random() * 200;
                const left = Math.random() * (containerWidth - width);
                const bottom = 120 + Math.random() * (containerHeight - 250);

                platform.style.width = `${width}px`;
                platform.style.left = `${left}px`;
                platform.style.bottom = `${bottom}px`;

                gameContainer.appendChild(platform);
                platforms.push({
                    element: platform,
                    left: left,
                    right: left + width,
                    bottom: bottom,
                    top: bottom + 20
                });
            }

            // Add ground to platforms array
            platforms.push({
                element: ground,
                left: 0,
                right: containerWidth,
                bottom: 0,
                top: 100
            });

            // Create lemmings
            const lemmingCount = 15;
            const lemmings = [];

            for (let i = 0; i < lemmingCount; i++) {
                createLemming();
            }

            function createLemming() {
                const lemming = document.createElement('div');
                lemming.className = 'lemming walking';

                // Add body parts
                const hair = document.createElement('div');
                hair.className = 'hair';
                lemming.appendChild(hair);

                const leftArm = document.createElement('div');
                leftArm.className = 'arm left';
                lemming.appendChild(leftArm);

                const rightArm = document.createElement('div');
                rightArm.className = 'arm right';
                lemming.appendChild(rightArm);

                const leftLeg = document.createElement('div');
                leftLeg.className = 'leg left';
                lemming.appendChild(leftLeg);

                const rightLeg = document.createElement('div');
                rightLeg.className = 'leg right';
                lemming.appendChild(rightLeg);

                const eye = document.createElement('div');
                eye.className = 'eye';
                lemming.appendChild(eye);

                // Add whiskers
                const leftWhisker = document.createElement('div');
                leftWhisker.className = 'whisker left';
                lemming.appendChild(leftWhisker);

                const rightWhisker = document.createElement('div');
                rightWhisker.className = 'whisker right';
                lemming.appendChild(rightWhisker);

                // Random starting position
                const startPlatformIndex = Math.floor(Math.random() * platforms.length);
                const startPlatform = platforms[startPlatformIndex];
                const left = startPlatform.left + Math.random() * (startPlatform.right - startPlatform.left - 20);
                const bottom = startPlatform.top;

                lemming.style.left = `${left}px`;
                lemming.style.bottom = `${bottom}px`;

                gameContainer.appendChild(lemming);

                // Lemming properties
                const lemmingObj = {
                    element: lemming,
                    x: left,
                    y: bottom,
                    width: 20,
                    height: 30,
                    direction: Math.random() > 0.5 ? 1 : -1, // 1 for right, -1 for left
                    speed: 0.5 + Math.random() * 1.5,
                    falling: false,
                    currentPlatform: startPlatform,
                    fallSpeed: 0
                };

                lemmings.push(lemmingObj);

                // Set initial direction
                if (lemmingObj.direction === -1) {
                    lemming.style.transform = 'scaleX(-1)';
                }
            }

            // Game loop
            function update() {
                lemmings.forEach(lemming => {
                    // Move horizontally
                    lemming.x += lemming.direction * lemming.speed;

                    // Check if lemming is on a platform
                    if (!lemming.falling) {
                        // Check if lemming is at the edge of the platform
                        if (lemming.x < lemming.currentPlatform.left ||
                            lemming.x + lemming.width > lemming.currentPlatform.right) {

                            // Check if there's another platform below
                            let foundPlatform = false;

                            for (const platform of platforms) {
                                if (lemming.x >= platform.left - lemming.width &&
                                    lemming.x <= platform.right &&
                                    lemming.y > platform.top &&
                                    lemming.y - platform.top < 20) {

                                    lemming.currentPlatform = platform;
                                    lemming.y = platform.top;
                                    foundPlatform = true;
                                    break;
                                }
                            }

                            if (!foundPlatform) {
                                // Start falling
                                lemming.falling = true;
                                lemming.fallSpeed = 0;
                                lemming.element.classList.remove('walking');
                                lemming.element.classList.add('falling');
                            }
                        }

                        // Check if lemming hit a wall (edge of screen)
                        if (lemming.x < 0) {
                            lemming.x = 0;
                            lemming.direction = 1;
                            lemming.element.style.transform = 'scaleX(1)';
                        } else if (lemming.x + lemming.width > containerWidth) {
                            lemming.x = containerWidth - lemming.width;
                            lemming.direction = -1;
                            lemming.element.style.transform = 'scaleX(-1)';
                        }
                    } else {
                        // Falling
                        lemming.fallSpeed += 0.2;
                        lemming.y -= lemming.fallSpeed;

                        // Check if landed on a platform
                        for (const platform of platforms) {
                            if (lemming.x + lemming.width > platform.left &&
                                lemming.x < platform.right &&
                                lemming.y <= platform.top &&
                                lemming.y >= platform.bottom) {

                                lemming.y = platform.top;
                                lemming.falling = false;
                                lemming.currentPlatform = platform;
                                lemming.element.classList.remove('falling');
                                lemming.element.classList.add('walking');
                                break;
                            }
                        }

                        // Check if lemming fell off the screen
                        if (lemming.y < -50) {
                            // Respawn at the top
                            gameContainer.removeChild(lemming.element);
                            const index = lemmings.indexOf(lemming);
                            if (index > -1) {
                                lemmings.splice(index, 1);
                            }
                            createLemming();
                        }
                    }

                    // Update position
                    lemming.element.style.left = `${lemming.x}px`;
                    lemming.element.style.bottom = `${lemming.y}px`;
                });

                requestAnimationFrame(update);
            }

            // Start the game loop
            update();
        });
    </script>
</body>

</html>