-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode smileyface.py
More file actions
1305 lines (1086 loc) · 51.8 KB
/
Code smileyface.py
File metadata and controls
1305 lines (1086 loc) · 51.8 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 math
import pickle
import time
from pygame.locals import *
limit = lambda maxval, minval, value: max(min(maxval, value), minval)
pack = "Assets/"
'''
This is a comment group.
(✿◠‿◠)
'''
random.seed(0)
BRUSH = 3
winsize = [500, 500]
pygame.init()
WIN = pygame.display.set_mode(winsize, RESIZABLE)
logo = pygame.image.load(pack + "GUIs/Logo.png")
otherlogo = pygame.image.load(pack + "GUIs/Other logo.png")
clock = pygame.time.Clock()
pygame.font.init()
FONT = pygame.font.Font(pack + "Font.ttf", 25)
def drawfont(text, pos):
# Text is "FONT.render(f"And he said, \"Hi. (:\"", 1, (255, 255, 255))"
WIN.blit(text, pos)
pygame.display.set_caption("SPRINGFEET")
def blit_alpha(target, source, location, opacity):
x = location[0]
y = location[1]
temp = pygame.Surface((source.get_width(), source.get_height())).convert()
temp.blit(target, (-x, -y))
temp.blit(source, (0, 0))
temp.set_alpha(limit(255, 0, opacity))
target.blit(temp, location)
done = False
class Mouse():
def __init__(self) -> None:
self.leftMiddleRight = pygame.mouse.get_pressed()
self.left = self.leftMiddleRight[0]
self.right = self.leftMiddleRight[2]
self.middle = self.leftMiddleRight[1]
self.leftclick = False
self.onetimeplaceholder = True
self.pos = pygame.mouse.get_pos()
self.x, self.y = self.pos
def update(self):
self.leftMiddleRight = pygame.mouse.get_pressed()
self.left = self.leftMiddleRight[0]
self.right = self.leftMiddleRight[2]
self.middle = self.leftMiddleRight[1]
self.down = self.left or self.middle or self.right
if self.left and self.onetimeplaceholder:
self.leftclick = True
self.onetimeplaceholder = False
else:
self.leftclick = False
if not self.left:
self.onetimeplaceholder = True
self.pos = pygame.mouse.get_pos()
self.x, self.y = self.pos
MOUSE = Mouse()
class Button:
def __init__(self) -> None:
self.image = {
"idle": pygame.image.load(pack + "GUIs/Buttons/idle.png"),
"mousehover": pygame.image.load(pack + "GUIs/Buttons/hover.png"),
"idlepushed": pygame.image.load(pack + "GUIs/Buttons/idlepushed.png"),
"mousehoverpushed": pygame.image.load(pack + "GUIs/Buttons/hoverpushed.png"),
}
self.buttons = []
self.menucurrent = 1
def create(self, text, x, y, sizex, sizey, type, menu, action):
self.buttons.append(
{
"pos": (x, y),
"size": (sizex, sizey),
"text": text,
"rotationboost": 0,
"viscoscity": 255,
"style": type,
"pushed": False,
"menu": menu,
"menuswitchaction": action,
}
)
def removeAll(self):
self.buttons = []
def remove(self, ID):
self.buttons.pop(ID)
def draw(self):
for button in self.buttons:
if button["menu"] == self.menucurrent:
bx, by = button["pos"]
sx, sy = button["size"]
bx, by = button["pos"]
if bx == -1:
bx = pygame.transform.scale(self.image["idle"], (sx, sy)).get_rect(center = WIN.get_rect().center).x
if by == -1:
by = pygame.transform.scale(self.image["idle"], (sx, sy)).get_rect(center = WIN.get_rect().center).y
if MOUSE.x > bx and \
MOUSE.x < bx + sx and \
MOUSE.y > by and \
MOUSE.y < by + sy:
if MOUSE.leftclick:
button["pushed"] = not button["pushed"]
if button["menuswitchaction"] > 0:
button["pushed"] = False
self.menucurrent = button["menuswitchaction"]
if button["menuswitchaction"] == 0: GAME.setup(); GAME.isPlaying = True
if button["pushed"]:
imageToBlit = self.image["mousehoverpushed"]
else:
imageToBlit = self.image["mousehover"]
else:
if button["pushed"]:
imageToBlit = self.image["idlepushed"]
else:
imageToBlit = self.image["idle"]
# Image to print
printImg = pygame.transform.scale(
# Image to resize
pygame.transform.rotate(
imageToBlit, # Image to rotate
# Rotation
button["rotationboost"]
),
# Size × size booster
(sx, sy)
)
blit_alpha(WIN,
# Image to print
printImg,
# Location to print
(bx, by),
button["viscoscity"]
)
blit_alpha(WIN,
# Image to print
pygame.transform.scale(
# Image to resize
pygame.transform.rotate(
FONT.render(button["text"], 1, (255, 255, 255)), # Image to rotate
# Rotation
button["rotationboost"]
),
# Size × size booster
((sx) / 1.5, (sy) / 1.5)
),
# Location to print
(bx + 2 * (sx / 40), by + 1 * (sy / 10)),
button["viscoscity"]
)
BUTTON = Button()
displaywidth, displayheight = pygame.display.get_surface().get_size()
class Bossbars:
def __init__(self):
self.ID = [
{"colour": "blue",
"prog": pygame.image.load(pack + "GUIs/Bars/blue_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/blue_background.png"),
},
{"colour": "green",
"prog": pygame.image.load(pack + "GUIs/Bars/green_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/green_background.png"),
},
{"colour": "pink",
"prog": pygame.image.load(pack + "GUIs/Bars/pink_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/pink_background.png"),
},
{"colour": "purple",
"prog": pygame.image.load(pack + "GUIs/Bars/purple_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/purple_background.png"),
},
{"colour": "red",
"prog": pygame.image.load(pack + "GUIs/Bars/red_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/red_background.png"),
},
{"colour": "white",
"prog": pygame.image.load(pack + "GUIs/Bars/white_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/white_background.png"),
},
{"colour": "yellow",
"prog": pygame.image.load(pack + "GUIs/Bars/yellow_progress.png"),
"bg": pygame.image.load(pack + "GUIs/Bars/yellow_background.png"),
}
]
def draw(self, y, valinp, maxinp, bb_colour):
try:
tempbg, tempprg = (
pygame.transform.scale(self.ID[bb_colour]["bg"], (182 * 5, 5 * 5)),
pygame.transform.scale(self.ID[bb_colour]["prog"], (182 * 5, 5 * 5))
)
# Printing the background
WIN.blit(tempbg, (tempbg.get_rect(center = WIN.get_rect().center).x, y))
# Printing the progress
WIN.blit(
tempprg,
(
tempprg.get_rect(center = WIN.get_rect().center).x,
y
),
( 0, 0,
tempprg.get_rect(center = WIN.get_rect().center).x * (5 / (maxinp / valinp)),
5 * 5
)
)
except: pass
bossbar = Bossbars()
BLOCKS = [
{"img": pack + "Air.png",
"name": "Air",
"tags": ["NoRender"],
"extratags": []
}, # ID 0
{"img": pack + "dirt_block.png",
"name": "Dirt Block",
"tags": ["Solid", "Non-transparent"],
"extratags": ["DitchCorrodable"]
}, # ID 1
{"img": pack + "grass_block.png",
"name": "Grass Block",
"tags": ["Solid", "Non-transparent"],
"extratags": ["DitchCorrodable"]
}, # ID 2
{"img": pack + "oak_log.png",
"name": "Oak log",
"tags": ["Solid"],
"extratags": ["noOverhang"]
}, # ID 3
{"img": pack + "oak_leaves.png",
"name": "Oak Leaves",
"tags": ["Semisolid"],
"extratags": []
}, # ID 4
{"img": pack + "lava.png",
"name": "Lava",
"tags": ["playerDmg"],
"extratags": []
}, # ID 5
{"img": pack + "lava_top.png",
"name": "Lava",
"tags": ["playerDmg"],
"extratags": []
}, # ID 6
{"img": pack + "bricks.png",
"name": "Bricks",
"tags": ["Solid"],
"extratags": ["noOverhang"]
}, # ID 7
]
def checkcollisions(pos1x, pos1y, pos2x, pos2y, pos1sze, pos2sze):
if abs(pos1x - pos2x) < (pos1sze + pos2sze) / 2 and abs(pos1y - pos2y) < (pos1sze + pos2sze) / 2:
return True
else:
return False
class Particles:
def __init__(self):
self.particlesOnScreen = []
self.image = pygame.transform.scale(
pygame.image.load(
pack + "Particle.png"
),
(4, 4))
def draw(self):
for particle in self.particlesOnScreen:
print("We are drawing a particle at " + str(particle["pos"]))
px, py = particle["pos"]
WIN.blit(self.image,
(px, py)
)
def create(self, x, y, vx, vy, parttype, syncedwithtilemap):
self.particlesOnScreen.append(
{
"pos": (x, y),
"vel": (vx, vy),
"type": parttype,
"?BG": not syncedwithtilemap,
"timer": 100,
}
)
def createAll(self, amount):
displaywidth, displayheight = pygame.display.get_surface().get_size()
while len(self.particlesOnScreen) < amount:
self.create( # Pos ↓
random.randint(1, displaywidth),
random.randint(1, displayheight),
# Vel ↓
0, 0,
0, # Particle type
False # Synced with tilemap
)
while len(self.particlesOnScreen) > amount:
self.particlesOnScreen.pop()
def update(self, partID):
displaywidth, displayheight = pygame.display.get_surface().get_size()
currpart = self.particlesOnScreen[partID]
pos = currpart["pos"]
posx, posy = pos
vel = currpart["vel"]
velx, vely = vel
parttype = currpart["type"]
if parttype == 0:
vely += (random.randint(1, 3) - 2)
velx += (random.randint(1, 3) - 2)
self.particlesOnScreen[partID]["timer"] -= 1
posx += limit(1, -1, velx)
posy += limit(1, -1, vely)
pos = (limit(displaywidth, 0, posx), limit(displayheight, 0, posy))
if parttype == 0: vel = (limit(1, -1, velx), limit(1, -1, vely))
else: vel = (limit(1, -1, velx), limit(1, -1, vely))
self.particlesOnScreen[partID]["pos"] = pos
self.particlesOnScreen[partID]["vel"] = vel
def updateAll(self):
for particle in range(len(self.particlesOnScreen)):
self.update(particle)
PARTICLE = Particles()
PARTICLE.createAll(amount = 0)
spaceDown = False
class Player:
def __init__(self):
self.x = 0
self.y = 2
self.vx = 10
self.vy = 0
self.spaceDown = False
self.spaceDownTimer = True
self.HP = 500
self.MAX_HP = self.HP
self.score = 0
try:
#if True:
# Load the high score from the file
with open('highscore.scores', 'rb') as f:
self.highscore = pickle.load(f)
#print(str(pickle.load(f)))
print("Loading high scores as " + str(self.highscore))
self.highscore = float(str(self.highscore))
except:
#else:
# Save the dictionary to a file
with open('highscore.scores', 'wb') as f:
pickle.dump(20, f)
self.highscore = 20
print("Could not find high scores file, saving file named \"highscore.scores\" as \"" + str(self.highscore) + "\".")
self.stamina = 10000
self.maxscore = 0
self.staminaMax = self.stamina
self.saturation = self.score
self.isRegeneratingStamina = False
self.gravity = 0.01
self.originalgravity = 0.01
self.jumpHeight = -0.1
self.jumpTime = 0
self.twirlTime = 50
self.jumped = False
self.size = (64.1, 64.1)
self.sizex, self.sizey = self.size
self.image = pygame.transform.scale(
pygame.image.load(
pack + "Player/Playerframe1Run.png"
),
self.size)
def updateMovement(self):
self.maxscore = max(self.score, self.maxscore)
global keys, movex, movey
if not self.spaceDownTimer:
self.spaceDown = False
if keys[pygame.K_SPACE] and self.spaceDownTimer:
self.spaceDown = True
self.spaceDownTimer = False
if not keys[pygame.K_SPACE]:
self.spaceDownTimer = True
self.spaceDown = False
self.vy = min(self.vy, 5)
self.twirlTime -= 1
#'''
self.gravity = self.originalgravity
if keys[pygame.K_s] and self.stamina > 0 and not self.isRegeneratingStamina: self.gravity += 0.03; self.stamina -= 2
#'''
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
collisions2 = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Semisolid")
if self.HP > self.MAX_HP: self.HP = self.MAX_HP
if self.stamina > self.staminaMax: self.stamina = self.staminaMax; self.isRegeneratingStamina = False
else:
if self.isRegeneratingStamina: self.stamina += 4.5
else: self.stamina += 1
if self.vy > 0 and (True in collisions[2] or (True in collisions2[0] or True in collisions2[1] or True in collisions2[2])):
while True in collisions[2] or (True in collisions2[0] or True in collisions2[1] or True in collisions2[2]):
self.y -= 0.001
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
collisions2 = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Semisolid")
if self.vy > 0: self.vy = 0
self.jumpTime = 15
self.twirlTime = 50
self.jumped = True
self.isSliding = False
else:
# Here is a note
'''
self.y += self.gravity
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
if collisions[0][2] or collisions[1][2] or collisions[2][2]: self.y -= self.gravity
else: self.vy += self.gravity'''
self.vy += self.gravity
self.jumpTime -= 1
if keys[pygame.K_SPACE] and self.jumpTime > 0 and self.jumped:
if keys[pygame.K_s] and not self.isRegeneratingStamina: self.vy += self.jumpHeight * 5
else: self.vy += self.jumpHeight
if (self.jumped and not keys[pygame.K_SPACE]) or (keys[pygame.K_s] and not self.isRegeneratingStamina): self.jumped = False
if keys[pygame.K_s] and not self.isRegeneratingStamina and self.stamina > 0: self.vy = limit(0.5, -0.7, self.vy); self.stamina -= 2; self.stamina -= 2
else: self.vy = limit(0.4, -0.5, self.vy)
if True in collisions[0]:
while True in collisions[0]:
self.HP += 0.001
self.y += 0.001
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
#self.vy -= self.gravity
self.vy *= -1
if keys[pygame.K_a] and self.stamina > 0 and not self.isRegeneratingStamina: self.vx -= 0.05; self.stamina -= 2
t = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "playerDmg")
if True in t[1]:
self.HP -= 10
if self.y > TILEMAP.height: self.HP -= self.y - TILEMAP.height
if self.saturation < 0: self.HP += self.saturation / 8
if not isNegative(self.vx - 0.001): self.saturation += 1
if keys[pygame.K_RIGHT] and not self.isRegeneratingStamina: self.HP += 1; self.stamina -= 10
if keys[pygame.K_LEFT]:
self.HP -= 1; self.stamina += 10
#'''
if not (keys[pygame.K_LSHIFT] and self.stamina > 0 and not self.isRegeneratingStamina):
if collisions[0][2] or collisions[1][2] or collisions[2][2]:
self.score -= 1; self.saturation -= 1
if (keys[pygame.K_s] and keys[pygame.K_SPACE] and not self.isRegeneratingStamina): prevpos = self.y
while collisions[0][2] or collisions[1][2] or collisions[2][2]:
if not ((keys[pygame.K_s] and not self.isRegeneratingStamina) and keys[pygame.K_SPACE] and not collisions[0][2]): self.x -= 0.001
else: self.y -= 0.001; self.HP += 0.001
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
if (keys[pygame.K_s] and not self.isRegeneratingStamina and keys[pygame.K_SPACE] and not collisions[0][2]):
if abs(prevpos - self.y) >= 1:
self.y = prevpos
while collisions[0][2] or collisions[1][2] or collisions[2][2]:
self.x -= 0.001
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
if not ((keys[pygame.K_s] and not self.isRegeneratingStamina) or keys[pygame.K_SPACE]): self.vx = 0
else:
self.x += 0.001
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
if collisions[0][2] or collisions[1][2] or collisions[2][2]:
self.x -= 0.001
else:
self.vx += 0.001
if keys[pygame.K_d] and self.stamina > 0 and not self.isRegeneratingStamina and self.vx < 0.5: self.vx += 0.01; self.stamina -= 2
while collisions[0][0] or collisions[1][0] or collisions[2][0]:
self.x += 0.001
self.vx = 0
collisions = TILEMAP.checkCollisions(self.x, self.y, self.sizex, self.sizey, "Solid")
else: self.vx += 0.001; self.stamina -= 100
if self.stamina <= 0:
self.isRegeneratingStamina = True
#'''
self.vx = limit(0.3, -0.3, self.vx)
self.saturation = limit(10, -10, self.saturation)
if self.spaceDown and self.vy > 0 and isNegative(self.twirlTime):
self.twirlTime = 50
self.vy = 0.001
self.x += (self.vx * 1) / 3
self.score += self.vx - 0.2
self.saturation += self.vx - 0.2
self.y += self.vy / 4
def scoreUpdate(self):
if self.score > self.highscore:
self.highscore = self.score
print("Scores have been updated to " + str(self.highscore))
# Save the dictionary to a file
with open('highscore.scores', 'wb') as f:
pickle.dump(self.highscore, f)
PLAYER = Player()
class Vibrate():
def __init__(self):
self.curAmount = 0
self.curTime = 0
def vibrate(self):
pass
def stitch(list1, list2):
tlist = list1
for i in list2 :
tlist.append(i)
return tlist
class Tilemap:
def __init__(self):
self.width = 200
self.height = 17
self.camx = 20
self.camy = 20
self.selectedx = 0
self.selectedy = 0
self.size = 64
self.name = ""
self.tilemap = []
self.tilemapaddon = []
self.tilemapStart = []
def checkCollisions(self, Player_X, Player_Y, Player_SizeX, Player_SizeY, Tag_To_Look_For):
px, py, pszex, pszey, tsze, tm = (Player_X, Player_Y, Player_SizeX, Player_SizeY, self.size, self.tilemap)
returnval = [
[False, False, False],
[False, False, False],
[False, False, False]
]
for x in range(3):
for y in range(3):
try:
if checkcollisions(px * pszex, py * pszey, round(px + (x - 1)) * pszex, round(py + y - 1) * pszey, pszex, tsze):
#pygame.sprite.spritecollideany()
#try:
if abs(round(py + (y - 1))) != round(py + (y - 1)):
pass
elif Tag_To_Look_For in BLOCKS[tm[round(py + (y - 1))][round(px + (x - 1))]]["tags"]:
if Tag_To_Look_For != "Semisolid": returnval[y][x] = True
else:
if (py * pszey < (round(py + y - 1) * pszey) - (tsze / 4)) and tm[round(py + (y - 1)) - 1][round(px + (x - 1))] == 0:
returnval[y][x] = True
else:
returnval[y][x] = False
except: pass
# if isRaise: raise Exception("Hi ~o( =∩ω∩= )m")
return returnval
def draw(self):
displaywidth, displayheight = pygame.display.get_surface().get_size()
for YI in range(self.height):
for XI in range(self.width):
if not "NoRender" in BLOCKS[self.tilemap[YI][XI]]["tags"]:
WIN.blit(BLOCKS[self.tilemap[YI][XI]]["img"],
(
XI * self.size + self.camx, # X POS
YI * self.size + self.camy, # Y POS
))
def generateName(self):
nouns = ["Block", "Brick", "Ledge", "Path", "Blitz", "Journey", "Quest", "Chase"]
for i in range(len(BLOCKS)):
nouns.append(BLOCKS[i]["name"])
verbs = ["Rush", "Hurdle", "Dash", "Race", "Sprint", "Leap", "Jump", "Run", "Charge"]
adjectives = ["Swift", "Speedy", "Swift", "Quick", "Fast", "Rapid", "Fleet", "Zippy", "Nimble"]
self.name = f"{random.choice(adjectives)} {random.choice(nouns)} {random.choice(verbs)}"
def create(self, tw, th, tilemap):
#tilemap = []
for i in range(th):
tilemap.append([])
for _ in range(tw):
tilemap[i].append(0)
def glue(self, tilemap1, tilemap2):
tilemapoutput = tilemap1.copy()
for y in range(len(tilemapoutput)):
tilemapoutput[y] = stitch(tilemap1[y], tilemap2[y])
return tilemapoutput
def fix(self, Tilemap_to_fix):
#raise Exception("We have reached the function")
for x in range(len(Tilemap_to_fix[0])):
for y in range(len(Tilemap_to_fix)):
try:
if Tilemap_to_fix[y][x] == 2: # If the block is grass
if "Non-transparent" in BLOCKS[Tilemap_to_fix[y - 1][x]]["tags"]: # If the block above isn't transparent
Tilemap_to_fix[y][x] = 1 # Set the block to dirt
elif Tilemap_to_fix[y][x] == 1: # If the block is dirt
if not "Non-transparent" in BLOCKS[Tilemap_to_fix[y - 1][x]]["tags"]: # If the block above is transparent
Tilemap_to_fix[y][x] = 2 # Set the block to grass
elif Tilemap_to_fix[y][x] == 7: # If the block is bricks
#raise Exception("We have found di bricks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
if not "Non-transparent" in BLOCKS[Tilemap_to_fix[y + 1][x]]["tags"]: # If the block below is transparent
Tilemap_to_fix[y + 1][x] == 7
except: pass
def slice(self, Tilemap_to_slice, Column_to_slice):
for i in range(len(Tilemap_to_slice)):
Tilemap_to_slice[i].pop(Column_to_slice)
TILEMAP.width -= 1
def generateFlatArea(self, tilemap, groundHeight):
print(len(tilemap[0]))
print(len(tilemap))
for X in range(len(tilemap[0])):
for Y in range(len(tilemap)):
if Y > groundHeight: tilemap[Y][X] = 1
elif Y == groundHeight: tilemap[Y][X] = 2
def generateTuotorial(self, tilemap):
for x in range(len(tilemap[0])):
tilemap[len(tilemap) - 1][x] = 1
tilemap[len(tilemap) - 2][x] = 1
tilemap[len(tilemap) - 3][x] = 2
tilemap[len(tilemap) - 4][140] = 7
tilemap[len(tilemap) - 4][141] = 7
tilemap[len(tilemap) - 4][142] = 7
tilemap[len(tilemap) - 4][143] = 7
tilemap[len(tilemap) - 4][144] = 7
tilemap[len(tilemap) - 5][141] = 7
tilemap[len(tilemap) - 5][142] = 7
tilemap[len(tilemap) - 5][143] = 7
tilemap[len(tilemap) - 5][144] = 7
tilemap[len(tilemap) - 6][142] = 7
tilemap[len(tilemap) - 6][143] = 7
tilemap[len(tilemap) - 6][144] = 7
tilemap[len(tilemap) - 7][143] = 7
tilemap[len(tilemap) - 7][144] = 7
tilemap[len(tilemap) - 8][144] = 7
def setblock(y, x, type, tilemap, allowErrors):
if allowErrors:
tilemap[round(y)][round(x)] = type
if type >= len(BLOCKS):
raise Exception("UMMMM... The block you specified is out of range. (っ °Д °;)っ")
else:
try:
tilemap[round(y)][round(x)] = type
except: pass
if type >= len(BLOCKS):
raise Exception("UMMMM... The block you specified is out of range. (っ °Д °;)っ")
targetpos = (len(tilemap) - 3, 170)
targetposy, targetposx = targetpos
height = 4
# Floor
setblock(targetposy, targetposx + 2, 7, tilemap, True)
setblock(targetposy, targetposx + 1, 7, tilemap, True)
setblock(targetposy, targetposx, 7, tilemap, True)
setblock(targetposy, targetposx - 1, 7, tilemap, True)
setblock(targetposy, targetposx - 2, 7, tilemap, True)
# Walls
for i in range(height):
setblock(targetposy - (i + 1), targetposx + 2, 3, tilemap, True)
setblock(targetposy - (i + 1), targetposx - 2, 3, tilemap, True)
# Roof
setblock(targetposy - (height + 1), targetposx + 2, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx + 1, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx - 1, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx - 2, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx + 1, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx - 1, 7, tilemap, True)
setblock(targetposy - (height + 3), targetposx, 7, tilemap, True)
def generateTerrain(self, tilemap, segmentsGenerated, segmentStartX, segmentWidth, groundHeight):
groundHeight = len(tilemap) - groundHeight
def setblock(y, x, type, tilemap, allowErrors):
if allowErrors:
tilemap[round(y)][round(x)] = type
if type >= len(BLOCKS):
raise Exception("UMMMM... The block you specified is out of range. (っ °Д °;)っ")
else:
try:
tilemap[round(y)][round(x)] = type
except: pass
if type >= len(BLOCKS):
raise Exception("UMMMM... The block you specified is out of range. (っ °Д °;)っ")
for I in range(segmentsGenerated):
# Generate the ground
for Y in range(len(tilemap)):
for X in range(min( len(tilemap[0]), segmentWidth )):
try:
if Y == groundHeight:
setblock(Y, X + segmentStartX, 2, tilemap, False)
if Y > groundHeight:
setblock(Y, X + segmentStartX, 1, tilemap, False)
except: pass
# Generate obstacles
rndvalue = random.randint(1, 5)
#rndvalue2 = random.randint(1, 4)
rndvalue2 = 1
if rndvalue == 1:
# Tree obstacle
try:
for i in range(3):
targetpos = (groundHeight - i - 1, math.floor(segmentWidth / 2) + segmentStartX)
targetposy, targetposx = targetpos
setblock(targetposy, targetposx, 3, tilemap, True)
if i != 0:
setblock(targetposy, targetposx + 1, 4, tilemap, True)
setblock(targetposy, targetposx - 1, 4, tilemap, True)
setblock(targetposy, targetposx + 2, 4, tilemap, True)
setblock(targetposy, targetposx - 2, 4, tilemap, True)
if i == min(max(min(len(tilemap) - groundHeight - 1, 4), 3), len(tilemap)):
setblock(targetposy, targetposx - 2, 4, tilemap, True)
for i in range(2):
setblock(targetposy - i - 1, targetposx, 4, tilemap, True)
setblock(targetposy - i - 1, targetposx - 1, 4, tilemap, True)
setblock(targetposy - i - 1, targetposx + 1, 4, tilemap, True)
except: pass
elif rndvalue == 2:
# Ditch obstacle
for X in range(2):
for Y in range(groundHeight):
targetpos = (len(tilemap) - Y, X + round(segmentWidth / 2) - segmentStartX)
targetposy, targetposx = targetpos
try:
if "DitchCorrodable" in BLOCKS[tilemap[targetposy][targetposx]]["extratags"]:
setblock(targetposy, targetposx, 0, tilemap, False)
except: pass
elif rndvalue == 3:
# Lava pool obstacle
for X in range(2):
setblock(groundHeight, X + round(segmentWidth / 2) - segmentStartX, 6, tilemap, False)
setblock(groundHeight + 1, X + round(segmentWidth / 2) - segmentStartX, 2, tilemap, False)
elif rndvalue == 4:
# Bricks obstacle
dir = random.randint(1, 3) - 2
dir = -1
height = random.randint(2, 5)
for Y in range(height):
setblock((groundHeight - height) + Y, round(segmentWidth / 2) - segmentStartX, 7, tilemap, False)
for X in range(Y):
setblock((groundHeight - height) + Y, (round(segmentWidth / 2) - segmentStartX) + (X + 1) * dir, 7, tilemap, False)
elif rndvalue == 5:
# House obstacle
try:
targetpos = (groundHeight, math.floor(segmentWidth / 2) + segmentStartX)
targetposy, targetposx = targetpos
height = 3
# Floor
setblock(targetposy, targetposx + 2, 7, tilemap, True)
setblock(targetposy, targetposx + 1, 7, tilemap, True)
setblock(targetposy, targetposx, 7, tilemap, True)
setblock(targetposy, targetposx - 1, 7, tilemap, True)
setblock(targetposy, targetposx - 2, 7, tilemap, True)
# Walls
for i in range(height):
setblock(targetposy - (i + 1), targetposx + 2, 3, tilemap, True)
setblock(targetposy - (i + 1), targetposx - 2, 3, tilemap, True)
# Roof
setblock(targetposy - (height + 1), targetposx + 2, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx + 1, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx - 1, 7, tilemap, True)
setblock(targetposy - (height + 1), targetposx - 2, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx + 1, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx, 7, tilemap, True)
setblock(targetposy - (height + 2), targetposx - 1, 7, tilemap, True)
setblock(targetposy - (height + 3), targetposx, 7, tilemap, True)
except: pass
segmentStartX += segmentWidth
self.fix(tilemap)
TILEMAP = Tilemap()
for i in range(len(BLOCKS)):
BLOCKS[i]["img"] = pygame.transform.scale(
pygame.image.load(
BLOCKS[i]["img"]
),
(TILEMAP.size, TILEMAP.size))
movex, movey = (0, 0)
movex2, movey2 = (0, 0)
keys = pygame.key.get_pressed()
class Game:
def __init__(self):
self.isPlaying = False
self.timeSinceStartPlaying = 0
self.paused = False
self.pausedForAReason = False
def setup(self):
random.seed = 18756189465832765
print(f"Name: {TILEMAP.name}")
TILEMAP.generateName()
TILEMAP.tilemap = []; TILEMAP.tilemapaddon = []; TILEMAP.tilemapStart = []
TILEMAP.create(TILEMAP.width, TILEMAP.height, TILEMAP.tilemap)
TILEMAP.create(30, TILEMAP.height, TILEMAP.tilemapStart)
TILEMAP.generateName()
tgroundHeight = random.randint(1, 5)
if BUTTON.buttons[4]["pushed"]:
TILEMAP.generateTuotorial(TILEMAP.tilemap)
else:
TILEMAP.generateTerrain(TILEMAP.tilemap, 99, 0, 6, 3 + tgroundHeight)
TILEMAP.generateFlatArea(TILEMAP.tilemapStart, tgroundHeight)
TILEMAP.tilemap = TILEMAP.glue(TILEMAP.tilemapStart, TILEMAP.tilemap)
PLAYER.x = 0
PLAYER.y = 2
PLAYER.vx = 10
PLAYER.vy = 0
PLAYER.HP = 500
PLAYER.MAX_HP = PLAYER.HP
PLAYER.score = 0
PLAYER.stamina = 10000
PLAYER.staminaMax = PLAYER.stamina
PLAYER.isRegeneratingStamina = False
PLAYER.gravity = 0.01
PLAYER.originalgravity = 0.01
PLAYER.jumpHeight = -0.1
PLAYER.jumpTime = 0
PLAYER.jumped = False
GAME = Game()
def controlsupdate():
global keys, movex, movey, movex2, movey2, timer
MOUSE.update()
movex, movey = (0, 0)
movex2, movey2 = (0, 0)
spaceDown = True
spaceDownTimer = True
if keys[pygame.K_w]: movey += 1
if keys[pygame.K_s]: movey -= 1
if keys[pygame.K_a]: movex += 1
if keys[pygame.K_d]: movex -= 1
if keys[pygame.K_UP]: movey2 += 1
if keys[pygame.K_DOWN]: movey2 -= 1
if keys[pygame.K_LEFT]: movex2 += 1
if keys[pygame.K_RIGHT]: movex2 -= 1
keys = pygame.key.get_pressed()
if keys[pygame.K_p] or GAME.pausedForAReason: GAME.paused = True; timer += 1
else:
if keys[pygame.K_f]:
GAME.paused = not GAME.paused
else:
GAME.paused = False
if (not GAME.paused) and GAME.isPlaying:
GAME.timeSinceStartPlaying += 1
tothenearest = lambda val, inp : round(val / inp) * inp
pause = pygame.transform.scale(
pygame.image.load(
pack + "GUIs/Pause.png"
),
(TILEMAP.size, TILEMAP.size))
ANYKEYS = False
GAME.paused = False
animState = 0
animStateVel = 0
isNegative = lambda x: abs(x) != x
isDecimal = lambda x: round(x) != x
def percentage(percent, whole):
return (percent * whole) / 100.0
timer = 0
animState = logo.get_rect(center = WIN.get_rect().center).y
timeSinceStart = 0
gradient = 0
gradientToggle = False
def drawCentredText(text, posy):
drawfont(
text, (text.get_rect(center = WIN.get_rect().center).x, posy))
def pausewhen(time, valToMeasure, key, textToDraw):
if BUTTON.buttons[4]["pushed"]:
if round(valToMeasure) == time and not key:
GAME.pausedForAReason = True