Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jankupczyk authored Apr 14, 2021
1 parent 02f0e1a commit 0ab5ebc
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 13 deletions.
135 changes: 123 additions & 12 deletions MAINGAME.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
ROWS = 16
COLS = 150
TILE_SIZE = SCREEN_HEIGHT // ROWS
TILE_TYPES = 21
TILE_TYPES = 22
MAX_LEVELS = 6
screen_scroll = 0
bg_scroll = 0
Expand Down Expand Up @@ -93,6 +93,7 @@
'Health' : health_box_img,
'Ammo' : ammo_box_img,
'Grenade' : grenade_box_img,
'Molotov' :molotov_box_img
}

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

MOLOTOVBR = pygame.mixer.Sound('audio/molotovbr.wav')
MOLOTOVBR.set_volume(3)

PICK = pygame.mixer.Sound('audio/grenadepick.mp3')
PICK.set_volume(2)

Expand Down Expand Up @@ -178,7 +182,9 @@ def reset_level():
bullet_group.empty()
zombiebullet_group.empty()
grenade_group.empty()
molotov_group.empty()
explosion_group.empty()
moloexplosion_group.empty()
item_box_group.empty()
decoration_group.empty()
water_group.empty()
Expand All @@ -194,7 +200,7 @@ def reset_level():


class Soldier(pygame.sprite.Sprite):
def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
def __init__(self, char_type, x, y, scale, speed, ammo, grenades, molotovs):
pygame.sprite.Sprite.__init__(self)
self.alive = True
self.char_type = char_type
Expand All @@ -203,7 +209,8 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
self.start_ammo = ammo
self.shoot_cooldown = 0
self.grenades = grenades
self.health = 120
self.molotovs = molotovs
self.health = 125
self.max_health = self.health
self.direction = 1
self.vel_y = 0
Expand All @@ -220,7 +227,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
self.idling = False
self.idling_counter = 0

