about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@10kloc.org>2006-09-06 09:23:34 +0200
committerAnselm R. Garbe <arg@10kloc.org>2006-09-06 09:23:34 +0200
commitf6656fffb4e0c6a9a59e2669da4f7bebda19f08e (patch)
tree7e2178c82992a5a2c302c209982bca87b7a5a277
parentaaad7bfd15a023ab693bb17e2974b57cae7e7e21 (diff)
downloaddwm-f6656fffb4e0c6a9a59e2669da4f7bebda19f08e.tar.gz
made args mode symbols the default ones (the default ones look too ugly)
-rw-r--r--config.default.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/config.default.h b/config.default.h
index 395b35e..ad048ae 100644
--- a/config.default.h
+++ b/config.default.h
@@ -7,8 +7,8 @@
 const char *tags[] = { "1", "2", "3", "4", "5", NULL };
 
 #define DEFMODE			dotile /* dofloat */
-#define FLOATSYMBOL		"~"
-#define TILESYMBOL		"#"
+#define FLOATSYMBOL		"><>"
+#define TILESYMBOL		"[]="
 
 #define FONT			"fixed"
 #define SELBGCOLOR		"#666699"
te> 2024-12-13 08:14:25 -0500 *' href='/elioat/tour/commit/html/plains/game.js?id=001c721b39cebf3cccce884cb38211b8833a1c12'>001c721 ^
5ae2833 ^

001c721 ^



5ae2833 ^





001c721 ^


5ae2833 ^
001c721 ^
5ae2833 ^
001c721 ^

5ae2833 ^


001c721 ^








5ae2833 ^









001c721 ^


5ae2833 ^





001c721 ^




























5ae2833 ^


001c721 ^









5ae2833 ^

001c721 ^





5ae2833 ^

001c721 ^


5ae2833 ^
001c721 ^



5ae2833 ^
001c721 ^







































































5ae2833 ^
001c721 ^

5ae2833 ^
001c721 ^





5ae2833 ^
001c721 ^
5ae2833 ^
001c721 ^




5ae2833 ^
001c721 ^










5ae2833 ^

001c721 ^























5ae2833 ^
001c721 ^















































5ae2833 ^

001c721 ^


5ae2833 ^
001c721 ^




















5ae2833 ^


001c721 ^









5ae2833 ^



001c721 ^



5ae2833 ^

012c8f7 ^
5ae2833 ^










001c721 ^









































































5ae2833 ^

















5ae2833 ^





































































012c8f7 ^
5ae2833 ^













5ae2833 ^
































001c721 ^





















5ae2833 ^
001c721 ^
5ae2833 ^






001c721 ^
























5ae2833 ^




























001c721 ^

5ae2833 ^



001c721 ^

5ae2833 ^

























































































001c721 ^


















































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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
                




















                                             


                 
                            










                                                               



                        















                              








                                   



                       
     

  



                                             





                                     


                                                                                  
 
                                   
             

                                  


                                   








                                                               









                         


                                 





                                                     




























                                                                                                            


     









                                                        

  





                                                                           

     


                                                                                   
    



                                                                                            
    







































































                                                                                                                       
        

                                                                                                                      
        





                                          
             
          
     




                                                   
        










                                                 

         























                                                                                        
         















































                                                                                 

     


                                                                         
    




















                                  


     









                                                                                  



                                          



                                                                                                                            

   
                                               










                                                               









































































                                                                                          

















                                                                                                       





































































                                                                                                           
                          













                                                                                            
































                                                                                                                 





















                                                                                           
            
                             






                                                    
























                                                                                           




























                                                                          

                                                                                            



                                                  

                                                

























































































                                                                                       


















































                                                                                                        
const CONFIG = {
    display: {
        fps: 60,
        grid: {
            size: 100,
            color: '#ddd'
        },
        camera: {
            deadzoneMultiplierX: 0.6,
            deadzoneMultiplierY: 0.6,
            ease: 0.08
        }
    },
    effects: {
        colors: {
            primary: '#4169E1',
            secondary: '#1E90FF',
            tertiary: '#0000CD',
            glow: 'rgba(30, 144, 255, 0.25)',
            inner: '#0000CD'
        }
    },
    player: {
        size: 30,
        speed: 5,
        sprintMultiplier: 2,
        color: '#111',
        strafeKey: ' ',
        directionIndicator: {
            size: 10,
            color: 'rgba(32, 178, 170, 1)'
        },
        dash: {
            duration: 3000,    // 3 seconds of use
            cooldown: 1000,    // 1 second cooldown
            exhaustedAt: 0     // Track when dash was exhausted
        }
    },
    sword: {
        length: 60,
        swingSpeed: 0.6,
        colors: null
    },
    bubble: {
        size: 20,
        speed: 8,
        lifetime: 800,
        cooldown: 1000,
        arcWidth: Math.PI / 3,
        colors: null,
        particleEmitRate: 0.3,
        fadeExponent: 2.5
    },
    bubbleParticle: {
        lifetime: 700,
        speedMultiplier: 0.3,
        size: 3
    },
    defense: {
        numLayers: 6,
        maxRadiusMultiplier: 2,
        baseAlpha: 0.15,
        particleCount: 12,
        orbitRadiusMultiplier: 0.8,
        rotationSpeed: 1.5
    },
    footprints: {
        lifetime: 1000,
        spacing: 300,
        size: 5
    }
};

