forked from matheus-1618/OneBit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneBit.py
1058 lines (901 loc) · 48.4 KB
/
OneBit.py
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
"""
ONEBIT THE GAME!
Jogo criado por: Leticia Coêlho Barbosa e Matheus Silva Melo de Oliveira
na disciplina de Design de Software
Professor orientador: Luciano Soares
1A- ENG
INSPER 2020.2
Créditos no arquivo README.md
"""
# ===== Inicialização =====
# ----- Importa e inicia pacotes
import pygame
import sys
from tilemap_codigo import *
from os import path
from config import *
from sprites import *
#----- Criando classe Jogo -----#
class Jogo:
def __init__(self):
#Inicializando biblioteca
pygame.init()
#Inicializando a trilha sonora
pygame.mixer.init()
#------Inicializando Tela------#
self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(TITLE)
self.clock = pygame.time.Clock()
#------Inicializando Fases e transições------#
self.playing = True
self.paused = False
self.GAMEOVER = False
self.TRANSITION= False
self.INSTRUCTION=False
self.WINNER= False
self.Fase1 = True
self.Fase2 = False
self.init_load = False
self.passa_fase= 0
#------Inicializando carregamento------#
self.load_data()
self.xp_total=0 # Xp acumulado total
self.propg= CANNONBALL_PROPG #Direcionamento dos tiros
self.last_respawn=0 #tempo para respawn
self.last_spawn=0 #Variavel para tempo de spawn
self.GAMEOVER = False #Variavel para iniciar a tela de Gameover
def load_data(self):
#------Caminhos para a busca de arquivo------#
game_folder = path.dirname(__file__)
img_folder = path.join(game_folder,'img')
map_folder1 = path.join(game_folder,'map1')
map_folder2 = path.join(game_folder,'map2N')
#------Importando mapa------#
if self.Fase1==True:
self.map = TiledMap(path.join(map_folder1, 'map1.tmx'))
self.map_img = self.map.make_map()
self.map_rect = self.map_img.get_rect()
elif self.Fase2==True:
self.map = TiledMap(path.join(map_folder2, 'map2N.tmx'))
self.map_img = self.map.make_map()
self.map_rect = self.map_img.get_rect()
#------Imagens inicias------#
self.init_img ={}
for imagem in INIT_IMG:
self.init_img[imagem]=pygame.image.load(path.join(IMG_DIR, imagem)).convert_alpha()
#------Imagens de instrução------#
self.instruction_img ={}
for img in INST_IMG:
self.instruction_img[img]=pygame.image.load(path.join(IMG_DIR,img))
#------Imagens de transição------#
self.transition_img ={}
for img in TRAN_IMG:
self.transition_img[img]=pygame.image.load(path.join(IMG_DIR,img))
#------Imagens da tela game_over------#
self.game_over_img={}
for img in OVER_IMG:
self.game_over_img[img]=pygame.image.load(path.join(IMG_DIR, img)).convert_alpha()
#------Imagens da tela de vencedor------#
self.winner_img={}
for imagem in WIN_IMG:
self.winner_img[imagem]=pygame.image.load(path.join(IMG_DIR, imagem)).convert_alpha()
#------Fontes utilizadas------#
self.ken_pixel = path.join(FONT_DIR, 'kenpixel_blocks.TTF')
self.romulus = path.join(FONT_DIR, 'romulus.TTF')
self.trioDX = path.join(FONT_DIR, 'TrioDX.fon')
self.romulus_20 = pygame.font.Font(self.romulus, 20)
self.romulus_30 = pygame.font.Font(self.romulus, 30)
self.romulus_80 = pygame.font.Font(self.romulus, 80)
self.kenpixel_40 = pygame.font.Font(self.ken_pixel, 40)
self.kenpixel_80 = pygame.font.Font(self.ken_pixel, 80)
self.trioDX_10 = pygame.font.Font(self.trioDX, 10)
self.trioDX_200 = pygame.font.Font(self.trioDX, 200)
#------ Inicializando musicas------#
#Inicializando músicas de fundo-da abertura
self.abertura = pygame.mixer.Channel(1)
self.abertura.set_volume(0.3)
self.game_over = pygame.mixer.Channel(2)
self.game_over.set_volume(0.3)
self.transition = pygame.mixer.Channel(3)
self.transition.set_volume(0.3)
self.level1 = pygame.mixer.Channel(4)
self.level1.set_volume(0.5)
self.level2 = pygame.mixer.Channel(5)
self.level2.set_volume(0.5)
self.winner = pygame.mixer.Channel(6)
self.winner.set_volume(0.3)
#Dicionário com os efeitos sonoros utilizados
self.sound_effects = {}
self.sound_effects['abertura'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'ONE_PIECE.ogg'))
self.sound_effects['game over'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'final.mp3'))
self.sound_effects['level1 theme'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'pirates.ogg'))
self.sound_effects['level2 theme'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'transition_theme.mp3'))
self.sound_effects['new_fase'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'new_fase.mp3'))
self.sound_effects['winner'] = pygame.mixer.Sound(path.join(MUSIC_DIR, 'winner.mp3'))
self.sound_effects['cannonball'] = pygame.mixer.Sound(path.join(EFFECTS_DIR, 'tiro_canhão.mp3'))
self.sound_effects['canhao']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'canhao.mp3' ))
self.sound_effects['cracken']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'cracken.WAV' ))
self.sound_effects['pirata1']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'pirate1.mp3' ))
self.sound_effects['pirata2']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'pirate2.mp3' ))
self.sound_effects['pirata3']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'pirate3.mp3' ))
self.sound_effects['pirata4']=pygame.mixer.Sound(path.join(EFFECTS_DIR,'pirate4.mp3' ))
#------Importando Imagens utilizadas------#
self.boat_img = pygame.image.load(path.join(img_folder, BOAT_IMG)).convert_alpha()
self.cannonball_img = pygame.image.load(path.join(img_folder, CANNONBALL_IMG)).convert_alpha()
self.cracken_img = pygame.image.load(path.join(img_folder, CRACKEN_IMG)).convert_alpha()
#Carregando imagens de itens:
self.carne_img=pygame.image.load(path.join(IMG_DIR,MEAT_IMG)).convert_alpha()
self.rum_img=pygame.image.load(path.join(IMG_DIR,RUM_IMG)).convert_alpha()
self.tesouro_img=pygame.image.load(path.join(IMG_DIR,TESOURO_IMG)).convert_alpha()
#------Importando movimentação dos personagens------#
#------Navio------#
#Esquerda
self.boat_left = {}
self.boat_left[BOAT_WALK_LEFT] = pygame.image.load(path.join(IMG_DIR,'Barco', BOAT_WALK_LEFT)).convert_alpha()
self.boat_left[BOAT_WALK_LEFT] = pygame.transform.scale(self.boat_left[BOAT_WALK_LEFT], (BOAT_WIDTH, BOAT_HEIGHT))
# Direita
self.boat_right = {}
self.boat_right[BOAT_WALK_RIGHT] = pygame.image.load(path.join(IMG_DIR,'Barco', BOAT_WALK_RIGHT)).convert_alpha()
self.boat_right[BOAT_WALK_RIGHT] = pygame.transform.scale(self.boat_right[BOAT_WALK_RIGHT], (BOAT_WIDTH, BOAT_HEIGHT))
# Cima
self.boat_up = {}
self.boat_up[BOAT_WALK_UP] = pygame.image.load(path.join(IMG_DIR,'Barco', BOAT_WALK_UP)).convert_alpha()
self.boat_up[BOAT_WALK_UP] = pygame.transform.scale(self.boat_up[BOAT_WALK_UP], (BOAT_WIDTH, BOAT_HEIGHT))
# Baixo
self.boat_down = {}
self.boat_down[BOAT_WALK_DOWN] = pygame.image.load(path.join(IMG_DIR,'Barco', BOAT_WALK_DOWN)).convert_alpha()
self.boat_down[BOAT_WALK_DOWN] = pygame.transform.scale(self.boat_down[BOAT_WALK_DOWN], (BOAT_WIDTH, BOAT_HEIGHT))
#------Piratas------#
#Esquerda
self.pirate_esquerda = {}
self.pirate_esquerda[PIRATA_ESQUERDA]=pygame.image.load(path.join(IMG_DIR,PIRATA_ESQUERDA))
self.pirate_esquerda[PIRATA_ESQUERDA]=pygame.transform.scale(self.pirate_esquerda[PIRATA_ESQUERDA],(PIRATA_WIDTH,PIRATA_HEIGHT))
#Direita
self.pirate_direita = {}
self.pirate_direita[PIRATA_DIREITA]=pygame.image.load(path.join(IMG_DIR,PIRATA_DIREITA))
self.pirate_direita[PIRATA_DIREITA]=pygame.transform.scale(self.pirate_direita[PIRATA_DIREITA],(PIRATA_WIDTH,PIRATA_HEIGHT))
#Cima
self.pirate_cima = {}
self.pirate_cima[PIRATA_CIMA]=pygame.image.load(path.join(IMG_DIR,PIRATA_CIMA))
self.pirate_cima[PIRATA_CIMA]=pygame.transform.scale(self.pirate_cima[PIRATA_CIMA],(PIRATA_WIDTH,PIRATA_HEIGHT))
#Baixo
self.pirate_baixo = {}
self.pirate_baixo[PIRATA_BAIXO]=pygame.image.load(path.join(IMG_DIR,PIRATA_BAIXO))
self.pirate_baixo[PIRATA_BAIXO]=pygame.transform.scale(self.pirate_baixo[PIRATA_BAIXO],(PIRATA_WIDTH,PIRATA_HEIGHT))
def new(self):
#Futuramente chamar last_spawn para mudança de fase
while self.init_load: # carrega o Load novamente, cada vez q mudar de fase
self.load_data()
self.init_load = False
self.last_respawn= pygame.time.get_ticks()
self.last_spawn = pygame.time.get_ticks()
#------Criando sprites------#
self.all_sprites = pygame.sprite.Group() #Grupo geral
self.ilhas = pygame.sprite.Group() #Obstaculo
self.crackens = pygame.sprite.Group() #crackens
self.cannonball = pygame.sprite.Group() #Bala de canhão
#Criando sprites dos navios em todas as direções:
self.pirates_l1=pygame.sprite.Group()
self.pirates_l2=pygame.sprite.Group()
self.pirates_r1=pygame.sprite.Group()
self.pirates_r2=pygame.sprite.Group()
self.pirates_t1=pygame.sprite.Group()
self.pirates_t2=pygame.sprite.Group()
self.pirates_b1=pygame.sprite.Group()
self.pirates_b2=pygame.sprite.Group()
#criando sprites dos morteiros
self.cannon1=pygame.sprite.Group()
self.cannon2=pygame.sprite.Group()
self.cannon3=pygame.sprite.Group()
self.cannon4=pygame.sprite.Group()
#Criando sprites de itens:
self.Meat1= pygame.sprite.Group()
self.Meat2= pygame.sprite.Group()
self.Meat3= pygame.sprite.Group()
self.Meat4= pygame.sprite.Group()
self.Rum1= pygame.sprite.Group()
self.Rum2= pygame.sprite.Group()
self.Rum3= pygame.sprite.Group()
self.Rum4= pygame.sprite.Group()
self.tesouro1= pygame.sprite.Group()
self.tesouro2= pygame.sprite.Group()
self.tesouro3= pygame.sprite.Group()
self.tesouro4= pygame.sprite.Group()
#------Criando objetos no mapa------#
for tile_object in self.map.tmxdata.objects:
#Spawna o Navio no mapa
if tile_object.name == 'boat':
self.boat=Boat(self,tile_object.x, tile_object.y)
#Spawna o Cracken no mapa
if tile_object.name == 'cracken':
Cracken(self, tile_object.x, tile_object.y)
#Gera os limites da ilha
if tile_object.name == 'Ilha':
Obstacle(self, tile_object.x, tile_object.y,
tile_object.width, tile_object.height)
#Gera os obstáculos
if tile_object.name == 'objetos':
Obstacle(self, tile_object.x, tile_object.y,
tile_object.width, tile_object.height)
#Spawna navios inimigos em suas respectivas posições
if tile_object.name == 'pirate_l1':
Pirata_esquerda(self,self.pirate_esquerda[PIRATA_ESQUERDA], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_l2':
Pirata_esquerda(self,self.pirate_esquerda[PIRATA_ESQUERDA], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_r1':
Pirata_direita(self,self.pirate_direita[PIRATA_DIREITA], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_r2':
Pirata_direita(self,self.pirate_direita[PIRATA_DIREITA], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_t1':
Pirata_baixo(self,self.pirate_baixo[PIRATA_BAIXO], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_t2':
Pirata_baixo(self,self.pirate_baixo[PIRATA_BAIXO], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_b1':
Pirata_cima(self,self.pirate_cima[PIRATA_CIMA], tile_object.x, tile_object.y)
if tile_object.name == 'pirate_b2':
Pirata_cima(self,self.pirate_cima[PIRATA_CIMA], tile_object.x, tile_object.y)
#Spawnando item Carne:
if tile_object.name == 'Meat1':
Carne(self,tile_object.x, tile_object.y)
if tile_object.name == 'Meat2':
Carne(self,tile_object.x, tile_object.y)
if tile_object.name == 'Meat3':
Carne(self,tile_object.x, tile_object.y)
if tile_object.name == 'Meat4':
Carne(self,tile_object.x, tile_object.y)
#Spawnando item Rum:
if tile_object.name == 'Rum1':
Rum(self,tile_object.x, tile_object.y)
if tile_object.name in 'Rum2':
Rum(self,tile_object.x, tile_object.y)
if tile_object.name in 'Rum3':
Rum(self,tile_object.x, tile_object.y)
if tile_object.name in 'Rum4':
Rum(self,tile_object.x, tile_object.y)
#Spawnando item Tesouro:
if tile_object.name == 'Tesouro1':
Tesouro(self,tile_object.x,tile_object.y)
if tile_object.name == 'Tesouro2':
Tesouro(self,tile_object.x,tile_object.y)
if tile_object.name == 'Tesouro3':
Tesouro(self,tile_object.x,tile_object.y)
if tile_object.name == 'Tesouro4':
Tesouro(self,tile_object.x,tile_object.y)
#Spawnando a primeira bala de canhão
if tile_object.name== 'cannon3':
Cannonball2(self,vec(tile_object.x, tile_object.y),vec(-1,0))
#------Camera------#
self.camera = Camera(self.map.width, self.map.height)
self.draw_debug = False
def resnasce(self,string):
#Spawnando tesouros pelo mapa
if string == 'Tesouro':
aleatorio=choice([1,2,3,4]) #Sorteando posição de respawn
if aleatorio==1:
for sprite in self.tesouro1.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Tesouro1': #Posição 1
Tesouro(self,tile_object.x, tile_object.y)
if aleatorio==2:
for sprite in self.tesouro2.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Tesouro2': #Posição 2
Tesouro(self,tile_object.x, tile_object.y)
if aleatorio==3:
for sprite in self.tesouro3.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Tesouro3': #Posição 3
Tesouro(self,tile_object.x, tile_object.y)
if aleatorio==4:
for sprite in self.tesouro4.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Tesouro4': #Posição 4
Tesouro(self,tile_object.x, tile_object.y)
#Spawnando canhões nas ilhas
if string=='cannons':
channel2=self.sound_effects['canhao'].play()
sorteando=choice([1,2,3,4])
if sorteando ==1:
for sprite in self.cannon1.sprites():
self.last_respawn=pygame.time.get_ticks()
for tile_object in self.map.tmxdata.objects:
if tile_object.name== 'cannon1':
Cannonball2(self,vec(tile_object.x, tile_object.y),vec(0,-1))
if sorteando==2:
for sprite in self.cannon1.sprites():
self.last_respawn=pygame.time.get_ticks()
for tile_object in self.map.tmxdata.objects:
if tile_object.name== 'cannon2':
Cannonball2(self,vec(tile_object.x, tile_object.y),vec(1,0))
if sorteando==3:
for sprite in self.cannon1.sprites():
self.last_respawn=pygame.time.get_ticks()
for tile_object in self.map.tmxdata.objects:
if tile_object.name== 'cannon3':
Cannonball2(self,vec(tile_object.x, tile_object.y),vec(-1,0))
else:
for sprite in self.cannon1.sprites():
self.last_respawn=pygame.time.get_ticks()
for tile_object in self.map.tmxdata.objects:
if tile_object.name== 'cannon4':
Cannonball2(self,vec(tile_object.x, tile_object.y),vec(0,1))
#Respawn piratas esquerda:
if string == 'pirate_l':
aleatorio=choice([1,2]) #Sorteando posição
if aleatorio ==1:
for sprite in self.pirates_l1.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_l1':
Pirata_esquerda(self,self.pirate_esquerda[PIRATA_ESQUERDA], tile_object.x, tile_object.y)
else:
for sprite in self.pirates_l2.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_l2':
Pirata_esquerda(self,self.pirate_esquerda[PIRATA_ESQUERDA], tile_object.x, tile_object.y)
#Respawn piratas direita:
if string == 'pirate_r':
aleatorio=choice([1,2]) #Sorteando posição
if aleatorio==1:
for sprite in self.pirates_r1.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_r1':
Pirata_direita(self,self.pirate_direita[PIRATA_DIREITA], tile_object.x, tile_object.y)
else:
for sprite in self.pirates_r2.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_r2':
Pirata_direita(self,self.pirate_direita[PIRATA_DIREITA], tile_object.x, tile_object.y)
#Respawn piratas topo:
if string == 'pirate_t':
aleatorio=choice([1,2]) #Sorteando posição
if aleatorio==1:
for sprite in self.pirates_t1.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_t1':
Pirata_baixo(self,self.pirate_baixo[PIRATA_BAIXO], tile_object.x, tile_object.y)
else:
for sprite in self.pirates_t2.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_t2':
Pirata_baixo(self,self.pirate_baixo[PIRATA_BAIXO], tile_object.x, tile_object.y)
#Respawn piratas base:
if string == 'pirate_b':
aleatorio=choice([1,2]) #Sorteando posição
if aleatorio==1:
for sprite in self.pirates_b1.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_b1':
Pirata_cima(self,self.pirate_cima[PIRATA_CIMA], tile_object.x, tile_object.y)
else:
for sprite in self.pirates_b2.sprites():
sprite.kill()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'pirate_b2':
Pirata_cima(self,self.pirate_cima[PIRATA_CIMA], tile_object.x, tile_object.y)
#Respawn Carnes:
if string == 'Meat':
aleatorio=choice([1,2,3,4]) #Sorteando posição de respawn
if aleatorio==1:
for sprite in self.Meat1.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Meat1': #Posição 1
Carne(self,tile_object.x, tile_object.y)
if aleatorio==2:
for sprite in self.Meat2.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Meat2': #Posição 2
Carne(self,tile_object.x, tile_object.y)
if aleatorio==3:
for sprite in self.Meat3.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Meat3': #Posição 3
Carne(self,tile_object.x, tile_object.y)
if aleatorio==4:
for sprite in self.Meat2.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Meat4': #Posição 4
Carne(self,tile_object.x, tile_object.y)
#Respawn Rum:
if string == 'Rum':
aleatorio=choice([1,2,3,4]) #Sorteando posição de respawn
if aleatorio==1:
for sprite in self.Rum1.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Rum1': #Posição 1
Rum(self,tile_object.x, tile_object.y)
if aleatorio==2:
for sprite in self.Rum2.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Rum2': #Posição 2
Rum(self,tile_object.x, tile_object.y)
if aleatorio==3:
for sprite in self.Rum3.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Rum3': #Posição 3
Rum(self,tile_object.x, tile_object.y)
if aleatorio==4:
for sprite in self.Rum4.sprites():
sprite.kill()
self.last_spawn = pygame.time.get_ticks() #Pegando tempo de spawn
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'Rum4': #Posição 4
Rum(self,tile_object.x, tile_object.y)
def run(self):
#Iniciando o mixer de música
if self.Fase1==True:
self.level1.play(self.sound_effects['level1 theme'])
self.level2.stop()
if self.Fase2==True:
self.level1.stop()
self.level2.play(self.sound_effects['level2 theme'])
#------Loop do jogo------#
self.playing = True
while self.playing:
self.dt = self.clock.tick(FPS) / 1000.0 # fix for Python 2.x
self.events()
self.update()
self.draw()
#------Criando Tela inicial------#
def init_screen(self): # Exibe a tela inicial do jogo
self.passagem_imagem = 1
self.winner.stop()
self.game_over.stop()
self.abertura.play(self.sound_effects['abertura'])
running = True
self.last_update = pygame.time.get_ticks()
while running:
now = pygame.time.get_ticks()
delta_t=now - self.last_update
if delta_t>50:
delta_t=0
self.last_update=now
self.passagem_imagem+=1
if self.passagem_imagem>5:
self.passagem_imagem=1
self.clock.tick(30) #Contagem interna pra vinda dos crackens
# Fundo de tela
self.image = self.init_img['frame-{}.gif'.format(self.passagem_imagem)]
self.image_rect = self.image.get_rect()
self.image_rect.center = (WIDTH/2, self.image_rect.height/2)
self.screen.blit(self.image, self.image_rect)
# Desenha o texto
self.draw_text("ONE BIT", self.kenpixel_80, RED, WIDTH/2, HEIGHT/2 -20)
self.draw_text("THE GAME", self.kenpixel_40, RED, WIDTH/2, HEIGHT/2 + 40)
self.draw_text("PRESS 'ENTER' TO START LEVEL 1", self.romulus_30, BLACK, WIDTH/2, HEIGHT/2 + 120)
self.draw_text("LETICIA & MATHEUS PRESENTS", self.romulus_30, WHITE, WIDTH/2, HEIGHT/2 - 100)
self.draw_text("A DESIGN SOFTWARE's PROJECT", self.romulus_30, BLACK, WIDTH/2, HEIGHT/2 - 320)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_RETURN:
running = False
self.INSTRUCTION=True
self.Fase1 = False
self.Fase2=False
if event.key == pygame.K_ESCAPE:
self.quit()
self.abertura.stop()
#------Criando Tela de Instruções------#
def instruction_screen(self): # Exibe a tela de instruções do jogo
if self.INSTRUCTION :
self.passagem_imagemi = 1
self.abertura.play(self.sound_effects['abertura'])
running = True
self.last_updatei = pygame.time.get_ticks()
self.clock.tick(30) #Contagem interna pra vinda dos crackens
while running:
now = pygame.time.get_ticks()
delta_t=now - self.last_updatei
if delta_t>7000:
delta_t=0
self.last_updatei=now
self.passagem_imagemi+=1
if self.passagem_imagemi>2:
self.passagem_imagemi=1
# Imagem tela de instruções:
self.image = self.instruction_img['inst-{}.png'.format(self.passagem_imagemi)]
self.instruction_img['inst-{}.png'.format(self.passagem_imagemi)] = pygame.transform.scale(self.image, (WIDTH, HEIGHT))
self.image_rect = self.image.get_rect()
self.image_rect.center = (WIDTH/2, self.image_rect.height/2)
self.screen.blit(self.image, self.image_rect)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_RETURN:
running = False
self.INSTRUCTION=False
self.Fase1 = True
self.Fase2=False
if event.key == pygame.K_ESCAPE:
self.quit()
self.abertura.stop()
#------Criando Tela de transição de fase------#
def troca_de_fase_screen(self):
if self.TRANSITION:
self.passagem_imagem3=1
self.level1.stop()
self.transition.play(self.sound_effects['new_fase'])
running = True # Configura o looping
self.last_update3=pygame.time.get_ticks()
while running:
now=pygame.time.get_ticks()
delta=now-self.last_update3
if delta>50:
delta=0
self.last_update3=now
self.passagem_imagem3+=1
if self.passagem_imagem3>39:
self.passagem_imagem3=1
self.clock.tick(30) #Contagem interna pra vinda dos crackens
# Fundo de tela
self.image = self.transition_img['frae-{}.gif'.format(self.passagem_imagem3)]
self.image_rect = self.image.get_rect()
self.image_rect.center = (WIDTH/2, self.image_rect.height/2)
self.screen.blit(self.image, self.image_rect)
# Desenha o texto
self.draw_text("PRESS 'ENTER' TO START LEVEL 2", self.romulus_30, WHITE, WIDTH/2, HEIGHT/2 + 120)
self.draw_text("YOU DEFIED THE", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2 - 200)
self.draw_text("WRATH OF", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2 - 160)
self.draw_text("SEVEN SEAS...", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2 - 120)
self.draw_text("ARE YOU ", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2 - 80)
self.draw_text("READY FOR ", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2 - 40)
self.draw_text("THE CONSEQUENCES?", self.kenpixel_40, YELLOW, WIDTH/2, HEIGHT/2)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_RETURN:
running = False
self.Fase2 = True
self.Fase1 = False
if event.key == pygame.K_ESCAPE:
self.quit()
self.transition.stop()
#------Criando Tela de game_over------#
def game_over_screen(self): # Exibe a tela de derrota do jogo
if self.GAMEOVER:
self.passagem_imagem2=1
self.level1.stop()
self.level2.stop()
self.game_over.play(self.sound_effects['game over'])
running = True # Configura o looping
self.last_update2=pygame.time.get_ticks()
while running:
now=pygame.time.get_ticks()
delta=now-self.last_update2
if delta>100:
delta=0
self.last_update2=now
self.passagem_imagem2+=1
if self.passagem_imagem2>14:
self.passagem_imagem2=1
self.clock.tick(30) #Contagem interna pra vinda dos crackens
# Fundo de tela
self.image = self.game_over_img['fram-{}.gif'.format(self.passagem_imagem2)]
self.image_rect = self.image.get_rect()
self.image_rect.center = (WIDTH/2, self.image_rect.height/2)
self.screen.blit(self.image, self.image_rect)
# Desenha o texto
self.draw_text("GAME OVER", self.kenpixel_80, RED, WIDTH/2, HEIGHT/2 -20)
self.draw_text("PRESS 'ENTER' TO START AGAIN", self.romulus_30, BLACK, WIDTH/2, HEIGHT/2 + 120)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_RETURN:
running = False
self.GAMEOVER= False
self.playing=True
self.Fase1 = True
self.Fase2=False
jogo.__init__()
if event.key == pygame.K_ESCAPE:
self.quit()
self.game_over.stop()
#------Criando Tela Vencedor------#
def winner_screen(self): # Exibe a tela inicial do jogo
if self.WINNER:
self.passagem_imagem1 = 1
self.level2.stop()
self.winner.play(self.sound_effects['winner'])
running = True
self.last_update1 = pygame.time.get_ticks()
while running:
now =pygame.time.get_ticks()
delta_t1=now -self.last_update1
if delta_t1>100:
delta_t1=0
self.last_update1=now
self.passagem_imagem1+=1
if self.passagem_imagem1>14:
self.passagem_imagem1=1
self.clock.tick(30) # Contagem interna pra vinda dos crackens
# Fundo de tela
self.image = self.winner_img['mar-{}.gif'.format(self.passagem_imagem1)]
self.image_rect = self.image.get_rect()
self.image_rect.center = (WIDTH/2, self.image_rect.height/2)
self.screen.blit(self.image, self.image_rect)
# Desenha o texto
self.draw_text("PRESS 'ENTER' TO PLAY AGAIN", self.romulus_30, WHITE, WIDTH/2, HEIGHT/2 + 150)
self.draw_text("YOU WON!", self.kenpixel_80, BLACK, WIDTH/2, HEIGHT/2 - 160)
self.draw_text("YOU ARE THE", self.kenpixel_80, BLACK, WIDTH/2, HEIGHT/2 - 80)
self.draw_text("NEW KING OF", self.kenpixel_80, BLACK, WIDTH/2, HEIGHT/2 )
self.draw_text("THE PIRATES", self.kenpixel_80, BLACK, WIDTH/2, HEIGHT/2 +80)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
self.quit()
if event.type == pygame.KEYUP:
if event.key == pygame.K_RETURN:
running = False
self.GAMEOVER= False
self.playing=True
self.Fase1 = True
self.Fase2=False
jogo.__init__()
if event.key == pygame.K_ESCAPE:
self.quit()
self.winner.stop()
def update(self):
#Atualiza os elementos gráficos do jogo
self.all_sprites.update()
self.camera.update(self.boat)
#Se o jogador morre
if self.boat.health <= 0:
self.playing = False
self.GAMEOVER = True
#Acrescentar condição tempo para mudança de fase
#------Bala de canhão atinge jogador------#
lista_canhões=[self.cannon1,self.cannon2,self.cannon3,self.cannon4]
for m in lista_canhões:
hits = pygame.sprite.spritecollide(self.boat, m, True, collide_hit_rect)
for hit in hits:
self.boat.health -= CANNONBALL_DAMAGE2
self.boat.speed-=CANNONBALL_LESS_SPEED
hit.vel = vec(0, 0)
#------Cracken atinge jogador------#
hits = pygame.sprite.spritecollide(self.boat, self.crackens, False, collide_hit_rect)
for hit in hits:
channel2=self.sound_effects['cracken'].play()
self.boat.health -= CRACKEN_DAMAGE
hit.vel = vec(0, 0)
if self.boat.health <= 0:
self.GAMEOVER = True
self.playing = False
if self.GAMEOVER== True:
pygame.mixer.music.stop()
if hits:
self.boat.pos += vec(CRACKEN_KNOCKBACK, 0).rotate(-hits[0].rot)
#------Balas atingem Crackens------#
hits = pygame.sprite.groupcollide(self.crackens, self.cannonball, False, True)
for hit in hits:
hit.health -= CANNONBALL_DAMAGE
hit.vel = vec(0, 0)
#------Balas atigem piratas--------#
#Criando lista para grupos de piratas:
lista=[self.pirates_l1,self.pirates_l2,self.pirates_r1,self.pirates_r2,self.pirates_t1,self.pirates_t2,self.pirates_b1,self.pirates_b2]
for k in lista:
hits = pygame.sprite.groupcollide(k, self.cannonball, False, True) #Colisão bala com pirata
for hit in hits: # Verificando se houve colisão
hit.health -= CANNONBALL_DAMAGE
hit.vel = vec(0, 0)
#------Piratas atingem navio------#
#Piratas Esquerda:
hits = pygame.sprite.spritecollide(self.boat, self.pirates_l1, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(-MOB_KNOCKBACK, 0)
hits = pygame.sprite.spritecollide(self.boat, self.pirates_l2, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(-MOB_KNOCKBACK, 0)
#Piratas Direita:
hits = pygame.sprite.spritecollide(self.boat, self.pirates_r1, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(MOB_KNOCKBACK, 0)
hits = pygame.sprite.spritecollide(self.boat, self.pirates_r2, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(MOB_KNOCKBACK, 0)
#Piratas Cima:
hits = pygame.sprite.spritecollide(self.boat, self.pirates_b1, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(0,-MOB_KNOCKBACK)
hits = pygame.sprite.spritecollide(self.boat, self.pirates_b2, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(0,-MOB_KNOCKBACK)
#Piratas Baixo:
hits = pygame.sprite.spritecollide(self.boat, self.pirates_t1, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(0,MOB_KNOCKBACK)
hits = pygame.sprite.spritecollide(self.boat, self.pirates_t2, False, collide_hit_rect) #Colisão barco pirata
for hit in hits: #Verificando se houve colisão
self.boat.health -= PIRATA_DAMAGE
hit.vel = vec(0, 0)
if hits:
hit.health -= CANNONBALL_DAMAGE/5
self.boat.pos += vec(0,MOB_KNOCKBACK)
#------Player colide com Itens------#
lista_tesouro=[self.tesouro1, self.tesouro2, self.tesouro3, self.tesouro4]
for i in lista_tesouro:
hits = pygame.sprite.spritecollide (self.boat, i, False, pygame.sprite.collide_mask)
for hit in hits:
channel2=self.sound_effects['pirata2'].play()
self.xp_total+=TESOURO_XP
hit.kill()
self.resnasce('Tesouro')
#Criando lista para armazenar carne
lista_carne=[self.Meat1, self.Meat2, self.Meat3, self.Meat4]
for i in lista_carne:
hits = pygame.sprite.spritecollide (self.boat, i, False, pygame.sprite.collide_mask)
for hit in hits:
channel2=self.sound_effects['pirata4'].play()
self.boat.health+= CARNE_LIFE
self.xp_total+=CARNE_XP
hit.kill()
self.resnasce('Meat')
#Criando lista para armazenar bebida
lista_rum=[self.Rum1, self.Rum2, self.Rum3, self.Rum4]
for i in lista_rum:
hits = pygame.sprite.spritecollide (self.boat, i, False, pygame.sprite.collide_mask)
for hit in hits:
channel2=self.sound_effects['pirata3'].play()
self.propg+=5
hit.kill()
self.resnasce('Rum')
def proxima_fase(self):
if self.passa_fase== 0: # se estava na fase inicial
self.Fase1 = False
self.playing = False
self.TRANSITION=True
self.init_load = True
self.xp_total=0
self.boat.health=BOAT_HEALTH
self.boat.speed= BOAT_SPEED
self.propg= CANNONBALL_PROPG
self.passa_fase= 1
elif self.passa_fase== 1:
self.Fase2 = False
self.playing = False
self.Fase1 = False
self.xp_total=0
self.passa_fase= 0
self.init_load = False
self.TRANSITION=False
self.GAMEOVER = False
self.WINNER = True
def draw_grid(self):
#Desenhando linhas (grid) na tela
for x in range(0, WIDTH, TILESIZE):
pygame.draw.line(self.screen, LIGHTGREY, (x, 0), (x, HEIGHT))
for y in range(0, HEIGHT, TILESIZE):
pygame.draw.line(self.screen, LIGHTGREY, (0, y), (WIDTH, y))
def draw(self):
#------Desenhando mapa na tela------#
pygame.display.set_caption("{:.2f}".format(self.clock.get_fps()))
self.screen.blit(self.map_img, self.camera.apply_rect(self.map_rect))
#------Desenhando a barra de vida dos personagens------#
for sprite in self.all_sprites:
if isinstance(sprite, Cracken):
sprite.draw_health()
self.screen.blit(sprite.image, self.camera.apply(sprite))
if isinstance(sprite,Pirata_esquerda):
sprite.draw_health()
self.screen.blit(sprite.image, self.camera.apply(sprite))
if isinstance(sprite, Pirata_direita):
sprite.draw_health()
self.screen.blit(sprite.image, self.camera.apply(sprite))
if isinstance(sprite, Pirata_baixo):
sprite.draw_health()
self.screen.blit(sprite.image, self.camera.apply(sprite))
if isinstance(sprite, Pirata_cima):
sprite.draw_health()
self.screen.blit(sprite.image, self.camera.apply(sprite))
if self.draw_debug:
pygame.draw.rect(self.screen, CYAN, self.camera.apply_rect(sprite.hit_rect), 1)