25
25
ROWS = 16
26
26
COLS = 150
27
27
TILE_SIZE = SCREEN_HEIGHT // ROWS
28
- TILE_TYPES = 21
28
+ TILE_TYPES = 22
29
29
MAX_LEVELS = 6
30
30
screen_scroll = 0
31
31
bg_scroll = 0
93
93
'Health' : health_box_img ,
94
94
'Ammo' : ammo_box_img ,
95
95
'Grenade' : grenade_box_img ,
96
+ 'Molotov' :molotov_box_img
96
97
}
97
98
98
99
# COLORS
117
118
MOLOTOVSOUND = pygame .mixer .Sound ('audio/molotov.wav' )
118
119
MOLOTOVSOUND .set_volume (1 )
119
120
121
+ MOLOTOVBR = pygame .mixer .Sound ('audio/molotovbr.wav' )
122
+ MOLOTOVBR .set_volume (3 )
123
+
120
124
PICK = pygame .mixer .Sound ('audio/grenadepick.mp3' )
121
125
PICK .set_volume (2 )
122
126
@@ -178,7 +182,9 @@ def reset_level():
178
182
bullet_group .empty ()
179
183
zombiebullet_group .empty ()
180
184
grenade_group .empty ()
185
+ molotov_group .empty ()
181
186
explosion_group .empty ()
187
+ moloexplosion_group .empty ()
182
188
item_box_group .empty ()
183
189
decoration_group .empty ()
184
190
water_group .empty ()
@@ -194,7 +200,7 @@ def reset_level():
194
200
195
201
196
202
class Soldier (pygame .sprite .Sprite ):
197
- def __init__ (self , char_type , x , y , scale , speed , ammo , grenades ):
203
+ def __init__ (self , char_type , x , y , scale , speed , ammo , grenades , molotovs ):
198
204
pygame .sprite .Sprite .__init__ (self )
199
205
self .alive = True
200
206
self .char_type = char_type
@@ -203,7 +209,8 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
203
209
self .start_ammo = ammo
204
210
self .shoot_cooldown = 0
205
211
self .grenades = grenades
206
- self .health = 120
212
+ self .molotovs = molotovs
213
+ self .health = 125
207
214
self .max_health = self .health
208
215
self .direction = 1
209
216
self .vel_y = 0
@@ -220,7 +227,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
220
227
self .idling = False
221
228
self .idling_counter = 0
222
229
223
- # IRJD
230
+ # IDLE RUN JUMP DEATH FLIP
224
231
animation_types = ['Idle' , 'Run' , 'Jump' , 'Death' ]
225
232
for animation in animation_types :
226
233
# LIST
@@ -417,12 +424,12 @@ def process_data(self, data):
417
424
decoration_group .add (decoration )
418
425
elif tile == 15 : # create player
419
426
player = Soldier ('player' , x * TILE_SIZE ,
420
- y * TILE_SIZE , 1.65 , 5 , 20 , 5 )
427
+ y * TILE_SIZE , 1.65 , 5 , 20 , 5 , 5 )
421
428
health_bar = HealthBar (
422
429
10 , 10 , player .health , player .health )
423
430
elif tile == 16 : # create enemies
424
431
enemy = Soldier ('enemy' , x * TILE_SIZE ,
425
- y * TILE_SIZE , 1.65 , 2 , 20 , 0 )
432
+ y * TILE_SIZE , 1.65 , 2 , 20 , 0 , 0 )
426
433
enemy_group .add (enemy )
427
434
elif tile == 17 : # create ammo box
428
435
item_box = ItemBox (
@@ -507,6 +514,9 @@ def update(self):
507
514
elif self .item_type == 'Grenade' :
508
515
player .grenades += 1
509
516
PICK .play ()
517
+ elif self .item_type == 'Molotov' :
518
+ player .molotovs += 1
519
+ PICK .play ()
510
520
self .kill ()
511
521
512
522
@@ -565,7 +575,7 @@ def __init__(self, x, y, direction):
565
575
pygame .sprite .Sprite .__init__ (self )
566
576
self .timer = 100
567
577
self .vel_y = - 11
568
- self .speed = 7
578
+ self .speed = 6
569
579
self .image = grenade_img
570
580
self .rect = self .image .get_rect ()
571
581
self .rect .center = (x , y )
@@ -587,7 +597,7 @@ def update(self):
587
597
if self .vel_y < 0 :
588
598
self .vel_y = 0
589
599
dy = tile [1 ].bottom - self .rect .top
590
- # check if above the ground, i.e. falling
600
+ # Check height
591
601
elif self .vel_y >= 0 :
592
602
self .vel_y = 0
593
603
dy = tile [1 ].top - self .rect .bottom
@@ -596,7 +606,7 @@ def update(self):
596
606
self .rect .x += dx + screen_scroll
597
607
self .rect .y += dy
598
608
599
- # CD TIMER
609
+ # CD GRENADE TIMER
600
610
self .timer -= 0.95
601
611
if self .timer <= 0 :
602
612
self .kill ()
@@ -612,6 +622,90 @@ def update(self):
612
622
enemy .health -= 100
613
623
GRUNTING .play ()
614
624
625
+ class Molotov (pygame .sprite .Sprite ):
626
+ def __init__ (self , x , y , direction ):
627
+ pygame .sprite .Sprite .__init__ (self )
628
+ self .timer = 99
629
+ self .vel_y = - 10
630
+ self .speed = 11
631
+ self .image = molotov_img
632
+ self .rect = self .image .get_rect ()
633
+ self .rect .center = (x , y )
634
+ self .width = self .image .get_width ()
635
+ self .height = self .image .get_height ()
636
+ self .direction = direction
637
+
638
+ def update (self ):
639
+ self .vel_y += GRAVITY
640
+ dx = self .direction * self .speed
641
+ dy = self .vel_y
642
+
643
+ for tile in world .obstacle_list :
644
+ if tile [1 ].colliderect (self .rect .x + dx , self .rect .y , self .width , self .height ):
645
+ self .direction *= - 1
646
+ dx = self .direction * self .speed
647
+ if tile [1 ].colliderect (self .rect .x , self .rect .y + dy , self .width , self .height ):
648
+ self .speed = 0
649
+ if self .vel_y < 0 :
650
+ self .vel_y = 0
651
+ dy = tile [1 ].bottom - self .rect .top
652
+ # Check height
653
+ elif self .vel_y >= 0 :
654
+ self .vel_y = 0
655
+ dy = tile [1 ].top - self .rect .bottom
656
+
657
+ # MOLOTOV POS
658
+ self .rect .x += dx + screen_scroll
659
+ self .rect .y += dy
660
+
661
+ # CD MOLOTOV TIMER
662
+ self .timer -= 2
663
+ if self .timer <= 0 :
664
+ self .kill ()
665
+ moloexplosion = MoloExplosion (self .rect .x , self .rect .y , 1.5 )
666
+ moloexplosion_group .add (moloexplosion )
667
+ #DAMAGE
668
+ if abs (self .rect .centerx - player .rect .centerx ) < TILE_SIZE * 2 and \
669
+ abs (self .rect .centery - player .rect .centery ) < TILE_SIZE * 2 :
670
+ player .health -= 25
671
+ for enemy in enemy_group :
672
+ if abs (self .rect .centerx - enemy .rect .centerx ) < TILE_SIZE * 4 and \
673
+ abs (self .rect .centery - enemy .rect .centery ) < TILE_SIZE * 4 :
674
+ enemy .health -= 55
675
+ GRUNTING .play ()
676
+ GRUNTING .play ()
677
+ GRUNTING .play ()
678
+
679
+ class MoloExplosion (pygame .sprite .Sprite ):
680
+ def __init__ (self , x , y , scale ):
681
+ pygame .sprite .Sprite .__init__ (self )
682
+ self .images = []
683
+ MOLOTOVBR .play ()
684
+ for num in range (0 , 4 ):
685
+ img = pygame .image .load (
686
+ f'img/moloexplosion/Molo_{ num } .png' ).convert_alpha ()
687
+ img = pygame .transform .scale (
688
+ img , (int (img .get_width () * scale ), int (img .get_height () * scale )))
689
+ self .images .append (img ), MOLOTOVSOUND .play ()
690
+ self .frame_index = 0
691
+ self .image = self .images [self .frame_index ]
692
+ self .rect = self .image .get_rect ()
693
+ self .rect .center = (x , y )
694
+ self .counter = 0
695
+
696
+ def update (self ):
697
+ self .rect .x += screen_scroll
698
+
699
+ MOLOEXPLOSION_SPEED = 20
700
+ self .counter += 1
701
+
702
+ if self .counter >= MOLOEXPLOSION_SPEED :
703
+ self .counter = 0
704
+ self .frame_index += 1
705
+ if self .frame_index >= len (self .images ):
706
+ self .kill ()
707
+ else :
708
+ self .image = self .images [self .frame_index ]
615
709
616
710
class Explosion (pygame .sprite .Sprite ):
617
711
def __init__ (self , x , y , scale ):
@@ -662,7 +756,9 @@ def screenshot(obj, file_name, position, size):
662
756
bullet_group = pygame .sprite .Group ()
663
757
zombiebullet_group = pygame .sprite .Group ()
664
758
grenade_group = pygame .sprite .Group ()
759
+ molotov_group = pygame .sprite .Group ()
665
760
explosion_group = pygame .sprite .Group ()
761
+ moloexplosion_group = pygame .sprite .Group ()
666
762
item_box_group = pygame .sprite .Group ()
667
763
decoration_group = pygame .sprite .Group ()
668
764
water_group = pygame .sprite .Group ()
@@ -732,10 +828,10 @@ def screenshot(obj, file_name, position, size):
732
828
screen .blit (bullet_img , (90 + (x * 10 ), 40 ))
733
829
draw_text ('GRENADES: ' , font , WHITE , 10 , 60 )
734
830
for x in range (player .grenades ):
735
- screen .blit (grenade_img , (135 + (x * 15 ), 60 ))
831
+ screen .blit (grenade_img , (135 + (x * 15 ), 61 ))
736
832
draw_text ('MOLOTOVS: ' , font , WHITE , 10 , 85 )
737
- for x in range (player .grenades ):
738
- screen .blit (molotov_img , (140 + (x * 15 ), 90 ))
833
+ for x in range (player .molotovs ):
834
+ screen .blit (molotov_img , (140 + (x * 15 ), 75 ))
739
835
740
836
player .update ()
741
837
player .draw ()
@@ -749,6 +845,8 @@ def screenshot(obj, file_name, position, size):
749
845
bullet_group .update ()
750
846
grenade_group .update ()
751
847
explosion_group .update ()
848
+ moloexplosion_group .update ()
849
+ molotov_group .update ()
752
850
item_box_group .update ()
753
851
decoration_group .update ()
754
852
water_group .update ()
@@ -757,6 +855,8 @@ def screenshot(obj, file_name, position, size):
757
855
bullet_group .draw (screen )
758
856
grenade_group .draw (screen )
759
857
explosion_group .draw (screen )
858
+ moloexplosion_group .draw (screen )
859
+ molotov_group .draw (screen )
760
860
item_box_group .draw (screen )
761
861
decoration_group .draw (screen )
762
862
water_group .draw (screen )
@@ -771,6 +871,12 @@ def screenshot(obj, file_name, position, size):
771
871
grenade_group .add (grenade )
772
872
player .grenades -= 1
773
873
grenade_thrown = True
874
+ elif molotov and molotov_thrown == False and player .molotovs > 0 :
875
+ molotov = Molotov (player .rect .centerx + (0.5 * player .rect .size [0 ] * player .direction ),
876
+ player .rect .top , player .direction )
877
+ molotov_group .add (molotov )
878
+ player .molotovs -= 1
879
+ molotov_thrown = True
774
880
if player .in_air :
775
881
player .update_action (2 ) # 2: jump
776
882
elif moving_left or moving_right :
@@ -827,6 +933,8 @@ def screenshot(obj, file_name, position, size):
827
933
shoot = True
828
934
if event .key == pygame .K_q :
829
935
grenade = True
936
+ if event .key == pygame .K_e :
937
+ molotov = True
830
938
if event .key == pygame .K_w and player .alive :
831
939
player .jump = True
832
940
if event .key == pygame .K_ESCAPE :
@@ -859,6 +967,9 @@ def screenshot(obj, file_name, position, size):
859
967
if event .key == pygame .K_q :
860
968
grenade = False
861
969
grenade_thrown = False
970
+ if event .key == pygame .K_e :
971
+ molotov = False
972
+ molotov_thrown = False
862
973
863
974
864
975
pygame .display .update ()
0 commit comments