// Set references to shared colors
CONFIG.sword.colors = CONFIG.effects.colors;
CONFIG.bubble.colors = CONFIG.effects.colors;

let GAME_WIDTH = window.innerWidth;
let GAME_HEIGHT = window.innerHeight;

let lastFrameTime = 0;
let animationTime = 0;

const FRAME_TIME = 1000 / CONFIG.display.fps;
const CAMERA_DEADZONE_X = GAME_WIDTH * CONFIG.display.camera.deadzoneMultiplierX;
const CAMERA_DEADZONE_Y = GAME_HEIGHT * CONFIG.display.camera.deadzoneMultiplierY;

const createInitialState = () => ({
    player: {
        x: window.innerWidth / 2,
        y: window.innerHeight / 2,
        isDefending: false,
        direction: { x: 0, y: -1 },
        swordAngle: 0,
        isSwinging: false,
        equipment: 'sword',
        bubbles: [],
        bubbleParticles: [],
        lastBubbleTime: 0,
        dashStartTime: 0,      // When the current dash started
        isDashing: false,      // Currently dashing?
        dashExhausted: false,  // Is dash on cooldown?
        lastDashEnd: 0         // When the last dash ended
    },
    particles: [],
    footprints: [],
    lastFootprintTime: 0,
    camera: {
        x: 0,
        y: 0,
        targetX: 0,
        targetY: 0
    }
});

let state = createInitialState();

const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');

const keys = new Set();

const inputHandlers = {
    handleAttack: (state, animationTime) => {
        if (state.player.isDefending) return state;
        
        if (state.player.equipment === 'sword' && !state.player.isSwinging) {
            return {
                ...state,
                player: {
                    ...state.player,
                    isSwinging: true,
                    swordAngle: Math.atan2(state.player.direction.y, state.player.direction.x) - Math.PI / 2
                }
            };
        } else if (state.player.equipment === 'unarmed') {
            return createBubbleAttack(state, animationTime);
        }
        return state;
    },

    handleEquipmentSwitch: (state) => {
        const equipment = ['sword', 'unarmed'];
        const currentIndex = equipment.indexOf(state.player.equipment);
        return {
            ...state,
            player: {
                ...state.player,
                equipment: equipment[(currentIndex + 1) % equipment.length]
            }
        };
    }
};

const updateBubble = (bubble, animationTime) => {
    const age = animationTime - bubble.createdAt;
    const ageRatio = age / CONFIG.bubble.lifetime;
    const speedMultiplier = Math.pow(1 - ageRatio, 0.5);
    
    return {
        ...bubble,
        x: bubble.x + bubble.dx * speedMultiplier,
        y: bubble.y + bubble.dy * speedMultiplier
    };
};

