-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.py
More file actions
3549 lines (3281 loc) · 163 KB
/
snake.py
File metadata and controls
3549 lines (3281 loc) · 163 KB
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
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pygame
import random
import sys
import math
import json
import os
import struct
import asyncio
# --- Konstanter ---
CELL_SIZE = 20
GRID_W = 50
GRID_H = 30
SCOREBOARD_H = 50
WINDOW_W = GRID_W * CELL_SIZE
WINDOW_H = GRID_H * CELL_SIZE + SCOREBOARD_H
HIGHSCORE_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "highscores.json")
MAX_HIGHSCORES = 5
MAX_NAME_LEN = 12
# Sværhedsgrader: (label, start_fps, max_fps, fps_increase_every)
DIFFICULTIES = [
("Let", 5, 20, 8),
("Normal", 8, 26, 5),
("Svær", 12, 32, 3),
("Vanvid", 16, 48, 2),
]
# Farver
BLACK = (0, 0, 0)
DARK_GRAY = (25, 25, 25)
GRAY = (40, 40, 40)
LIGHT_GRAY = (120, 120, 120)
WHITE = (255, 255, 255)
RED = (220, 50, 50)
GREEN = (80, 200, 80)
GREEN_DARK = (50, 150, 50)
GREEN_BELLY = (100, 220, 100)
BLUE = (80, 130, 220)
BLUE_DARK = (50, 90, 170)
BLUE_BELLY = (110, 160, 240)
YELLOW = (240, 220, 60)
GOLD = (255, 200, 0)
PURPLE = (180, 60, 220)
CYAN = (60, 220, 220)
# Ruin-farver
# === MAP TEMAER pr. sværhedsgrad ===
# 0=Let(skov), 1=Normal(vildmark), 2=Svær(vulkan), 3=Vanvid(militærbase)
MAP_THEMES = {
0: { # SKOV (Let)
"floor1": (28, 45, 22), "floor2": (34, 52, 26), "floor3": (24, 38, 18),
"dirt1": (50, 38, 24), "dirt2": (42, 32, 20),
"detail_col": [(70, 50, 20), (80, 60, 15), (55, 75, 25), (90, 70, 30)],
"detail_chance": 0.08, "moss_chance": 0.15,
"moss_r": (40, 25), "moss_g": (70, 30), "moss_b": (30, 15),
"trunk": (90, 60, 35), "trunk_dark": (65, 42, 22), "trunk_light": (115, 80, 50),
"canopy": (35, 90, 30), "canopy_light": (55, 120, 45),
"canopy_dark": (22, 60, 18), "canopy_shadow": (15, 35, 12),
"ruin_dark": (75, 60, 45), "ruin_med": (95, 78, 58),
"ruin_light": (115, 95, 72), "ruin_moss": (60, 90, 45),
"scoreboard": (30, 45, 28),
},
1: { # VILDMARK (Normal)
"floor1": (55, 48, 30), "floor2": (62, 55, 35), "floor3": (48, 40, 25),
"dirt1": (70, 55, 32), "dirt2": (58, 45, 28),
"detail_col": [(80, 70, 40), (65, 55, 30), (90, 80, 50), (50, 60, 30)],
"detail_chance": 0.10, "moss_chance": 0.10,
"moss_r": (55, 20), "moss_g": (60, 25), "moss_b": (25, 15),
"trunk": (70, 50, 30), "trunk_dark": (50, 35, 18), "trunk_light": (95, 70, 45),
"canopy": (60, 75, 25), "canopy_light": (80, 100, 40),
"canopy_dark": (40, 50, 15), "canopy_shadow": (25, 35, 10),
"ruin_dark": (65, 55, 38), "ruin_med": (85, 72, 50),
"ruin_light": (105, 90, 65), "ruin_moss": (50, 70, 35),
"scoreboard": (40, 35, 22),
},
2: { # VULKAN (Svær)
"floor1": (40, 22, 18), "floor2": (50, 28, 20), "floor3": (32, 18, 14),
"dirt1": (60, 30, 15), "dirt2": (45, 20, 10),
"detail_col": [(180, 60, 20), (200, 80, 10), (150, 40, 15), (220, 100, 30)],
"detail_chance": 0.12, "moss_chance": 0.08,
"moss_r": (80, 40), "moss_g": (25, 15), "moss_b": (10, 10),
"trunk": (55, 35, 30), "trunk_dark": (35, 20, 18), "trunk_light": (75, 50, 40),
"canopy": (160, 50, 20), "canopy_light": (220, 100, 30),
"canopy_dark": (100, 30, 10), "canopy_shadow": (60, 15, 5),
"ruin_dark": (45, 25, 20), "ruin_med": (65, 35, 25),
"ruin_light": (85, 50, 35), "ruin_moss": (120, 50, 15),
"scoreboard": (50, 20, 15),
},
3: { # MILITÆRBASE (Vanvid)
"floor1": (48, 50, 48), "floor2": (55, 58, 55), "floor3": (40, 42, 40),
"dirt1": (60, 62, 58), "dirt2": (50, 52, 48),
"detail_col": [(70, 72, 68), (55, 58, 52), (80, 82, 78), (45, 48, 42)],
"detail_chance": 0.06, "moss_chance": 0.05,
"moss_r": (50, 15), "moss_g": (52, 15), "moss_b": (48, 15),
"trunk": (80, 82, 78), "trunk_dark": (55, 58, 52), "trunk_light": (110, 112, 108),
"canopy": (60, 75, 55), "canopy_light": (80, 95, 70),
"canopy_dark": (40, 52, 35), "canopy_shadow": (30, 40, 25),
"ruin_dark": (55, 58, 52), "ruin_med": (75, 78, 72),
"ruin_light": (95, 98, 92), "ruin_moss": (50, 65, 45),
"scoreboard": (35, 40, 35),
},
}
# Standardfarver (bruges som fallback)
RUIN_DARK = (75, 60, 45)
RUIN_MED = (95, 78, 58)
RUIN_LIGHT = (115, 95, 72)
RUIN_MOSS = (60, 90, 45)
# Skov-farver (fallback)
FOREST_FLOOR_1 = (28, 45, 22)
FOREST_FLOOR_2 = (34, 52, 26)
FOREST_FLOOR_3 = (24, 38, 18)
FOREST_DIRT_1 = (50, 38, 24)
FOREST_DIRT_2 = (42, 32, 20)
TREE_TRUNK = (90, 60, 35)
TREE_TRUNK_DARK = (65, 42, 22)
TREE_TRUNK_LIGHT = (115, 80, 50)
TREE_CANOPY = (35, 90, 30)
TREE_CANOPY_LIGHT = (55, 120, 45)
TREE_CANOPY_DARK = (22, 60, 18)
TREE_CANOPY_SHADOW = (15, 35, 12)
# Retninger
UP = (0, -1)
DOWN = (0, 1)
LEFT = (-1, 0)
RIGHT = (1, 0)
OPPOSITES = {UP: DOWN, DOWN: UP, LEFT: RIGHT, RIGHT: LEFT}
FOOD_NORMAL = "normal"
FOOD_BONUS = "bonus"
FOOD_INVINCIBLE = "invincible"
FOOD_MEGA = "mega" # 100 point - spawner 20 per 10 min
MEGA_FOOD_INTERVAL = 30 # sekunder mellem mega-food spawns (10 min / 20 = 30s)
# Coin / Bullet / Gun
COIN_COLOR = (255, 215, 0)
COIN_COLOR_DARK = (200, 160, 0)
MONEY_BILL_COLOR = (85, 200, 85) # Grøn pengeseddel
MONEY_BILL_DARK = (60, 140, 60)
MONEY_BILL_VALUE = 10 # Pengesedler giver 10 coins
BULLET_COLOR = (255, 100, 50)
BULLET_SPEED = 2 # celler per game-tick
AMMO_PRICE = 1 # 1 coin = 5 skud
AMMO_AMOUNT = 5 # skud per køb
GUN_BARREL_COLOR = (100, 100, 110)
GUN_BODY_COLOR = (70, 70, 80)
SAVE_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "savedata.json")
# Kanon-typer: (id, navn, pris, farve)
GUN_NONE = None
GUN_BASIC = "basic" # Manuel skydning, 1 skud
GUN_AUTO = "auto" # Automatisk skydning
GUN_QUAD = "quad" # 4 skud ad gangen
GUN_VACUUM = "vacuum" # Støvsuger - suger mad til sig
GUN_TYPES = [
(GUN_BASIC, "Kanon", 10, GUN_BARREL_COLOR),
(GUN_AUTO, "Auto-Kanon", 15, (120, 180, 120)),
(GUN_QUAD, "Quad-Kanon", 25, (180, 100, 100)),
(GUN_VACUUM, "Støvsuger", 50, (100, 60, 180)),
]
GUN_INFO = {g[0]: g for g in GUN_TYPES}
AUTO_SHOOT_INTERVAL = 4 # auto-kanon skyder hvert N. tick
VACUUM_INTERVAL = 12 # støvsuger suger hvert N. tick (langsom forbrug)
VACUUM_RANGE = 10 # rækkevidde i celler
POWER_PRICE = 5 # 5 coins for 7 strøm
POWER_AMOUNT = 7
# Slange-typer (20 stk)
SNAKE_NORMAL = "normal"
SNAKE_DOG = "dog"
SNAKE_TANK = "tank"
SNAKE_CAT = "cat"
SNAKE_DRAGON = "dragon"
SNAKE_ROBOT = "robot"
SNAKE_SHARK = "shark"
SNAKE_FIRE = "fire"
SNAKE_ICE = "ice"
SNAKE_RAINBOW = "rainbow"
SNAKE_ZOMBIE = "zombie"
SNAKE_NINJA = "ninja"
SNAKE_PIRATE = "pirate"
SNAKE_ALIEN = "alien"
SNAKE_CANDY = "candy"
SNAKE_GOLD = "gold"
SNAKE_SKELETON = "skeleton"
SNAKE_LAVA = "lava"
SNAKE_ELECTRIC = "electric"
SNAKE_DIAMOND = "diamond"
SNAKE_TYPES_LIST = [
SNAKE_NORMAL, SNAKE_DOG, SNAKE_TANK, SNAKE_CAT, SNAKE_DRAGON,
SNAKE_ROBOT, SNAKE_SHARK, SNAKE_FIRE, SNAKE_ICE, SNAKE_RAINBOW,
SNAKE_ZOMBIE, SNAKE_NINJA, SNAKE_PIRATE, SNAKE_ALIEN, SNAKE_CANDY,
SNAKE_GOLD, SNAKE_SKELETON, SNAKE_LAVA, SNAKE_ELECTRIC, SNAKE_DIAMOND,
]
SNAKE_TYPE_NAMES = {
SNAKE_NORMAL: "Normal", SNAKE_DOG: "Hund", SNAKE_TANK: "Tank",
SNAKE_CAT: "Kat", SNAKE_DRAGON: "Drage", SNAKE_ROBOT: "Robot",
SNAKE_SHARK: "Hai", SNAKE_FIRE: "Ild", SNAKE_ICE: "Is",
SNAKE_RAINBOW: "Regnbue", SNAKE_ZOMBIE: "Zombie", SNAKE_NINJA: "Ninja",
SNAKE_PIRATE: "Pirat", SNAKE_ALIEN: "Alien", SNAKE_CANDY: "Slik",
SNAKE_GOLD: "Guld", SNAKE_SKELETON: "Skelet", SNAKE_LAVA: "Lava",
SNAKE_ELECTRIC: "Elektrisk", SNAKE_DIAMOND: "Diamant",
}
# Square-head types
SQUARE_HEAD_TYPES = (SNAKE_TANK, SNAKE_ROBOT)
# Farver per (slange-type, spiller-idx): (main, dark, belly)
SNAKE_TYPE_COLORS = {
SNAKE_NORMAL: {
0: ((80, 200, 80), (50, 150, 50), (100, 220, 100)),
1: ((80, 130, 220), (50, 90, 170), (110, 160, 240)),
},
SNAKE_DOG: {
0: ((180, 130, 70), (140, 95, 45), (210, 170, 100)),
1: ((200, 150, 90), (160, 110, 55), (230, 180, 120)),
},
SNAKE_TANK: {
0: ((100, 120, 80), (70, 85, 55), (130, 150, 110)),
1: ((90, 100, 120), (65, 75, 95), (120, 130, 150)),
},
SNAKE_CAT: {
0: ((180, 140, 180), (140, 100, 140), (210, 175, 210)),
1: ((200, 170, 130), (160, 130, 90), (230, 200, 165)),
},
SNAKE_DRAGON: {
0: ((180, 50, 50), (130, 30, 30), (210, 80, 60)),
1: ((50, 100, 180), (30, 70, 130), (80, 130, 210)),
},
SNAKE_ROBOT: {
0: ((160, 165, 175), (110, 115, 125), (190, 195, 205)),
1: ((175, 160, 140), (125, 110, 95), (205, 190, 175)),
},
SNAKE_SHARK: {
0: ((100, 115, 135), (70, 80, 100), (145, 160, 180)),
1: ((120, 105, 135), (85, 70, 100), (155, 140, 175)),
},
SNAKE_FIRE: {
0: ((230, 120, 30), (180, 80, 15), (255, 170, 60)),
1: ((230, 50, 30), (180, 30, 15), (255, 90, 60)),
},
SNAKE_ICE: {
0: ((140, 195, 235), (95, 155, 205), (185, 220, 250)),
1: ((175, 215, 235), (135, 180, 205), (210, 238, 250)),
},
SNAKE_RAINBOW: {
0: ((255, 100, 100), (200, 60, 60), (255, 150, 150)),
1: ((100, 100, 255), (60, 60, 200), (150, 150, 255)),
},
SNAKE_ZOMBIE: {
0: ((115, 140, 85), (78, 100, 55), (148, 170, 112)),
1: ((130, 115, 140), (90, 78, 100), (162, 148, 170)),
},
SNAKE_NINJA: {
0: ((50, 40, 65), (30, 22, 42), (78, 65, 90)),
1: ((40, 50, 65), (22, 30, 42), (65, 78, 90)),
},
SNAKE_PIRATE: {
0: ((140, 80, 48), (100, 52, 28), (178, 112, 75)),
1: ((150, 58, 48), (108, 35, 28), (188, 88, 75)),
},
SNAKE_ALIEN: {
0: ((70, 220, 95), (42, 170, 62), (110, 248, 135)),
1: ((95, 175, 220), (62, 135, 170), (135, 208, 248)),
},
SNAKE_CANDY: {
0: ((238, 135, 178), (198, 98, 138), (255, 178, 208)),
1: ((135, 198, 238), (98, 158, 198), (178, 228, 255)),
},
SNAKE_GOLD: {
0: ((218, 178, 48), (178, 138, 28), (248, 208, 78)),
1: ((198, 198, 208), (158, 158, 168), (228, 228, 238)),
},
SNAKE_SKELETON: {
0: ((218, 212, 198), (168, 162, 148), (238, 232, 222)),
1: ((198, 208, 218), (148, 158, 168), (222, 232, 238)),
},
SNAKE_LAVA: {
0: ((78, 38, 28), (48, 22, 14), (118, 58, 38)),
1: ((58, 38, 48), (34, 22, 28), (88, 58, 68)),
},
SNAKE_ELECTRIC: {
0: ((238, 218, 58), (198, 178, 38), (255, 238, 98)),
1: ((58, 178, 238), (38, 138, 198), (98, 208, 255)),
},
SNAKE_DIAMOND: {
0: ((158, 218, 238), (118, 178, 208), (198, 238, 252)),
1: ((218, 158, 218), (178, 118, 178), (238, 198, 238)),
},
}
# --- Ruin-layouts (relative positioner fra anker) ---
RUIN_TEMPLATES = [
# L-form
[(0, 0), (1, 0), (2, 0), (0, 1), (0, 2)],
# Omvendt L
[(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)],
# Lille kvadrat
[(0, 0), (1, 0), (0, 1), (1, 1)],
# Vandret mur
[(0, 0), (1, 0), (2, 0), (3, 0)],
# Lodret mur
[(0, 0), (0, 1), (0, 2), (0, 3)],
# T-form
[(0, 0), (1, 0), (2, 0), (1, 1), (1, 2)],
# Kryds
[(1, 0), (0, 1), (1, 1), (2, 1), (1, 2)],
# S-form
[(1, 0), (2, 0), (0, 1), (1, 1), (0, 2)],
# Lille prik-klump
[(0, 0), (2, 0), (1, 1), (0, 2), (2, 2)],
]
# Antal ruiner per sværhedsgrad (mere skov = flere ruiner)
RUIN_COUNTS = [4, 6, 9, 13]
# Antal dekorative træer per sværhedsgrad
TREE_COUNTS = [8, 12, 16, 20]
def load_highscores():
if os.path.exists(HIGHSCORE_FILE):
try:
with open(HIGHSCORE_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except (json.JSONDecodeError, OSError):
pass
return {}
def save_highscores(data):
with open(HIGHSCORE_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
def get_highscore_list(data, difficulty_idx, num_players):
key = f"{num_players}p_{difficulty_idx}"
return data.get(key, [])
def add_highscore(data, difficulty_idx, num_players, name, score):
key = f"{num_players}p_{difficulty_idx}"
entries = data.get(key, [])
entries.append({"name": name, "score": score})
entries.sort(key=lambda e: e["score"], reverse=True)
entries = entries[:MAX_HIGHSCORES]
data[key] = entries
save_highscores(data)
for i, e in enumerate(entries):
if e["name"] == name and e["score"] == score:
return i
return None
def is_highscore(data, difficulty_idx, num_players, score):
if score <= 0:
return False
entries = get_highscore_list(data, difficulty_idx, num_players)
if len(entries) < MAX_HIGHSCORES:
return True
return score > entries[-1]["score"]
def load_savedata():
if os.path.exists(SAVE_FILE):
try:
with open(SAVE_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except (json.JSONDecodeError, OSError):
pass
return {}
def save_savedata(data):
with open(SAVE_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
def generate_ruins(count, safe_zones):
"""Generer tilfældige ruiner på banen. safe_zones er et set af positioner der skal holdes fri."""
ruin_cells = set()
attempts = 0
placed = 0
while placed < count and attempts < count * 20:
attempts += 1
template = random.choice(RUIN_TEMPLATES)
# Tilfældig rotation (0, 90, 180, 270)
rot = random.randint(0, 3)
rotated = template
for _ in range(rot):
rotated = [(-y, x) for x, y in rotated]
# Tilfældig offset
min_x = min(x for x, y in rotated)
min_y = min(y for x, y in rotated)
max_x = max(x for x, y in rotated)
max_y = max(y for x, y in rotated)
ox = random.randint(2 - min_x, GRID_W - 3 - max_x)
oy = random.randint(2 - min_y, GRID_H - 3 - max_y)
cells = [(x + ox, y + oy) for x, y in rotated]
# Tjek at alle celler er ledige
valid = True
for cx, cy in cells:
if cx < 1 or cx >= GRID_W - 1 or cy < 1 or cy >= GRID_H - 1:
valid = False
break
if (cx, cy) in ruin_cells or (cx, cy) in safe_zones:
valid = False
break
# Hold afstand til andre ruiner
for dx in range(-1, 2):
for dy in range(-1, 2):
if (cx + dx, cy + dy) in ruin_cells:
valid = False
break
if not valid:
break
if valid:
for c in cells:
ruin_cells.add(c)
placed += 1
return ruin_cells
def generate_trees(count, occupied):
"""Generer tilfældige dekorative træ-positioner (grid-celler). Undgår occuperede celler."""
trees = []
attempts = 0
while len(trees) < count and attempts < count * 30:
attempts += 1
tx = random.randint(1, GRID_W - 2)
ty = random.randint(1, GRID_H - 2)
if (tx, ty) in occupied:
continue
# Hold afstand til andre træer (min 2 celler)
too_close = False
for ex, ey in trees:
if abs(tx - ex) <= 2 and abs(ty - ey) <= 2:
too_close = True
break
if not too_close:
trees.append((tx, ty))
occupied.add((tx, ty))
return trees
def draw_map_floor(surface, difficulty=0):
"""Tegn gulv baseret på map-tema (skov/vildmark/vulkan/militærbase)."""
theme = MAP_THEMES.get(difficulty, MAP_THEMES[0])
rng = random.Random(123)
f1, f2, f3 = theme["floor1"], theme["floor2"], theme["floor3"]
d1, d2 = theme["dirt1"], theme["dirt2"]
for gx in range(GRID_W):
for gy in range(GRID_H):
px = gx * CELL_SIZE
py = gy * CELL_SIZE + SCOREBOARD_H
roll = rng.random()
if roll < 0.55:
base = f1
elif roll < 0.85:
base = f2
else:
base = f3
draw_3d_tile(surface, px, py, CELL_SIZE, base)
# Jord/detalje-pletter
if rng.random() < 0.12:
dx = rng.randint(2, CELL_SIZE - 6)
dy = rng.randint(2, CELL_SIZE - 6)
dr = rng.randint(2, 4)
dirt = d1 if rng.random() > 0.5 else d2
pygame.draw.circle(surface, dirt, (px + dx, py + dy), dr)
# Mos/tekstur-klumper
if rng.random() < theme["moss_chance"]:
mx = rng.randint(1, CELL_SIZE - 3)
my = rng.randint(1, CELL_SIZE - 3)
mr, mg, mb = theme["moss_r"], theme["moss_g"], theme["moss_b"]
moss_col = (mr[0] + rng.randint(0, mr[1]), mg[0] + rng.randint(0, mg[1]), mb[0] + rng.randint(0, mb[1]))
pygame.draw.circle(surface, moss_col, (px + mx, py + my), rng.randint(1, 3))
# Detaljer (blade/sten/aske/skruer)
if rng.random() < theme["detail_chance"]:
lx = px + rng.randint(3, CELL_SIZE - 5)
ly = py + rng.randint(3, CELL_SIZE - 5)
leaf_col = rng.choice(theme["detail_col"])
pygame.draw.ellipse(surface, leaf_col, (lx, ly, rng.randint(3, 6), rng.randint(2, 4)))
# Vulkan: lava-revner
if difficulty == 2 and rng.random() < 0.04:
cx = px + rng.randint(2, CELL_SIZE - 2)
cy = py + rng.randint(2, CELL_SIZE - 2)
ex = cx + rng.randint(-8, 8)
ey = cy + rng.randint(-8, 8)
pygame.draw.line(surface, (200, 60, 10), (cx, cy), (ex, ey), 1)
pygame.draw.line(surface, (255, 120, 20), (cx, cy), ((cx + ex) // 2, (cy + ey) // 2), 1)
# Militærbase: gulv-markeringer
if difficulty == 3 and rng.random() < 0.03:
mx = px + rng.randint(0, CELL_SIZE - 1)
my = py + rng.randint(0, CELL_SIZE - 1)
pygame.draw.line(surface, (80, 85, 60), (mx, my), (mx + rng.randint(4, 10), my), 1)
def draw_decorations(surface, trees, difficulty=0):
"""Tegn dekorationer baseret på tema: træer/buske/vulkan-klipper/militær-strukturer."""
theme = MAP_THEMES.get(difficulty, MAP_THEMES[0])
rng = random.Random(77)
cs = CELL_SIZE
trunk_col = theme["trunk"]
trunk_dk = theme["trunk_dark"]
trunk_lt = theme["trunk_light"]
canopy_col = theme["canopy"]
canopy_lt = theme["canopy_light"]
canopy_dk = theme["canopy_dark"]
for (tx, ty) in trees:
px = tx * cs
py = ty * cs + SCOREBOARD_H
cx = px + cs // 2
cy = py + cs // 2
if difficulty == 2:
# --- VULKAN: lava-klipper og ryggende sten ---
rock_h = rng.randint(10, 16)
# Skygge
shadow_surf = pygame.Surface((rock_h * 2, rock_h), pygame.SRCALPHA)
pygame.draw.ellipse(shadow_surf, (0, 0, 0, 50), (0, 0, rock_h * 2, rock_h))
surface.blit(shadow_surf, (cx - rock_h, cy + 2))
# Klippeform (uregelmæssig polygon)
pts = []
for a in range(6):
ang = a * math.pi / 3 - math.pi / 2
r = rock_h + rng.randint(-4, 4)
pts.append((int(cx + r * math.cos(ang)), int(cy - r * 0.6 * math.sin(ang))))
pygame.draw.polygon(surface, (50, 30, 25), [(p[0] + 2, p[1] + 2) for p in pts])
pygame.draw.polygon(surface, trunk_col, pts)
pygame.draw.polygon(surface, trunk_lt, pts, 1)
# Glødende revner
for _ in range(rng.randint(1, 3)):
rx = cx + rng.randint(-rock_h // 2, rock_h // 2)
ry = cy + rng.randint(-rock_h // 3, rock_h // 3)
pygame.draw.line(surface, (220, 80, 10), (rx, ry), (rx + rng.randint(-5, 5), ry + rng.randint(-5, 5)), 1)
# Røg/damp
for _ in range(rng.randint(1, 2)):
sx = cx + rng.randint(-3, 3)
sy = cy - rock_h // 2 - rng.randint(2, 8)
smoke_r = rng.randint(2, 5)
smoke_surf = pygame.Surface((smoke_r * 2, smoke_r * 2), pygame.SRCALPHA)
pygame.draw.circle(smoke_surf, (120, 110, 100, 60), (smoke_r, smoke_r), smoke_r)
surface.blit(smoke_surf, (sx - smoke_r, sy - smoke_r))
elif difficulty == 3:
# --- MILITÆRBASE: sandsække, barrikader, tårne ---
struct_type = rng.randint(0, 2)
if struct_type == 0:
# Sandsæk-bunke
for row in range(3):
for col in range(2 - row):
bx = cx - 8 + col * 10 + row * 5
by = cy + 4 - row * 6
draw_3d_rect(surface, (90, 85, 60), (bx, by, 10, 6), depth=2)
pygame.draw.rect(surface, (75, 70, 48), (bx + 1, by + 1, 8, 4), 1)
elif struct_type == 1:
# Vagttårn
base_w, base_h = 14, 8
draw_3d_rect(surface, (70, 72, 65), (cx - base_w // 2, cy, base_w, base_h), depth=3)
# Stolpe
pygame.draw.line(surface, (80, 82, 75), (cx, cy), (cx, cy - 18), 3)
pygame.draw.line(surface, (100, 102, 95), (cx - 1, cy), (cx - 1, cy - 18), 1)
# Platform
draw_3d_rect(surface, (75, 78, 70), (cx - 8, cy - 22, 16, 6), depth=2)
# Gelænder
pygame.draw.rect(surface, (90, 92, 85), (cx - 7, cy - 26, 14, 4), 1)
else:
# Pigtrådshegn
y1 = cy - 6
y2 = cy + 6
pygame.draw.line(surface, (90, 88, 80), (cx - 10, cy), (cx + 10, cy), 2)
pygame.draw.line(surface, (70, 68, 60), (cx - 10, y1), (cx - 10, y2), 2)
pygame.draw.line(surface, (70, 68, 60), (cx + 10, y1), (cx + 10, y2), 2)
# Pigtråd
for wx in range(cx - 9, cx + 9, 3):
pygame.draw.line(surface, (110, 108, 100), (wx, cy - 1), (wx + 2, cy + 1), 1)
pygame.draw.line(surface, (110, 108, 100), (wx + 2, cy + 1), (wx + 1, cy - 1), 1)
elif difficulty == 1:
# --- VILDMARK: buske og klipper ---
is_bush = rng.random() < 0.6
if is_bush:
bush_r = rng.randint(8, 14)
shadow_surf = pygame.Surface((bush_r * 2, bush_r), pygame.SRCALPHA)
pygame.draw.ellipse(shadow_surf, (0, 0, 0, 45), (0, 0, bush_r * 2, bush_r))
surface.blit(shadow_surf, (cx - bush_r, cy + 2))
# Busk-klumper
for _ in range(rng.randint(3, 5)):
bx = cx + rng.randint(-bush_r // 2, bush_r // 2)
by = cy + rng.randint(-bush_r // 2, bush_r // 3)
br = rng.randint(bush_r // 3, bush_r // 2 + 2)
pygame.draw.circle(surface, canopy_dk, (bx + 1, by + 1), br)
pygame.draw.circle(surface, canopy_col, (bx, by), br)
# Highlight
for _ in range(rng.randint(1, 3)):
hx = cx + rng.randint(-bush_r // 3, bush_r // 3)
hy = cy + rng.randint(-bush_r // 2, -bush_r // 4)
pygame.draw.circle(surface, canopy_lt, (hx, hy), rng.randint(2, 4))
else:
# Klippe
rock_r = rng.randint(6, 10)
pygame.draw.circle(surface, (40, 38, 32), (cx + 1, cy + 1), rock_r)
pygame.draw.circle(surface, (75, 70, 58), (cx, cy), rock_r)
pygame.draw.circle(surface, (95, 90, 75), (cx - 2, cy - 2), rock_r // 2)
pygame.draw.circle(surface, canopy_dk, (cx, cy), rock_r, 1)
else:
# --- SKOV: standard træer ---
tree_h = rng.randint(14, 22)
trunk_w = rng.randint(3, 5)
shadow_r = tree_h + 2
shadow_surf = pygame.Surface((shadow_r * 2, shadow_r), pygame.SRCALPHA)
pygame.draw.ellipse(shadow_surf, (0, 0, 0, 50), (0, 0, shadow_r * 2, shadow_r))
surface.blit(shadow_surf, (cx - shadow_r, cy + 2))
trunk_top = cy - tree_h // 2
trunk_bot = cy + 4
pygame.draw.line(surface, trunk_dk, (cx + 2, trunk_top + 2), (cx + 2, trunk_bot + 2), trunk_w + 2)
pygame.draw.line(surface, trunk_col, (cx, trunk_top), (cx, trunk_bot), trunk_w)
pygame.draw.line(surface, trunk_lt, (cx - trunk_w // 2 + 1, trunk_top), (cx - trunk_w // 2 + 1, trunk_bot), 1)
for bark_y in range(trunk_top + 3, trunk_bot, 4):
pygame.draw.line(surface, trunk_dk, (cx - trunk_w // 2, bark_y), (cx + trunk_w // 2, bark_y), 1)
crown_cx = cx + rng.randint(-2, 2)
crown_cy = trunk_top - tree_h // 3
draw_3d_circle(surface, canopy_dk, (crown_cx + 3, crown_cy + 3), tree_h, depth=0)
pygame.draw.circle(surface, canopy_col, (crown_cx, crown_cy), tree_h)
for _ in range(rng.randint(3, 5)):
bx = crown_cx + rng.randint(-tree_h // 2, tree_h // 2)
by = crown_cy + rng.randint(-tree_h // 2, tree_h // 2)
br = rng.randint(tree_h // 3, tree_h // 2)
pygame.draw.circle(surface, canopy_col, (bx, by), br)
for _ in range(rng.randint(2, 4)):
hx = crown_cx + rng.randint(-tree_h // 3, tree_h // 3)
hy = crown_cy + rng.randint(-tree_h // 2, -tree_h // 4)
hr = rng.randint(tree_h // 4, tree_h // 3)
pygame.draw.circle(surface, canopy_lt, (hx, hy), hr)
for _ in range(rng.randint(2, 3)):
sx = crown_cx + rng.randint(-tree_h // 3, tree_h // 3)
sy = crown_cy + rng.randint(0, tree_h // 3)
sr = rng.randint(tree_h // 4, tree_h // 3)
pygame.draw.circle(surface, canopy_dk, (sx, sy), sr)
spec_x = crown_cx - tree_h // 4
spec_y = crown_cy - tree_h // 3
pygame.draw.circle(surface, _lighten(canopy_lt, 30), (spec_x, spec_y), tree_h // 5)
pygame.draw.circle(surface, canopy_dk, (crown_cx, crown_cy), tree_h, 1)
def _seg_direction(prev, curr):
"""Retning fra prev til curr."""
return (curr[0] - prev[0], curr[1] - prev[1])
# --- 3D tegne-hjælpere ---
def _clamp(v, lo=0, hi=255):
return max(lo, min(hi, int(v)))
def _lighten(color, amount=40):
return tuple(_clamp(c + amount) for c in color)
def _hsv_to_rgb(h, s, v):
"""HSV -> RGB. h,s,v in [0,1]. Returns (r,g,b) in [0,255]."""
if s == 0:
val = int(v * 255)
return (val, val, val)
h6 = h * 6.0
i = int(h6) % 6
f = h6 - int(h6)
p, q, t = v * (1 - s), v * (1 - s * f), v * (1 - s * (1 - f))
if i == 0: r, g, b = v, t, p
elif i == 1: r, g, b = q, v, p
elif i == 2: r, g, b = p, v, t
elif i == 3: r, g, b = p, q, v
elif i == 4: r, g, b = t, p, v
else: r, g, b = v, p, q
return (int(r * 255), int(g * 255), int(b * 255))
def _darken(color, amount=40):
return tuple(_clamp(c - amount) for c in color)
def _blend(c1, c2, t):
"""Bland to farver. t=0 giver c1, t=1 giver c2."""
return tuple(_clamp(int(a + (b - a) * t)) for a, b in zip(c1, c2))
def draw_3d_rect(surface, color, rect, depth=3):
"""Tegn et realistisk ophøjet rektangel med bløde skygger og gradient."""
x, y, w, h = rect if isinstance(rect, tuple) else (rect.x, rect.y, rect.w, rect.h)
# Blød skygge (flere lag med alpha)
for d in range(depth, 0, -1):
alpha = 30 + (depth - d) * 15
sh = pygame.Surface((w, h), pygame.SRCALPHA)
sh.fill((0, 0, 0, min(alpha, 100)))
surface.blit(sh, (x + d, y + d))
# Hovedflade med subtle vertikal gradient
for row in range(h):
frac = row / max(1, h - 1)
rc = _blend(_lighten(color, 20), _darken(color, 15), frac)
pygame.draw.line(surface, rc, (x, y + row), (x + w - 1, y + row), 1)
# Bevelled kanter
highlight = _lighten(color, 55)
pygame.draw.line(surface, highlight, (x, y), (x + w - 1, y), 1)
pygame.draw.line(surface, highlight, (x, y), (x, y + h - 1), 1)
dark = _darken(color, 40)
pygame.draw.line(surface, dark, (x, y + h - 1), (x + w - 1, y + h - 1), 1)
pygame.draw.line(surface, dark, (x + w - 1, y), (x + w - 1, y + h - 1), 1)
# Inner glow (subtil lys ramme)
inner_hl = _lighten(color, 25)
if w > 4 and h > 4:
pygame.draw.line(surface, inner_hl, (x + 1, y + 1), (x + w - 2, y + 1), 1)
pygame.draw.line(surface, inner_hl, (x + 1, y + 1), (x + 1, y + h - 2), 1)
def draw_3d_circle(surface, color, center, radius, depth=2):
"""Tegn en realistisk 3D-sfære med gradient, ambient occlusion og specular."""
cx, cy = center
if radius < 1:
return
# Blød skygge
for d in range(depth, 0, -1):
alpha = 25 + (depth - d) * 20
sh = pygame.Surface((radius * 2 + 4, radius * 2 + 4), pygame.SRCALPHA)
pygame.draw.circle(sh, (0, 0, 0, min(alpha, 80)), (radius + 2, radius + 2), radius)
surface.blit(sh, (cx - radius - 2 + d, cy - radius - 2 + d))
# Basis cirkel
pygame.draw.circle(surface, color, (cx, cy), radius)
# Radial gradient (mørkere kant = ambient occlusion)
if radius >= 4:
dark_rim = _darken(color, 35)
pygame.draw.circle(surface, dark_rim, (cx, cy), radius, 2)
mid_rim = _darken(color, 18)
pygame.draw.circle(surface, mid_rim, (cx, cy), max(1, radius - 1), 1)
elif radius >= 2:
dark_rim = _darken(color, 30)
pygame.draw.circle(surface, dark_rim, (cx, cy), radius, 1)
# Specular highlights (realistisk lysrefleks)
if radius >= 3:
hl = _lighten(color, 90)
hr = max(1, radius // 3)
hx = cx - radius // 3
hy = cy - radius // 3
pygame.draw.circle(surface, hl, (hx, hy), hr)
# Sekundær diffus highlight
hl2 = _lighten(color, 40)
pygame.draw.circle(surface, hl2, (cx - radius // 5, cy - radius // 4), max(1, radius // 2))
def draw_3d_panel(surface, rect, base_color, depth=3):
"""Tegn et realistisk ophøjet panel med gradient og bløde kanter."""
x, y, w, h = rect if isinstance(rect, tuple) else (rect.x, rect.y, rect.w, rect.h)
# Blød skygge
for d in range(depth, 0, -1):
alpha = 20 + (depth - d) * 15
sh = pygame.Surface((w, h), pygame.SRCALPHA)
sh.fill((0, 0, 0, min(alpha, 80)))
surface.blit(sh, (x + d, y + d))
# Vertikal gradient panel
for row in range(h):
frac = row / max(1, h - 1)
rc = _blend(_lighten(base_color, 15), _darken(base_color, 10), frac)
pygame.draw.line(surface, rc, (x, y + row), (x + w - 1, y + row), 1)
# Bevelled kanter
highlight = _lighten(base_color, 45)
dark = _darken(base_color, 40)
pygame.draw.line(surface, highlight, (x, y), (x + w, y), 2)
pygame.draw.line(surface, highlight, (x, y), (x, y + h), 1)
pygame.draw.line(surface, dark, (x, y + h), (x + w, y + h), 2)
pygame.draw.line(surface, dark, (x + w, y), (x + w, y + h), 1)
def draw_3d_tile(surface, x, y, size, base_color, light_dir=(1, 1)):
"""Tegn en realistisk gulv-flise med subtil gradient og ambient occlusion."""
# Vertikal micro-gradient for dybde
for row in range(size):
frac = row / max(1, size - 1)
# Subtle gradient fra lys til mørkere
rc = _blend(_lighten(base_color, 6), _darken(base_color, 6), frac)
pygame.draw.line(surface, rc, (x, y + row), (x + size - 1, y + row), 1)
# Ambient occlusion (mørkere kanter)
ao = _darken(base_color, 18)
pygame.draw.line(surface, ao, (x + size - 1, y), (x + size - 1, y + size - 1), 1)
pygame.draw.line(surface, ao, (x, y + size - 1), (x + size - 1, y + size - 1), 1)
# Highlight kanter
hl = _lighten(base_color, 12)
pygame.draw.line(surface, hl, (x, y), (x + size - 1, y), 1)
pygame.draw.line(surface, hl, (x, y), (x, y + size - 1), 1)
class Snake:
def __init__(self, start_pos, direction, color, color_dark, color_belly):
self.color = color
self.color_dark = color_dark
self.color_belly = color_belly
self.direction = direction
self.next_direction = direction
self.body = []
self.alive = True
self.grow_pending = 0
self.invincible_timer = 0
x, y = start_pos
for i in range(3):
dx, dy = direction
self.body.append((x - dx * i, y - dy * i))
def reset(self, start_pos, direction):
self.direction = direction
self.next_direction = direction
self.body = []
self.alive = True
self.grow_pending = 0
self.invincible_timer = 0
x, y = start_pos
for i in range(3):
dx, dy = direction
self.body.append((x - dx * i, y - dy * i))
@property
def is_invincible(self):
return self.invincible_timer > 0
def set_direction(self, new_dir):
if new_dir != OPPOSITES.get(self.direction):
self.next_direction = new_dir
def move(self):
if not self.alive:
return
self.direction = self.next_direction
head_x, head_y = self.body[0]
dx, dy = self.direction
new_head = (head_x + dx, head_y + dy)
self.body.insert(0, new_head)
if self.grow_pending > 0:
self.grow_pending -= 1
else:
self.body.pop()
if self.invincible_timer > 0:
self.invincible_timer -= 1
def grow(self, amount=1):
self.grow_pending += amount
def head(self):
return self.body[0]
def check_wall_collision(self):
x, y = self.head()
if x < 0 or x >= GRID_W or y < 0 or y >= GRID_H:
if not self.is_invincible:
self.alive = False
def check_self_collision(self):
if self.head() in self.body[1:]:
if not self.is_invincible:
self.alive = False
def check_ruin_collision(self, ruins):
if self.head() in ruins:
if not self.is_invincible:
self.alive = False
def draw(self, surface, tick, gun_type=GUN_NONE, snake_type=SNAKE_NORMAL):
if not self.body:
return
n = len(self.body)
cs = CELL_SIZE
off_y = SCOREBOARD_H
sd = 2
for i in range(n):
x, y = self.body[i]
px = x * cs
py = y * cs + off_y
cx = px + cs // 2
cy = py + cs // 2
if self.is_invincible:
pulse = (math.sin(tick * 0.5) + 1) / 2
bright = int(180 + 75 * pulse)
body_col = (bright, bright, bright)
dark_col = (max(0, bright - 50),) * 3
belly_col = (min(255, bright + 20),) * 3
elif snake_type == SNAKE_RAINBOW:
hue = ((i * 18 + tick * 2) % 360) / 360.0
body_col = _hsv_to_rgb(hue, 0.75, 0.88)
dark_col = _darken(body_col, 40)
belly_col = _lighten(body_col, 30)
else:
body_col = self.color
dark_col = self.color_dark
belly_col = self.color_belly
if i == 0:
# ============ HOVED ============
dx, dy = self.direction
if snake_type in SQUARE_HEAD_TYPES:
# --- Firkantet hoved (Tank, Robot) ---
draw_3d_rect(surface, body_col, (px + 1, py + 1, cs - 2, cs - 2), depth=sd)
pygame.draw.rect(surface, dark_col, (px + 1, py + 1, cs - 2, cs - 2), 2, border_radius=3)
eo = cs // 4
e1 = (cx - eo, cy) if dx == 0 else (cx, cy - eo)
e2 = (cx + eo, cy) if dx == 0 else (cx, cy + eo)
if snake_type == SNAKE_TANK:
if dx != 0:
pygame.draw.line(surface, dark_col, (cx, py + 3), (cx, py + cs - 3), 1)
else:
pygame.draw.line(surface, dark_col, (px + 3, cy), (px + cs - 3, cy), 1)
draw_3d_rect(surface, (200, 200, 80), (e1[0] - 2, e1[1] - 1, 4, 2), depth=1)
draw_3d_rect(surface, (200, 200, 80), (e2[0] - 2, e2[1] - 1, 4, 2), depth=1)
ant_x = cx - dx * (cs // 3)
ant_y = cy - dy * (cs // 3)
pygame.draw.line(surface, (180, 180, 180), (ant_x, ant_y), (ant_x, ant_y - 9), 1)
pr = 2 if tick % 10 < 5 else 3
draw_3d_circle(surface, RED, (ant_x, ant_y - 9), pr, depth=1)
else: # ROBOT
# LED øjne
led_col = (50, 255, 50) if tick % 8 < 4 else (20, 180, 20)
draw_3d_rect(surface, led_col, (e1[0] - 2, e1[1] - 2, 4, 4), depth=1)
draw_3d_rect(surface, led_col, (e2[0] - 2, e2[1] - 2, 4, 4), depth=1)
# Antenne med roterende top
ant_x = cx - dx * (cs // 3)
ant_y = cy - dy * (cs // 3)
pygame.draw.line(surface, (180, 180, 190), (ant_x, ant_y), (ant_x, ant_y - 8), 2)
ang = tick * 0.4
rx = int(ant_x + 3 * math.cos(ang))
ry = int(ant_y - 8 + 2 * math.sin(ang))
draw_3d_circle(surface, (100, 200, 255), (rx, ry), 2, depth=1)
# Mund-gitter
mx = cx + dx * (cs // 3)
my = cy + dy * (cs // 3)
for off in (-2, 0, 2):
if dx != 0:
pygame.draw.line(surface, (120, 120, 130), (mx, my + off - 1), (mx + dx * 2, my + off - 1), 1)
else:
pygame.draw.line(surface, (120, 120, 130), (mx + off - 1, my), (mx + off - 1, my + dy * 2), 1)
else:
# --- Rund hoved (alle andre 18 typer) ---
draw_3d_circle(surface, body_col, (cx, cy), cs // 2, depth=sd)
eo = cs // 4
if dx == 0:
e1, e2 = (cx - eo, cy), (cx + eo, cy)
poff = (0, dy * 2)
else:
e1, e2 = (cx, cy - eo), (cx, cy + eo)
poff = (dx * 2, 0)
# --- Øjne per type ---
if snake_type == SNAKE_DOG:
draw_3d_circle(surface, WHITE, e1, 4, depth=1)
draw_3d_circle(surface, WHITE, e2, 4, depth=1)
pygame.draw.circle(surface, (60, 30, 10), (e1[0] + poff[0], e1[1] + poff[1]), 2)
pygame.draw.circle(surface, (60, 30, 10), (e2[0] + poff[0], e2[1] + poff[1]), 2)
elif snake_type == SNAKE_CAT:
draw_3d_circle(surface, (220, 200, 50), e1, 3, depth=1)
draw_3d_circle(surface, (220, 200, 50), e2, 3, depth=1)
# Slit-pupiller
if dx == 0:
pygame.draw.line(surface, BLACK, (e1[0] + poff[0], e1[1] - 2), (e1[0] + poff[0], e1[1] + 2), 1)
pygame.draw.line(surface, BLACK, (e2[0] + poff[0], e2[1] - 2), (e2[0] + poff[0], e2[1] + 2), 1)
else:
pygame.draw.line(surface, BLACK, (e1[0] - 2, e1[1] + poff[1]), (e1[0] + 2, e1[1] + poff[1]), 1)
pygame.draw.line(surface, BLACK, (e2[0] - 2, e2[1] + poff[1]), (e2[0] + 2, e2[1] + poff[1]), 1)
elif snake_type == SNAKE_ALIEN:
draw_3d_circle(surface, (20, 20, 20), e1, 5, depth=1)
draw_3d_circle(surface, (20, 20, 20), e2, 5, depth=1)
draw_3d_circle(surface, (0, 255, 100), e1, 3, depth=0)
draw_3d_circle(surface, (0, 255, 100), e2, 3, depth=0)
elif snake_type == SNAKE_ZOMBIE:
draw_3d_circle(surface, (200, 200, 50), e1, 3, depth=1)
pygame.draw.circle(surface, (120, 20, 20), (e1[0] + poff[0], e1[1] + poff[1]), 2)
# X-øje
pygame.draw.line(surface, RED, (e2[0] - 2, e2[1] - 2), (e2[0] + 2, e2[1] + 2), 2)
pygame.draw.line(surface, RED, (e2[0] + 2, e2[1] - 2), (e2[0] - 2, e2[1] + 2), 2)
elif snake_type == SNAKE_SKELETON:
# Tomme øjenhuler
pygame.draw.circle(surface, (20, 15, 10), e1, 4)
pygame.draw.circle(surface, (20, 15, 10), e2, 4)
pygame.draw.circle(surface, (50, 40, 30), e1, 2)
pygame.draw.circle(surface, (50, 40, 30), e2, 2)
elif snake_type == SNAKE_LAVA:
# Glødende øjne
glow = (255, 100 + int(50 * math.sin(tick * 0.3)), 20)
draw_3d_circle(surface, glow, e1, 3, depth=1)
draw_3d_circle(surface, glow, e2, 3, depth=1)
elif snake_type == SNAKE_PIRATE:
# Normalt øje + klap
draw_3d_circle(surface, WHITE, e1, 3, depth=1)
pygame.draw.circle(surface, BLACK, (e1[0] + poff[0], e1[1] + poff[1]), 2)