File size: 28,459 Bytes
7503899
 
 
 
 
2d693bf
7503899
 
2d693bf
7503899
 
2d693bf
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
 
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
 
 
 
2d693bf
 
 
 
 
7503899
2d693bf
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
7503899
2d693bf
 
 
7503899
2d693bf
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
7503899
 
2d693bf
 
7503899
2d693bf
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
7503899
2d693bf
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
7503899
2d693bf
7503899
2d693bf
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
 
 
7503899
2d693bf
 
7503899
2d693bf
 
 
 
 
 
 
 
 
 
7503899
 
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Desert Warrior: Sands of Fate</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Almendra+SC&family=Cinzel+Decorative&display=swap');
        
        body {
            font-family: 'Almendra SC', serif;
            background-color: #111;
            color: #d4af37;
            overflow: hidden;
            touch-action: none;
            user-select: none;
        }
        
        #game-container {
            position: relative;
            width: 100vw;
            height: 100vh;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="%231a120b"/><path d="M0,50 Q25,40 50,50 T100,50" stroke="%233d2b1f" fill="none" stroke-width="2"/><path d="M0,70 Q25,60 50,70 T100,70" stroke="%233d2b1f" fill="none" stroke-width="2"/><path d="M0,30 Q25,20 50,30 T100,30" stroke="%233d2b1f" fill="none" stroke-width="2"/></svg>');
            background-size: cover;
            overflow: hidden;
        }
        
        #player {
            position: absolute;
            width: 64px;
            height: 64px;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect x="24" y="40" width="16" height="24" fill="%233d2b1f"/><circle cx="32" cy="24" r="12" fill="%238B4513"/><rect x="20" y="20" width="24" height="20" fill="%23d4af37" rx="2"/><path d="M16,28 L8,36 M48,28 L56,36" stroke="%233d2b1f" stroke-width="4"/><path d="M32,24 L32,16" stroke="%233d2b1f" stroke-width="2"/></svg>');
            z-index: 10;
            transition: transform 0.2s;
        }
        
        .npc {
            position: absolute;
            width: 64px;
            height: 64px;
            background-size: contain;
            z-index: 9;
        }
        
        .enemy {
            position: absolute;
            width: 64px;
            height: 64px;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect x="24" y="40" width="16" height="24" fill="%23222222"/><circle cx="32" cy="24" r="12" fill="%23333"/><rect x="20" y="20" width="24" height="20" fill="%23772222" rx="2"/><path d="M16,28 L8,36 M48,28 L56,36" stroke="%23222" stroke-width="4"/><path d="M32,24 L32,16" stroke="%23222" stroke-width="2" stroke-linecap="round"/></svg>');
            z-index: 8;
        }
        
        .building {
            position: absolute;
            background-color: #3d2b1f;
            border: 2px solid #d4af37;
            z-index: 5;
        }
        
        .market-stall {
            position: absolute;
            background-color: #5e3c23;
            border: 1px solid #d4af37;
            z-index: 6;
        }
        
        .palm-tree {
            position: absolute;
            width: 48px;
            height: 80px;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="80" viewBox="0 0 48 80"><rect x="20" y="40" width="8" height="40" fill="%235e3c23"/><path d="M24,40 Q-10,20 24,0 Q50,20 24,40" fill="%23007040"/></svg>');
            z-index: 7;
        }
        
        .dialog-box {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            width: 80%;
            max-width: 600px;
            background-color: rgba(26, 18, 11, 0.9);
            border: 2px solid #d4af37;
            padding: 15px;
            border-radius: 5px;
            z-index: 100;
            display: none;
        }
        
        .health-bar {
            position: absolute;
            top: 10px;
            left: 10px;
            width: 200px;
            height: 20px;
            background-color: #3d2b1f;
            border: 1px solid #d4af37;
            z-index: 100;
        }
        
        .health-fill {
            height: 100%;
            width: 100%;
            background-color: #a52a2a;
            transition: width 0.3s;
        }
        
        .inventory {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: rgba(26, 18, 11, 0.8);
            border: 1px solid #d4af37;
            padding: 5px;
            z-index: 100;
        }
        
        .item {
            display: inline-block;
            width: 32px;
            height: 32px;
            margin: 2px;
            background-color: #3d2b1f;
            border: 1px solid #d4af37;
            text-align: center;
            line-height: 30px;
        }
        
        .attack-animation {
            position: absolute;
            width: 40px;
            height: 40px;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"><path d="M20,0 L40,20 L20,40 L0,20 Z" fill="%23d4af37" opacity="0.7"/></svg>');
            background-size: contain;
            z-index: 11;
            animation: spin 0.5s linear;
        }
        
        @keyframes spin {
            from { transform: rotate(0deg) scale(0.5); opacity: 1; }
            to { transform: rotate(360deg) scale(1.5); opacity: 0; }
        }
        
        #controls {
            position: absolute;
            bottom: 20px;
            right: 20px;
            z-index: 100;
        }
        
        .control-btn {
            width: 50px;
            height: 50px;
            background-color: rgba(26, 18, 11, 0.7);
            border: 1px solid #d4af37;
            color: #d4af37;
            border-radius: 50%;
            margin: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            cursor: pointer;
        }
        
        #quest-log {
            position: absolute;
            top: 40px;
            left: 10px;
            background-color: rgba(26, 18, 11, 0.8);
            border: 1px solid #d4af37;
            padding: 5px;
            max-width: 200px;
            z-index: 100;
            display: none;
        }
        
        #map {
            position: absolute;
            bottom: 20px;
            left: 20px;
            width: 150px;
            height: 150px;
            background-color: rgba(26, 18, 11, 0.7);
            border: 1px solid #d4af37;
            z-index: 100;
        }
        
        #map-player {
            position: absolute;
            width: 6px;
            height: 6px;
            background-color: #d4af37;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div id="game-container">
        <div id="player"></div>
        
        <div class="health-bar">
            <div id="health-fill" class="health-fill"></div>
        </div>
        
        <div class="inventory">
            <div class="item">⚔️</div>
            <div class="item">🛡️</div>
            <div class="item">💊</div>
            <div class="item">💰</div>
        </div>
        
        <div id="quest-log">
            <h3 class="text-lg font-bold border-b border-amber-700 mb-2">Quests</h3>
            <div id="quest-1" class="text-sm mb-1">✔️ Find the missing caravan</div>
            <div id="quest-2" class="text-sm mb-1">❌ Defeat the desert raiders</div>
            <div id="quest-3" class="text-sm">❌ Recover the stolen artifact</div>
        </div>
        
        <div id="map">
            <div id="map-player"></div>
        </div>
        
        <div class="dialog-box" id="dialog-box">
            <p id="dialog-text"></p>
            <button id="dialog-next" class="mt-2 px-3 py-1 bg-amber-700 text-amber-100 rounded">Next</button>
        </div>
        
        <div id="controls" class="hidden md:flex">
            <div class="flex flex-col items-center">
                <div class="control-btn" id="up-btn"></div>
                <div class="flex">
                    <div class="control-btn" id="left-btn"></div>
                    <div class="control-btn" id="down-btn"></div>
                    <div class="control-btn" id="right-btn"></div>
                </div>
            </div>
            <div class="control-btn" id="attack-btn">⚔️</div>
            <div class="control-btn" id="menu-btn"></div>
        </div>
    </div>

    <script>
        // Game state
        const gameState = {
            player: {
                x: 400,
                y: 300,
                health: 100,
                maxHealth: 100,
                attackPower: 15,
                direction: 'down',
                moving: false,
                inventory: ['sword', 'shield', 'potion', 'gold'],
                quests: {
                    findCaravan: { completed: true },
                    defeatRaiders: { completed: false },
                    recoverArtifact: { completed: false }
                }
            },
            npcs: [],
            enemies: [],
            buildings: [],
            marketStalls: [],
            palmTrees: [],
            currentDialog: null,
            dialogIndex: 0,
            gameWidth: window.innerWidth,
            gameHeight: window.innerHeight,
            worldWidth: 2000,
            worldHeight: 2000
        };

        // DOM elements
        const playerElement = document.getElementById('player');
        const healthFill = document.getElementById('health-fill');
        const dialogBox = document.getElementById('dialog-box');
        const dialogText = document.getElementById('dialog-text');
        const dialogNext = document.getElementById('dialog-next');
        const questLog = document.getElementById('quest-log');
        const mapPlayer = document.getElementById('map-player');
        
        // Control buttons
        const upBtn = document.getElementById('up-btn');
        const downBtn = document.getElementById('down-btn');
        const leftBtn = document.getElementById('left-btn');
        const rightBtn = document.getElementById('right-btn');
        const attackBtn = document.getElementById('attack-btn');
        const menuBtn = document.getElementById('menu-btn');

        // Initialize game
        function initGame() {
            // Set player initial position
            updatePlayerPosition();
            updateHealthBar();
            
            // Generate world
            generateWorld();
            
            // Set up controls
            setupControls();
            
            // Start game loop
            requestAnimationFrame(gameLoop);
            
            // Show initial dialog
            showDialog([
                "Welcome to Desert Warrior: Sands of Fate",
                "You are Amir, a warrior from the ancient city of Al'Rashid.",
                "The city has been attacked by desert raiders who stole a sacred artifact.",
                "Your quest is to track down the raiders and recover the artifact.",
                "Use the controls to move and attack enemies.",
                "Good luck, warrior!"
            ]);
        }
        
        // Generate game world
        function generateWorld() {
            // Create buildings
            createBuilding(300, 200, 150, 200); // Mosque
            createBuilding(600, 250, 200, 150); // Palace
            createBuilding(800, 400, 120, 180); // House
            
            // Create market stalls
            createMarketStall(500, 500);
            createMarketStall(550, 500);
            createMarketStall(500, 550);
            createMarketStall(550, 550);
            
            // Create palm trees
            createPalmTree(200, 400);
            createPalmTree(250, 450);
            createPalmTree(700, 300);
            createPalmTree(900, 500);
            
            // Create NPCs
            createNPC(520, 520, "merchant", [
                "Welcome to my humble stall, warrior.",
                "I sell the finest silks and spices in all of Al'Rashid.",
                "Perhaps you'd like to browse my wares?"
            ]);
            
            createNPC(350, 250, "imam", [
                "Peace be upon you, my son.",
                "The raiders have desecrated our sacred mosque.",
                "May Allah guide you in your quest for justice."
            ]);
            
            // Create enemies
            createEnemy(700, 700);
            createEnemy(750, 650);
            createEnemy(800, 700);
        }
        
        // Create a building
        function createBuilding(x, y, width, height) {
            const building = document.createElement('div');
            building.className = 'building';
            building.style.left = `${x}px`;
            building.style.top = `${y}px`;
            building.style.width = `${width}px`;
            building.style.height = `${height}px`;
            document.getElementById('game-container').appendChild(building);
            
            gameState.buildings.push({ x, y, width, height, element: building });
        }
        
        // Create a market stall
        function createMarketStall(x, y) {
            const stall = document.createElement('div');
            stall.className = 'market-stall';
            stall.style.left = `${x}px`;
            stall.style.top = `${y}px`;
            stall.style.width = '40px';
            stall.style.height = '40px';
            document.getElementById('game-container').appendChild(stall);
            
            gameState.marketStalls.push({ x, y, element: stall });
        }
        
        // Create a palm tree
        function createPalmTree(x, y) {
            const tree = document.createElement('div');
            tree.className = 'palm-tree';
            tree.style.left = `${x}px`;
            tree.style.top = `${y}px`;
            document.getElementById('game-container').appendChild(tree);
            
            gameState.palmTrees.push({ x, y, element: tree });
        }
        
        // Create an NPC
        function createNPC(x, y, type, dialog) {
            const npc = document.createElement('div');
            npc.className = 'npc';
            
            // Different visuals for different NPC types
            if (type === 'merchant') {
                npc.style.backgroundImage = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect x="24" y="40" width="16" height="24" fill="%23404080"/><circle cx="32" cy="24" r="12" fill="%238080c0"/><rect x="20" y="20" width="24" height="20" fill="%238080c0" rx="2"/><path d="M16,28 L8,36 M48,28 L56,36" stroke="%23404080" stroke-width="4"/><path d="M32,24 L32,16" stroke="%23404080" stroke-width="2"/></svg>\')';
            } else if (type === 'imam') {
                npc.style.backgroundImage = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect x="24" y="40" width="16" height="24" fill="%23ffffff"/><circle cx="32" cy="24" r="12" fill="%23ffffff"/><rect x="20" y="20" width="24" height="20" fill="%23ffffff" rx="2"/><path d="M16,28 L8,36 M48,28 L56,36" stroke="%23ffffff" stroke-width="4"/><path d="M32,24 L32,16" stroke="%23ffffff" stroke-width="2"/></svg>\')';
            }
            
            npc.style.left = `${x}px`;
            npc.style.top = `${y}px`;
            document.getElementById('game-container').appendChild(npc);
            
            gameState.npcs.push({ 
                x, 
                y, 
                type, 
                dialog, 
                element: npc,
                interact: function() {
                    showDialog(this.dialog);
                }
            });
            
            // Make NPC clickable
            npc.addEventListener('click', function() {
                gameState.npcs.find(n => n.element === this).interact();
            });
        }
        
        // Create an enemy
        function createEnemy(x, y) {
            const enemy = document.createElement('div');
            enemy.className = 'enemy';
            enemy.style.left = `${x}px`;
            enemy.style.top = `${y}px`;
            document.getElementById('game-container').appendChild(enemy);
            
            gameState.enemies.push({ 
                x, 
                y, 
                health: 30,
                element: enemy,
                update: function() {
                    // Simple AI: move toward player if within 300px
                    const dx = gameState.player.x - this.x;
                    const dy = gameState.player.y - this.y;
                    const distance = Math.sqrt(dx * dx + dy * dy);
                    
                    if (distance < 300 && distance > 50) {
                        this.x += dx / distance * 2;
                        this.y += dy / distance * 2;
                        this.element.style.left = `${this.x}px`;
                        this.element.style.top = `${this.y}px`;
                    }
                    
                    // Check collision with player
                    if (distance < 40 && Math.random() < 0.02) {
                        gameState.player.health -= 5;
                        updateHealthBar();
                        
                        if (gameState.player.health <= 0) {
                            showDialog(["You have been defeated!", "The raiders have overpowered you.", "Press OK to restart the game."]);
                            gameState.player.health = gameState.player.maxHealth;
                            updateHealthBar();
                        }
                    }
                }
            });
        }
        
        // Update player position on screen
        function updatePlayerPosition() {
            playerElement.style.left = `${gameState.player.x}px`;
            playerElement.style.top = `${gameState.player.y}px`;
            
            // Update minimap player position
            const mapX = (gameState.player.x / gameState.worldWidth) * 150;
            const mapY = (gameState.player.y / gameState.worldHeight) * 150;
            mapPlayer.style.left = `${mapX}px`;
            mapPlayer.style.top = `${mapY}px`;
        }
        
        // Update health bar
        function updateHealthBar() {
            const healthPercent = (gameState.player.health / gameState.player.maxHealth) * 100;
            healthFill.style.width = `${healthPercent}%`;
            
            if (healthPercent < 30) {
                healthFill.style.backgroundColor = '#ff0000';
            } else if (healthPercent < 70) {
                healthFill.style.backgroundColor = '#ffa500';
            } else {
                healthFill.style.backgroundColor = '#a52a2a';
            }
        }
        
        // Show dialog
        function showDialog(messages) {
            gameState.currentDialog = messages;
            gameState.dialogIndex = 0;
            dialogText.textContent = messages[0];
            dialogBox.style.display = 'block';
        }
        
        // Next dialog
        function nextDialog() {
            gameState.dialogIndex++;
            if (gameState.dialogIndex < gameState.currentDialog.length) {
                dialogText.textContent = gameState.currentDialog[gameState.dialogIndex];
            } else {
                dialogBox.style.display = 'none';
            }
        }
        
        // Player attack
        function playerAttack() {
            // Create attack animation
            const attack = document.createElement('div');
            attack.className = 'attack-animation';
            
            // Position based on player direction
            let attackX = gameState.player.x;
            let attackY = gameState.player.y;
            
            switch (gameState.player.direction) {
                case 'up':
                    attackY -= 40;
                    break;
                case 'down':
                    attackY += 40;
                    break;
                case 'left':
                    attackX -= 40;
                    break;
                case 'right':
                    attackX += 40;
                    break;
            }
            
            attack.style.left = `${attackX}px`;
            attack.style.top = `${attackY}px`;
            document.getElementById('game-container').appendChild(attack);
            
            // Remove after animation
            setTimeout(() => {
                attack.remove();
            }, 500);
            
            // Check for enemy hits
            gameState.enemies.forEach((enemy, index) => {
                const dx = enemy.x - attackX;
                const dy = enemy.y - attackY;
                const distance = Math.sqrt(dx * dx + dy * dy);
                
                if (distance < 40) {
                    enemy.health -= gameState.player.attackPower;
                    
                    if (enemy.health <= 0) {
                        // Enemy defeated
                        enemy.element.remove();
                        gameState.enemies.splice(index, 1);
                        
                        // Check if all enemies defeated
                        if (gameState.enemies.length === 0) {
                            gameState.player.quests.defeatRaiders.completed = true;
                            document.getElementById('quest-2').textContent = '✔️ Defeat the desert raiders';
                            showDialog([
                                "You have defeated all the raiders!",
                                "Now search for the stolen artifact in their camp."
                            ]);
                        }
                    }
                }
            });
        }
        
        // Set up controls
        function setupControls() {
            // Keyboard controls
            document.addEventListener('keydown', (e) => {
                switch (e.key) {
                    case 'ArrowUp':
                    case 'w':
                        gameState.player.direction = 'up';
                        gameState.player.moving = true;
                        break;
                    case 'ArrowDown':
                    case 's':
                        gameState.player.direction = 'down';
                        gameState.player.moving = true;
                        break;
                    case 'ArrowLeft':
                    case 'a':
                        gameState.player.direction = 'left';
                        gameState.player.moving = true;
                        break;
                    case 'ArrowRight':
                    case 'd':
                        gameState.player.direction = 'right';
                        gameState.player.moving = true;
                        break;
                    case ' ':
                        playerAttack();
                        break;
                    case 'm':
                        document.getElementById('map').style.display = 
                            document.getElementById('map').style.display === 'none' ? 'block' : 'none';
                        break;
                    case 'q':
                        questLog.style.display = questLog.style.display === 'none' ? 'block' : 'none';
                        break;
                }
            });
            
            document.addEventListener('keyup', (e) => {
                switch (e.key) {
                    case 'ArrowUp':
                    case 'w':
                    case 'ArrowDown':
                    case 's':
                    case 'ArrowLeft':
                    case 'a':
                    case 'ArrowRight':
                    case 'd':
                        gameState.player.moving = false;
                        break;
                }
            });
            
            // Touch controls
            upBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                gameState.player.direction = 'up';
                gameState.player.moving = true;
            });
            
            downBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                gameState.player.direction = 'down';
                gameState.player.moving = true;
            });
            
            leftBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                gameState.player.direction = 'left';
                gameState.player.moving = true;
            });
            
            rightBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                gameState.player.direction = 'right';
                gameState.player.moving = true;
            });
            
            attackBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                playerAttack();
            });
            
            menuBtn.addEventListener('touchstart', (e) => {
                e.preventDefault();
                questLog.style.display = questLog.style.display === 'none' ? 'block' : 'none';
            });
            
            // Touch end events
            [upBtn, downBtn, leftBtn, rightBtn].forEach(btn => {
                btn.addEventListener('touchend', (e) => {
                    e.preventDefault();
                    gameState.player.moving = false;
                });
            });
            
            // Dialog next button
            dialogNext.addEventListener('click', nextDialog);
        }
        
        // Game loop
        function gameLoop() {
            // Move player if moving
            if (gameState.player.moving) {
                const speed = 3;
                
                switch (gameState.player.direction) {
                    case 'up':
                        gameState.player.y = Math.max(0, gameState.player.y - speed);
                        break;
                    case 'down':
                        gameState.player.y = Math.min(gameState.worldHeight - 64, gameState.player.y + speed);
                        break;
                    case 'left':
                        gameState.player.x = Math.max(0, gameState.player.x - speed);
                        break;
                    case 'right':
                        gameState.player.x = Math.min(gameState.worldWidth - 64, gameState.player.x + speed);
                        break;
                }
                
                updatePlayerPosition();
            }
            
            // Update enemies
            gameState.enemies.forEach(enemy => enemy.update());
            
            // Check for NPC interactions
            if (gameState.player.moving) {
                gameState.npcs.forEach(npc => {
                    const dx = npc.x - gameState.player.x;
                    const dy = npc.y - gameState.player.y;
                    const distance = Math.sqrt(dx * dx + dy * dy);
                    
                    if (distance < 60 && Math.random() < 0.01) {
                        npc.interact();
                    }
                });
            }
            
            requestAnimationFrame(gameLoop);
        }
        
        // Start the game when window loads
        window.addEventListener('load', initGame);
        
        //
<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=ido6969/top-up" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>