const generateBubbleParticles = (bubble, animationTime) => {
    const age = animationTime - bubble.createdAt;
    const ageRatio = age / CONFIG.bubble.lifetime;
    
    if (Math.random() >= CONFIG.bubble.particleEmitRate * (1 - ageRatio)) {
        return [];
    }
    
    const trailDistance = Math.random() * 20;
    const particleX = bubble.x - bubble.dx * (trailDistance / CONFIG.bubble.speed);
    const particleY = bubble.y - bubble.dy * (trailDistance / CONFIG.bubble.speed);
    
    const particleAngle = bubble.angle + (Math.random() - 0.5) * CONFIG.bubble.arcWidth * 2;
    const spreadSpeed = CONFIG.bubble.speed * 0.2 * (1 - ageRatio);
    const spreadAngle = Math.random() * Math.PI * 2;
    const speedMultiplier = Math.pow(1 - ageRatio, 0.5);
    
    return [{
        x: particleX,
        y: particleY,
        dx: (Math.cos(particleAngle) * CONFIG.bubble.speed * CONFIG.bubbleParticle.speedMultiplier * speedMultiplier) +
            (Math.cos(spreadAngle) * spreadSpeed),
        dy: (Math.sin(particleAngle) * CONFIG.bubble.speed * CONFIG.bubbleParticle.speedMultiplier * speedMultiplier) +
            (Math.sin(spreadAngle) * spreadSpeed),
        size: CONFIG.bubbleParticle.size * (0.5 + Math.random() * 0.5),
        createdAt: animationTime
    }];
};

const updateBubbleParticles = (particles, animationTime) => {
    return particles.filter(particle => {
        const age = animationTime - particle.createdAt;
        return age < CONFIG.bubbleParticle.lifetime;
    }).map(particle => ({
        ...particle,
        x: particle.x + particle.dx,
        y: particle.y + particle.dy
    }));
};

const createBubbleAttack = (state, animationTime) => {
    const timeSinceLastBubble = animationTime - state.player.lastBubbleTime;
    if (timeSinceLastBubble < CONFIG.bubble.cooldown) return state;
    
    const angle = Math.atan2(state.player.direction.y, state.player.direction.x);
    const bubble = {
        x: state.player.x,
        y: state.player.y,
        dx: state.player.direction.x * CONFIG.bubble.speed,
        dy: state.player.direction.y * CONFIG.bubble.speed,
        angle: angle,
        createdAt: animationTime,
        size: CONFIG.bubble.size * (0.8 + Math.random() * 0.4)
    };
    
    return {
        ...state,
        player: {
            ...state.player,
            bubbles: [...state.player.bubbles, bubble],
            lastBubbleTime: animationTime
        }
    };
};

const weaponSystems = {
    updateBubbles: (state, animationTime) => {
        const updatedBubbles = state.player.bubbles
            .filter(bubble => animationTime - bubble.createdAt < CONFIG.bubble.lifetime)
            .map(bubble => updateBubble(bubble, animationTime));
            
        const newParticles = updatedBubbles
            .flatMap(bubble => generateBubbleParticles(bubble, animationTime));
            
        return {
            ...state,
            player: {
                ...state.player,
                bubbles: updatedBubbles,
                bubbleParticles: [
                    ...updateBubbleParticles(state.player.bubbleParticles, animationTime),
                    ...newParticles
                ]
            }
        };
    },

    updateSwordSwing: (state, animationTime) => {
        if (!state.player.isSwinging) return state;
        
        const newAngle = state.player.swordAngle + CONFIG.sword.swingSpeed;
        const swingComplete = newAngle > Math.atan2(state.player.direction.y, state.player.direction.x) + Math.PI / 2;
        
        return {
            ...state,
            player: {
                ...state.player,
                swordAngle: newAngle,
                isSwinging: !swingComplete
            }
        };
    }
};