# IRJD
# IDLE RUN JUMP DEATH FLIP
animation_types = ['Idle', 'Run', 'Jump', 'Death']
for animation in animation_types:
# LIST
Expand Down Expand Up @@ -417,12 +424,12 @@ def process_data(self, data):
decoration_group.add(decoration)
elif tile == 15: # create player
player = Soldier('player', x * TILE_SIZE,
y * TILE_SIZE, 1.65, 5, 20, 5)
y * TILE_SIZE, 1.65, 5, 20, 5, 5)
health_bar = HealthBar(
10, 10, player.health, player.health)
elif tile == 16: # create enemies
enemy = Soldier('enemy', x * TILE_SIZE,
y * TILE_SIZE, 1.65, 2, 20, 0)
y * TILE_SIZE, 1.65, 2, 20, 0, 0)
enemy_group.add(enemy)
elif tile == 17: # create ammo box
item_box = ItemBox(
Expand Down Expand Up @@ -507,6 +514,9 @@ def update(self):
elif self.item_type == 'Grenade':
player.grenades += 1
PICK.play()
elif self.item_type == 'Molotov':
player.molotovs += 1
PICK.play()
self.kill()


Expand Down Expand Up @@ -565,7 +575,7 @@ def __init__(self, x, y, direction):
pygame.sprite.Sprite.__init__(self)
self.timer = 100
self.vel_y = -11
self.speed = 7
self.speed = 6
self.image = grenade_img
self.rect = self.image.get_rect()
self.rect.center = (x, y)
Expand All @@ -587,7 +597,7 @@ def update(self):
if self.vel_y < 0:
self.vel_y = 0
dy = tile[1].bottom - self.rect.top
# check if above the ground, i.e. falling
# Check height
elif self.vel_y >= 0:
self.vel_y = 0
dy = tile[1].top - self.rect.bottom
Expand All @@ -596,7 +606,7 @@ def update(self):
self.rect.x += dx + screen_scroll
self.rect.y += dy

# CD TIMER
# CD GRENADE TIMER
self.timer -= 0.95
if self.timer <= 0:
self.kill()
Expand All @@ -612,6 +622,90 @@ def update(self):
enemy.health -= 100
GRUNTING.play()

class Molotov(pygame.sprite.Sprite):
def __init__(self, x, y, direction):
pygame.sprite.Sprite.__init__(self)
self.timer = 99
self.vel_y = -10
self.speed = 11
self.image = molotov_img
self.rect = self.image.get_rect()
self.rect.center = (x, y)
self.width = self.image.get_width()
self.height = self.image.get_height()
self.direction = direction

def update(self):
self.vel_y += GRAVITY
dx = self.direction * self.speed
dy = self.vel_y

for tile in world.obstacle_list:
if tile[1].colliderect(self.rect.x + dx, self.rect.y, self.width, self.height):
self.direction *= -1
dx = self.direction * self.speed
if tile[1].colliderect(self.rect.x, self.rect.y + dy, self.width, self.height):
self.speed = 0
if self.vel_y < 0:
self.vel_y = 0
dy = tile[1].bottom - self.rect.top
# Check height
elif self.vel_y >= 0:
self.vel_y = 0
dy = tile[1].top - self.rect.bottom

# MOLOTOV POS
self.rect.x += dx + screen_scroll
self.rect.y += dy

# CD MOLOTOV TIMER
self.timer -= 2
if self.timer <= 0:
self.kill()
moloexplosion = MoloExplosion(self.rect.x, self.rect.y, 1.5)
moloexplosion_group.add(moloexplosion)
#DAMAGE
if abs(self.rect.centerx - player.rect.centerx) < TILE_SIZE * 2 and \
abs(self.rect.centery - player.rect.centery) < TILE_SIZE * 2:
player.health -= 25
for enemy in enemy_group:
if abs(self.rect.centerx - enemy.rect.centerx) < TILE_SIZE * 4 and \
abs(self.rect.centery - enemy.rect.centery) < TILE_SIZE * 4:
enemy.health -= 55
GRUNTING.play()
GRUNTING.play()
GRUNTING.play()

class MoloExplosion(pygame.sprite.Sprite):
def __init__(self, x, y, scale):
pygame.sprite.Sprite.__init__(self)
self.images = []
MOLOTOVBR.play()
for num in range(0, 4):
img = pygame.image.load(
f'img/moloexplosion/Molo_{num}.png').convert_alpha()
img = pygame.transform.scale(
img, (int(img.get_width() * scale), int(img.get_height() * scale)))
self.images.append(img), MOLOTOVSOUND.play()
self.frame_index = 0
self.image = self.images[self.frame_index]
self.rect = self.image.get_rect()
self.rect.center = (x, y)
self.counter = 0

def update(self):
self.rect.x += screen_scroll

MOLOEXPLOSION_SPEED = 20
self.counter += 1

if self.counter >= MOLOEXPLOSION_SPEED:
self.counter = 0
self.frame_index += 1
if self.frame_index >= len(self.images):
self.kill()
else:
self.image = self.images[self.frame_index]

class Explosion(pygame.sprite.Sprite):
def __init__(self, x, y, scale):
Expand Down Expand Up @@ -662,7 +756,9 @@ def screenshot(obj, file_name, position, size):
bullet_group = pygame.sprite.Group()
zombiebullet_group = pygame.sprite.Group()
grenade_group = pygame.sprite.Group()
molotov_group = pygame.sprite.Group()
explosion_group = pygame.sprite.Group()
moloexplosion_group = pygame.sprite.Group()
item_box_group = pygame.sprite.Group()
decoration_group = pygame.sprite.Group()
water_group = pygame.sprite.Group()
Expand Down Expand Up @@ -732,10 +828,10 @@ def screenshot(obj, file_name, position, size):
screen.blit(bullet_img, (90 + (x * 10), 40))
draw_text('GRENADES: ', font, WHITE, 10, 60)
for x in range(player.grenades):
screen.blit(grenade_img, (135 + (x * 15), 60))
screen.blit(grenade_img, (135 + (x * 15), 61))
draw_text('MOLOTOVS: ', font, WHITE, 10, 85)
for x in range(player.grenades):
screen.blit(molotov_img, (140 + (x * 15), 90))
for x in range(player.molotovs):
screen.blit(molotov_img, (140 + (x * 15), 75))

player.update()
player.draw()
Expand All @@ -749,6 +845,8 @@ def screenshot(obj, file_name, position, size):
bullet_group.update()
grenade_group.update()
explosion_group.update()
moloexplosion_group.update()
molotov_group.update()
item_box_group.update()
decoration_group.update()
water_group.update()
Expand All @@ -757,6 +855,8 @@ def screenshot(obj, file_name, position, size):
bullet_group.draw(screen)
grenade_group.draw(screen)
explosion_group.draw(screen)
moloexplosion_group.draw(screen)
molotov_group.draw(screen)
item_box_group.draw(screen)
decoration_group.draw(screen)
water_group.draw(screen)
Expand All @@ -771,6 +871,12 @@ def screenshot(obj, file_name, position, size):
grenade_group.add(grenade)
player.grenades -= 1
grenade_thrown = True
elif molotov and molotov_thrown == False and player.molotovs > 0:
molotov = Molotov(player.rect.centerx + (0.5 * player.rect.size[0] * player.direction),
player.rect.top, player.direction)
molotov_group.add(molotov)
player.molotovs -= 1
molotov_thrown = True
if player.in_air:
player.update_action(2) # 2: jump
elif moving_left or moving_right:
Expand Down Expand Up @@ -827,6 +933,8 @@ def screenshot(obj, file_name, position, size):
shoot = True
if event.key == pygame.K_q:
grenade = True
if event.key == pygame.K_e:
molotov = True
if event.key == pygame.K_w and player.alive:
player.jump = True
if event.key == pygame.K_ESCAPE:
Expand Down Expand Up @@ -859,6 +967,9 @@ def screenshot(obj, file_name, position, size):
if event.key == pygame.K_q:
grenade = False
grenade_thrown = False
if event.key == pygame.K_e:
molotov = False
molotov_thrown = False


pygame.display.update()
Expand Down
2 changes: 1 addition & 1 deletion tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
enemy

0 comments on commit 0ab5ebc

Please sign in to comment.