Skip to content

Commit 0ab5ebc

Browse files
authored
Add files via upload
1 parent 02f0e1a commit 0ab5ebc

File tree

2 files changed

+124
-13
lines changed

2 files changed

+124
-13
lines changed

MAINGAME.py

Lines changed: 123 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ROWS = 16
2626
COLS = 150
2727
TILE_SIZE = SCREEN_HEIGHT // ROWS
28-
TILE_TYPES = 21
28+
TILE_TYPES = 22
2929
MAX_LEVELS = 6
3030
screen_scroll = 0
3131
bg_scroll = 0
@@ -93,6 +93,7 @@
9393
'Health' : health_box_img,
9494
'Ammo' : ammo_box_img,
9595
'Grenade' : grenade_box_img,
96+
'Molotov' :molotov_box_img
9697
}
9798

9899
# COLORS
@@ -117,6 +118,9 @@
117118
MOLOTOVSOUND = pygame.mixer.Sound('audio/molotov.wav')
118119
MOLOTOVSOUND.set_volume(1)
119120

121+
MOLOTOVBR = pygame.mixer.Sound('audio/molotovbr.wav')
122+
MOLOTOVBR.set_volume(3)
123+
120124
PICK = pygame.mixer.Sound('audio/grenadepick.mp3')
121125
PICK.set_volume(2)
122126

@@ -178,7 +182,9 @@ def reset_level():
178182
bullet_group.empty()
179183
zombiebullet_group.empty()
180184
grenade_group.empty()
185+
molotov_group.empty()
181186
explosion_group.empty()
187+
moloexplosion_group.empty()
182188
item_box_group.empty()
183189
decoration_group.empty()
184190
water_group.empty()
@@ -194,7 +200,7 @@ def reset_level():
194200

195201

196202
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):
198204
pygame.sprite.Sprite.__init__(self)
199205
self.alive = True
200206
self.char_type = char_type
@@ -203,7 +209,8 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
203209
self.start_ammo = ammo
204210
self.shoot_cooldown = 0
205211
self.grenades = grenades
206-
self.health = 120
212+
self.molotovs = molotovs
213+
self.health = 125
207214
self.max_health = self.health
208215
self.direction = 1
209216
self.vel_y = 0
@@ -220,7 +227,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
220227
self.idling = False
221228
self.idling_counter = 0
222229

223-
# IRJD
230+
# IDLE RUN JUMP DEATH FLIP
224231
animation_types = ['Idle', 'Run', 'Jump', 'Death']
225232
for animation in animation_types:
226233
# LIST
@@ -417,12 +424,12 @@ def process_data(self, data):
417424
decoration_group.add(decoration)
418425
elif tile == 15: # create player
419426
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)
421428
health_bar = HealthBar(
422429
10, 10, player.health, player.health)
423430
elif tile == 16: # create enemies
424431
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)
426433
enemy_group.add(enemy)
427434
elif tile == 17: # create ammo box
428435
item_box = ItemBox(
@@ -507,6 +514,9 @@ def update(self):
507514
elif self.item_type == 'Grenade':
508515
player.grenades += 1
509516
PICK.play()
517+
elif self.item_type == 'Molotov':
518+
player.molotovs += 1
519+
PICK.play()
510520
self.kill()
511521

512522

@@ -565,7 +575,7 @@ def __init__(self, x, y, direction):
565575
pygame.sprite.Sprite.__init__(self)
566576
self.timer = 100
567577
self.vel_y = -11
568-
self.speed = 7
578+
self.speed = 6
569579
self.image = grenade_img
570580
self.rect = self.image.get_rect()
571581
self.rect.center = (x, y)
@@ -587,7 +597,7 @@ def update(self):
587597
if self.vel_y < 0:
588598
self.vel_y = 0
589599
dy = tile[1].bottom - self.rect.top
590-
# check if above the ground, i.e. falling
600+
# Check height
591601
elif self.vel_y >= 0:
592602
self.vel_y = 0
593603
dy = tile[1].top - self.rect.bottom
@@ -596,7 +606,7 @@ def update(self):
596606
self.rect.x += dx + screen_scroll
597607
self.rect.y += dy
598608

599-
# CD TIMER
609+
# CD GRENADE TIMER
600610
self.timer -= 0.95
601611
if self.timer <= 0:
602612
self.kill()
@@ -612,6 +622,90 @@ def update(self):
612622
enemy.health -= 100
613623
GRUNTING.play()
614624

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]
615709

616710
class Explosion(pygame.sprite.Sprite):
617711
def __init__(self, x, y, scale):
@@ -662,7 +756,9 @@ def screenshot(obj, file_name, position, size):
662756
bullet_group = pygame.sprite.Group()
663757
zombiebullet_group = pygame.sprite.Group()
664758
grenade_group = pygame.sprite.Group()
759+
molotov_group = pygame.sprite.Group()
665760
explosion_group = pygame.sprite.Group()
761+
moloexplosion_group = pygame.sprite.Group()
666762
item_box_group = pygame.sprite.Group()
667763
decoration_group = pygame.sprite.Group()
668764
water_group = pygame.sprite.Group()
@@ -732,10 +828,10 @@ def screenshot(obj, file_name, position, size):
732828
screen.blit(bullet_img, (90 + (x * 10), 40))
733829
draw_text('GRENADES: ', font, WHITE, 10, 60)
734830
for x in range(player.grenades):
735-
screen.blit(grenade_img, (135 + (x * 15), 60))
831+
screen.blit(grenade_img, (135 + (x * 15), 61))
736832
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))
739835

740836
player.update()
741837
player.draw()
@@ -749,6 +845,8 @@ def screenshot(obj, file_name, position, size):
749845
bullet_group.update()
750846
grenade_group.update()
751847
explosion_group.update()
848+
moloexplosion_group.update()
849+
molotov_group.update()
752850
item_box_group.update()
753851
decoration_group.update()
754852
water_group.update()
@@ -757,6 +855,8 @@ def screenshot(obj, file_name, position, size):
757855
bullet_group.draw(screen)
758856
grenade_group.draw(screen)
759857
explosion_group.draw(screen)
858+
moloexplosion_group.draw(screen)
859+
molotov_group.draw(screen)
760860
item_box_group.draw(screen)
761861
decoration_group.draw(screen)
762862
water_group.draw(screen)
@@ -771,6 +871,12 @@ def screenshot(obj, file_name, position, size):
771871
grenade_group.add(grenade)
772872
player.grenades -= 1
773873
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
774880
if player.in_air:
775881
player.update_action(2) # 2: jump
776882
elif moving_left or moving_right:
@@ -827,6 +933,8 @@ def screenshot(obj, file_name, position, size):
827933
shoot = True
828934
if event.key == pygame.K_q:
829935
grenade = True
936+
if event.key == pygame.K_e:
937+
molotov = True
830938
if event.key == pygame.K_w and player.alive:
831939
player.jump = True
832940
if event.key == pygame.K_ESCAPE:
@@ -859,6 +967,9 @@ def screenshot(obj, file_name, position, size):
859967
if event.key == pygame.K_q:
860968
grenade = False
861969
grenade_thrown = False
970+
if event.key == pygame.K_e:
971+
molotov = False
972+
molotov_thrown = False
862973

863974

864975
pygame.display.update()

tempCodeRunnerFile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10
1+
enemy

0 commit comments

Comments
 (0)