const movementSystem = {
    updatePosition: (state, keys) => {
        if (state.player.isDefending) return state;
        
        const movement = calculateMovement(keys);
        if (!movement.moving) {
            // Reset dash when not moving
            return {
                ...state,
                player: {
                    ...state.player,
                    isDashing: false,
                    dashStartTime: 0
                }
            };
        }
        
        const wantsToDash = keys.has('Shift');
        const canDash = !state.player.dashExhausted && 
            (animationTime - state.player.lastDashEnd) >= CONFIG.player.dash.cooldown;
        
        let isDashing = false;
        let dashExhausted = state.player.dashExhausted;
        let dashStartTime = state.player.dashStartTime;
        let lastDashEnd = state.player.lastDashEnd;
        
        if (wantsToDash && canDash) {
            if (!state.player.isDashing) {
                dashStartTime = animationTime;
            }
            isDashing = true;
            
            // Check if dash duration exceeded
            if (animationTime - dashStartTime >= CONFIG.player.dash.duration) {
                isDashing = false;
                dashExhausted = true;
                lastDashEnd = animationTime;
            }
        } else if (state.player.dashExhausted && 
            (animationTime - state.player.lastDashEnd >= CONFIG.player.dash.cooldown)) {
            dashExhausted = false;
        }
        
        const speed = isDashing ? 
            CONFIG.player.speed * CONFIG.player.sprintMultiplier : 
            CONFIG.player.speed;
            
        // Handle footprint creation
        const timeSinceLastFootprint = animationTime - state.lastFootprintTime;
        const currentSpacing = isDashing ? 
            CONFIG.footprints.spacing * CONFIG.player.sprintMultiplier : 
            CONFIG.footprints.spacing;
            
        let newFootprints = state.footprints;
        if (timeSinceLastFootprint > currentSpacing / speed) {
            const offset = (Math.random() - 0.5) * 6;
            const perpX = -movement.direction.y * offset;
            const perpY = movement.direction.x * offset;
            
            newFootprints = [...state.footprints, createFootprint(
                state.player.x + perpX,
                state.player.y + perpY,
                Math.atan2(movement.dy, movement.dx)
            )];
        }
            
        return {
            ...state,
            player: {
                ...state.player,
                x: state.player.x + movement.dx * speed,
                y: state.player.y + movement.dy * speed,
                direction: movement.direction,
                isDashing,
                dashStartTime,
                dashExhausted,
                lastDashEnd
            },
            footprints: newFootprints,
            lastFootprintTime: timeSinceLastFootprint > currentSpacing / speed ? 
                animationTime : state.lastFootprintTime
        };
    }
};

const handleKeyDown = (e) => {
    keys.add(e.key);
    
    if (e.key === 'z' && !state.player.isDefending) {
        Object.assign(state, inputHandlers.handleAttack(state, animationTime));
    }
    
    if (e.key === 'e') {
        Object.assign(state, inputHandlers.handleEquipmentSwitch(state));
    }
    
    if (e.key === 'x') {
        Object.assign(state, {
            ...state,
            player: {
                ...state.player,
                isDefending: true
            }
        });
    }
};

const handleKeyUp = (e) => {
    keys.delete(e.key);
    if (e.key === 'x') {
        Object.assign(state, {
            ...state,
            player: {
                ...state.player,
                isDefending: false
            }
        });
    }
};

const updatePlayer = () => {
    Object.assign(state, weaponSystems.updateBubbles(state, animationTime));
    Object.assign(state, weaponSystems.updateSwordSwing(state, animationTime));
    Object.assign(state, movementSystem.updatePosition(state, keys));
    
    state.footprints = state.footprints.filter(footprint => {
        return (animationTime - footprint.createdAt) < CONFIG.footprints.lifetime;
    });
};

const createParticle = (x, y, angle) => ({
    x,
    y,
    angle,
    createdAt: animationTime,
    lifetime: CONFIG.swordParticles.lifetime,
    speed: CONFIG.swordParticles.speed * (0.5 + Math.random() * 0.5),
    size: CONFIG.swordParticles.size.min + Math.random() * (CONFIG.swordParticles.size.max - CONFIG.swordParticles.size.min)
});

const createFootprint = (x, y, direction) => ({
    x,
    y,
    direction,
    createdAt: animationTime,
    size: CONFIG.footprints.size * (0.8 + Math.random() * 0.4),
    offset: (Math.random() - 0.5) * 5
});

const renderPlayer = () => {
    ctx.save();
    
    // Render bubble particles
    state.player.bubbleParticles.forEach(particle => {
        const age = (animationTime - particle.createdAt) / CONFIG.bubbleParticle.lifetime;
        const alpha = (1 - age) * 0.8;
        
        // Draw outer glow
        ctx.fillStyle = `rgba(65, 105, 225, ${alpha * 0.3})`; // Royal Blue
        ctx.beginPath();
        ctx.arc(particle.x, particle.y, particle.size * 2.5, 0, Math.PI * 2);
        ctx.fill();
        
        // Draw core
        ctx.fillStyle = `rgba(30, 144, 255, ${alpha})`; // Dodger Blue
        ctx.beginPath();
        ctx.arc(particle.x, particle.y, particle.size * 1.5, 0, Math.PI * 2);
        ctx.fill();
    });
    
    // Render bubbles with adjusted fade
    state.player.bubbles.forEach(bubble => {
        const age = (animationTime - bubble.createdAt) / CONFIG.bubble.lifetime;
        const alpha = Math.pow(1 - age, CONFIG.bubble.fadeExponent);
        const expandedSize = bubble.size * (1 + age * 2);
        
        ctx.save();
        ctx.translate(bubble.x, bubble.y);
        ctx.rotate(bubble.angle);
        
        // Draw outer glow with adjusted fade
        ctx.beginPath();
        ctx.arc(0, 0, expandedSize * 1.5, 
            -CONFIG.bubble.arcWidth * (1 + age * 0.5),
            CONFIG.bubble.arcWidth * (1 + age * 0.5), 
            false
        );
        ctx.lineCap = 'round';
        ctx.lineWidth = expandedSize * 0.5 * (1 - age * 0.3);
        ctx.strokeStyle = CONFIG.bubble.colors.glow.replace(')', `, ${alpha * 0.5})`);
        ctx.stroke();
        
        // Draw main arc with gradient
        const gradient = ctx.createLinearGradient(
            -expandedSize, 0,
            expandedSize, 0
        );
        gradient.addColorStop(0, `rgba(65, 105, 225, ${alpha})`);
        gradient.addColorStop(0.6, `rgba(30, 144, 255, ${alpha})`);
        gradient.addColorStop(1, `rgba(0, 0, 205, ${alpha})`);
        
        ctx.beginPath();
        ctx.arc(0, 0, expandedSize, 
            -CONFIG.bubble.arcWidth * 0.8 * (1 + age * 0.5),
            CONFIG.bubble.arcWidth * 0.8 * (1 + age * 0.5),
            false
        );
        ctx.lineWidth = expandedSize * 0.3 * (1 - age * 0.3);
        ctx.strokeStyle = gradient;
        ctx.stroke();
        
        // Draw inner bright line
        ctx.beginPath();
        ctx.arc(0, 0, expandedSize * 0.9, 
            -CONFIG.bubble.arcWidth * 0.6 * (1 + age * 0.5),
            CONFIG.bubble.arcWidth * 0.6 * (1 + age * 0.5),
            false
        );
        ctx.lineWidth = expandedSize * 0.1 * (1 - age * 0.3);
        ctx.strokeStyle = `rgba(255, 255, 255, ${alpha * 0.8})`;
        ctx.stroke();
        
        ctx.restore();
    });
    
    if (state.player.isSwinging && state.player.equipment === 'sword') {
        const blurSteps = 12;
        const blurSpread = 0.2;
        
        for (let i = 0; i < blurSteps; i++) {
            const alpha = 0.35 - (i * 0.02);
            const angleOffset = -blurSpread * i;
            
            ctx.strokeStyle = `rgba(30, 144, 255, ${alpha})`;
            ctx.lineWidth = 4 + (blurSteps - i);
            ctx.beginPath();
            ctx.moveTo(state.player.x, state.player.y);
            ctx.lineTo(
                state.player.x + Math.cos(state.player.swordAngle + angleOffset) * CONFIG.sword.length,
                state.player.y + Math.sin(state.player.swordAngle + angleOffset) * CONFIG.sword.length
            );
            ctx.stroke();
        }
        
        const gradient = ctx.createLinearGradient(
            state.player.x,
            state.player.y,
            state.player.x + Math.cos(state.player.swordAngle) * CONFIG.sword.length,
            state.player.y + Math.sin(state.player.swordAngle) * CONFIG.sword.length
        );
        gradient.addColorStop(0, CONFIG.sword.colors.primary);
        gradient.addColorStop(0.6, CONFIG.sword.colors.secondary);
        gradient.addColorStop(1, CONFIG.sword.colors.tertiary);
        
        ctx.strokeStyle = CONFIG.sword.colors.glow;
        ctx.lineWidth = 10;
        ctx.beginPath();
        ctx.moveTo(state.player.x, state.player.y);
        ctx.lineTo(
            state.player.x + Math.cos(state.player.swordAngle) * CONFIG.sword.length,
            state.player.y + Math.sin(state.player.swordAngle) * CONFIG.sword.length
        );
        ctx.stroke();
        
        ctx.strokeStyle = gradient;
        ctx.lineWidth = 6;
        ctx.stroke();
    }
    
    if (state.player.isDefending) {
        const numLayers = CONFIG.defense.numLayers;
        const maxRadius = CONFIG.player.size * CONFIG.defense.maxRadiusMultiplier;
        const baseAlpha = CONFIG.defense.baseAlpha;
        
        for (let i = numLayers - 1; i >= 0; i--) {
            const radius = CONFIG.player.size / 2 + (maxRadius - CONFIG.player.size / 2) * (i / numLayers);
            const alpha = baseAlpha * (1 - i / numLayers);
            
            const pulseOffset = Math.sin(Date.now() / 500) * 3;
            
            const glowGradient = ctx.createRadialGradient(
                state.player.x, state.player.y, radius - 5,
                state.player.x, state.player.y, radius + pulseOffset
            );
            glowGradient.addColorStop(0, `rgba(30, 144, 255, ${alpha})`);
            glowGradient.addColorStop(1, 'rgba(30, 144, 255, 0)');
            
            ctx.beginPath();
            ctx.arc(state.player.x, state.player.y, radius + pulseOffset, 0, Math.PI * 2);
            ctx.fillStyle = glowGradient;
            ctx.fill();
        }
        
        const mainAuraGradient = ctx.createRadialGradient(
            state.player.x, state.player.y, CONFIG.player.size / 2 - 2,
            state.player.x, state.player.y, CONFIG.player.size / 2 + 8
        );
        mainAuraGradient.addColorStop(0, 'rgba(30, 144, 255, 0.3)');
        mainAuraGradient.addColorStop(0.5, 'rgba(30, 144, 255, 0.2)');
        mainAuraGradient.addColorStop(1, 'rgba(30, 144, 255, 0)');
        
        ctx.beginPath();
        ctx.arc(state.player.x, state.player.y, CONFIG.player.size / 2 + 8, 0, Math.PI * 2);
        ctx.fillStyle = mainAuraGradient;
        ctx.fill();
        
        ctx.beginPath();
        ctx.arc(state.player.x, state.player.y, CONFIG.player.size / 2, 0, Math.PI * 2);
        ctx.fillStyle = '#111';
        ctx.fill();
        
        ctx.beginPath();
        ctx.arc(state.player.x, state.player.y, CONFIG.player.size / 2, 0, Math.PI * 2);
        ctx.strokeStyle = CONFIG.sword.colors.secondary;
        ctx.lineWidth = 3;
        ctx.stroke();
        
        ctx.beginPath();
        ctx.arc(state.player.x, state.player.y, CONFIG.player.size / 2 - 3, 0, Math.PI * 2);
        ctx.strokeStyle = 'rgba(30, 144, 255, 0.3)';
        ctx.lineWidth = 2;
        ctx.stroke();
        
        const numParticles = CONFIG.defense.particleCount;
        const baseOrbitRadius = CONFIG.player.size * CONFIG.defense.orbitRadiusMultiplier;
        
        const rotationSpeed = CONFIG.defense.rotationSpeed;
        
        for (let i = 0; i < numParticles; i++) {
            const radialOffset = Math.sin(animationTime * 0.002 + i * 0.5) * 4;
            const orbitRadius = baseOrbitRadius + radialOffset;
            
            const angle = (i / numParticles) * Math.PI * 2 + animationTime * rotationSpeed * 0.001;
            const x = state.player.x + Math.cos(angle) * orbitRadius;
            const y = state.player.y + Math.sin(angle) * orbitRadius;
            
            const size = 2 + Math.sin(animationTime * 0.003 + i * 0.8) * 1.5;
            const baseAlpha = 0.6 + Math.sin(animationTime * 0.002 + i) * 0.2;
            
            ctx.beginPath();
            ctx.arc(x, y, size * 2, 0, Math.PI * 2);
            ctx.fillStyle = `rgba(30, 144, 255, ${baseAlpha * 0.3})`;
            ctx.fill();
            
            ctx.beginPath();
            ctx.arc(x, y, size, 0, Math.PI * 2);
            ctx.fillStyle = `rgba(135, 206, 250, ${baseAlpha})`;
            ctx.fill();
            
            if (i > 0) {
                const prevAngle = ((i - 1) / numParticles) * Math.PI * 2 + animationTime * rotationSpeed * 0.001;
                const prevX = state.player.x + Math.cos(prevAngle) * orbitRadius;
                const prevY = state.player.y + Math.sin(prevAngle) * orbitRadius;
                
                ctx.beginPath();
                ctx.moveTo(prevX, prevY);
                ctx.lineTo(x, y);
                ctx.strokeStyle = `rgba(30, 144, 255, ${baseAlpha * 0.2})`;
                ctx.lineWidth = 1;
                ctx.stroke();
            }
        }
        
        // Add direction indicator square in the center
        const dotSize = CONFIG.player.directionIndicator.size;
        
        // Calculate cooldown progress (0 to 1)
        const timeSinceLastBubble = animationTime - state.player.lastBubbleTime;
        const cooldownProgress = Math.min(timeSinceLastBubble / CONFIG.bubble.cooldown, 1);
        
        // Set opacity based on cooldown (0.1 to 1)
        const dotOpacity = getDotOpacity(state, animationTime);
        
        ctx.fillStyle = CONFIG.player.directionIndicator.color.replace(
            '1)',
            `${dotOpacity})`
        );
        
        ctx.fillRect(
            state.player.x - dotSize/2,
            state.player.y - dotSize/2,
            dotSize,
            dotSize
        );
    } else {
        // Draw player square
        ctx.fillStyle = CONFIG.player.color;
        ctx.fillRect(
            state.player.x - CONFIG.player.size / 2,
            state.player.y - CONFIG.player.size / 2,
            CONFIG.player.size,
            CONFIG.player.size
        );
        
        // Draw direction indicator square with cooldown opacity
        const dotSize = CONFIG.player.directionIndicator.size;
        const dotDistance = CONFIG.player.size / 3;
        const dotX = state.player.x + state.player.direction.x * dotDistance;
        const dotY = state.player.y + state.player.direction.y * dotDistance;
        
        // Calculate cooldown progress (0 to 1)
        const timeSinceLastBubble = animationTime - state.player.lastBubbleTime;
        const cooldownProgress = Math.min(timeSinceLastBubble / CONFIG.bubble.cooldown, 1);
        
        // Set opacity based on cooldown (0.1 to 1)
        const dotOpacity = getDotOpacity(state, animationTime);
        
        ctx.fillStyle = CONFIG.player.directionIndicator.color.replace(
            '1)',  // Replace the full opacity with our calculated opacity
            `${dotOpacity})`
        );
        
        ctx.fillRect(
            dotX - dotSize/2,
            dotY - dotSize/2,
            dotSize,
            dotSize
        );
    }
    
    ctx.restore();
};

const lerp = (start, end, t) => {
    return start * (1 - t) + end * t;
};

const render = () => {
    ctx.clearRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
    
    const screenCenterX = -state.camera.x + GAME_WIDTH / 2;
    const screenCenterY = -state.camera.y + GAME_HEIGHT / 2;
    
    const distX = state.player.x - screenCenterX;
    const distY = state.player.y - screenCenterY;
    
    if (Math.abs(distX) > CAMERA_DEADZONE_X / 2) {
        const bufferX = (GAME_WIDTH - CAMERA_DEADZONE_X) / 2;
        const targetOffsetX = distX > 0 ? GAME_WIDTH - bufferX : bufferX;
        state.camera.targetX = -(state.player.x - targetOffsetX);
    }
    if (Math.abs(distY) > CAMERA_DEADZONE_Y / 2) {
        const bufferY = (GAME_HEIGHT - CAMERA_DEADZONE_Y) / 2;
        const targetOffsetY = distY > 0 ? GAME_HEIGHT - bufferY : bufferY;
        state.camera.targetY = -(state.player.y - targetOffsetY);
    }
    
    state.camera.x = lerp(state.camera.x, state.camera.targetX, CONFIG.display.camera.ease);
    state.camera.y = lerp(state.camera.y, state.camera.targetY, CONFIG.display.camera.ease);
    
    ctx.save();
    ctx.translate(state.camera.x, state.camera.y);
    
    const gridSize = CONFIG.display.grid.size;
    ctx.strokeStyle = CONFIG.display.grid.color;
    ctx.lineWidth = 1;
    
    const startX = Math.floor((-state.camera.x) / gridSize) * gridSize;
    const startY = Math.floor((-state.camera.y) / gridSize) * gridSize;
    const endX = startX + GAME_WIDTH + gridSize;
    const endY = startY + GAME_HEIGHT + gridSize;
    
    for (let x = startX; x < endX; x += gridSize) {
        ctx.beginPath();
        ctx.moveTo(x, startY);
        ctx.lineTo(x, endY);
        ctx.stroke();
    }
    
    for (let y = startY; y < endY; y += gridSize) {
        ctx.beginPath();
        ctx.moveTo(startX, y);
        ctx.lineTo(endX, y);
        ctx.stroke();
    }
    
    state.footprints.forEach(footprint => {
        const age = (animationTime - footprint.createdAt) / CONFIG.footprints.lifetime;
        if (age >= 1) return;
        
        const alpha = Math.max(0, 1 - age * age);
        
        ctx.save();
        ctx.translate(footprint.x + footprint.offset, footprint.y + footprint.offset);
        
        const radius = Math.max(0.1, footprint.size * (1 - age * 0.5));
        
        if (radius > 0) {
            ctx.beginPath();
            ctx.arc(0, 0, radius * 2, 0, Math.PI * 2);
            ctx.fillStyle = `rgba(17, 17, 17, ${alpha * 0.1})`;
            ctx.fill();
            
            ctx.beginPath();
            ctx.arc(0, 0, radius, 0, Math.PI * 2);
            ctx.fillStyle = `rgba(17, 17, 17, ${alpha * 0.3})`;
            ctx.fill();
        }
        
        ctx.restore();
    });
    
    renderPlayer();
    
    ctx.restore();
};

const gameLoop = (currentTime) => {
    if (!lastFrameTime) {
        lastFrameTime = currentTime;
        animationTime = 0;
    }

    const deltaTime = currentTime - lastFrameTime;
    
    if (deltaTime >= FRAME_TIME) {
        animationTime += FRAME_TIME;
        
        updatePlayer();
        render();
        
        lastFrameTime = currentTime;
    }
    
    requestAnimationFrame(gameLoop);
};

window.addEventListener('keydown', handleKeyDown);
window.addEventListener('keyup', handleKeyUp);

const resizeCanvas = () => {
    GAME_WIDTH = window.innerWidth;
    GAME_HEIGHT = window.innerHeight;
    canvas.width = GAME_WIDTH;
    canvas.height = GAME_HEIGHT;
    if (!state.player.x) {
        state.player.x = GAME_WIDTH / 2;
        state.player.y = GAME_HEIGHT / 2;
    }
};

window.addEventListener('resize', resizeCanvas);

resizeCanvas();

requestAnimationFrame(gameLoop);

const calculateMovement = (keys) => {
    let dx = 0;
    let dy = 0;
    
    if (keys.has('ArrowLeft')) dx -= 1;
    if (keys.has('ArrowRight')) dx += 1;
    if (keys.has('ArrowUp')) dy -= 1;
    if (keys.has('ArrowDown')) dy += 1;
    
    if (dx === 0 && dy === 0) {
        return { moving: false };
    }
    
    const length = Math.sqrt(dx * dx + dy * dy);
    const normalizedDx = dx / length;
    const normalizedDy = dy / length;
    
    const isStrafing = keys.has(CONFIG.player.strafeKey);
    
    return {
        moving: true,
        dx: normalizedDx,
        dy: normalizedDy,
        direction: isStrafing ? 
            { ...state.player.direction } : // Keep current direction while strafing
            { x: normalizedDx, y: normalizedDy } // Update direction normally
    };
};

const getDotOpacity = (state, animationTime) => {
    // Get bubble cooldown opacity
    const timeSinceLastBubble = animationTime - state.player.lastBubbleTime;
    const bubbleCooldownProgress = Math.min(timeSinceLastBubble / CONFIG.bubble.cooldown, 1);
    const bubbleOpacity = 0.1 + (bubbleCooldownProgress * 0.9);
    
    // Get dash cooldown opacity
    let dashOpacity = 1;
    if (state.player.dashExhausted) {
        const timeSinceExhaustion = animationTime - state.player.lastDashEnd;
        const dashCooldownProgress = timeSinceExhaustion / CONFIG.player.dash.cooldown;
        dashOpacity = 0.1 + (Math.min(dashCooldownProgress, 1) * 0.9);
    } else if (state.player.isDashing) {
        const dashProgress = (animationTime - state.player.dashStartTime) / CONFIG.player.dash.duration;
        dashOpacity = 1 - (dashProgress * 0.7);  // Fade to 0.3 during dash
    }
    
    // Return the lower opacity of the two systems
    return Math.min(bubbleOpacity, dashOpacity);
};