Game 1
Game 1
Game 1
init
wnd = pygame.display.set_mode((635, 360))
pygame.display.set_caption('Game №1')
icon = pygame.image.load('images/icon.png.png')
pygame.display.set_icon(icon)
enemy1_walk = [
pygame.image.load('images/Enemy1/enemy1_14.xcf'),
pygame.image.load('images/Enemy1/enemy1_3.xcf'),
pygame.image.load('images/Enemy1/enemy1_14.xcf')
]
walk_left = [
pygame.image.load('images/left/left13.xcf'),
pygame.image.load('images/left/left2.xcf'),
pygame.image.load('images/left/left13.xcf'),
pygame.image.load('images/left/left4.xcf')
]
walk_right = [
pygame.image.load('images/right/right13.xcf'),
pygame.image.load('images/right/right2.xcf'),
pygame.image.load('images/right/right13.xcf'),
pygame.image.load('images/right/right4.xcf')
]
enemy_list_in_game = []
gameplay = True
enemy1_anim_count = 0
enemy1_speed = 5
player_anim_count = 0
bg_x = 0
bg_sound = pygame.mixer.Sound('sounds/player_sound_walk.mp3')
bg_sound.play()
finish_sound = pygame.mixer.Sound('sounds/ops.mp3')
player_speed = 5
player_x = 150
player_y = 230
is_jump = False
jump_count = 7
enemy1_timer = pygame.USEREVENT + 1
pygame.time.set_timer(enemy1_timer, 7000)
running = True
while running:
wnd.blit(bg, (bg_x, 0))
wnd.blit(bg, (bg_x + 635, 0))
if gameplay:
player_rect = walk_left[0].get_rect(topleft=(player_x, player_y))
if enemy_list_in_game:
for (i, el) in enumerate(enemy_list_in_game):
wnd.blit(enemy1_walk[enemy1_anim_count], el)
el.x -= 5
if el.x < -50:
enemy_list_in_game.pop(i)
if enemy1_anim_count >= 3:
enemy1_anim_count = 0
else:
enemy1_anim_count += 1
keys = pygame.key.get_pressed()
if keys[pygame.K_d] and player_x <= 200:
wnd.blit(walk_right[player_anim_count], (player_x, player_y))
player_x += player_speed
elif keys[pygame.K_a] and player_x >= 50:
wnd.blit(walk_left[player_anim_count], (player_x, player_y))
player_x -= player_speed
else:
wnd.blit(walk_right[player_anim_count], (player_x, player_y))
if not is_jump:
if keys[pygame.K_SPACE]:
is_jump = True
else:
if jump_count >= -7:
if jump_count > 0:
player_y -= (jump_count ** 2) / 2
else:
player_y += (jump_count ** 2) / 2
jump_count -= 1
else:
is_jump = False
jump_count = 7
if player_anim_count == 3:
player_anim_count = 0
else:
player_anim_count += 1
if bg_x == -634:
bg_x = 0
else:
bg_x -= 2
if bullets:
for (i, el) in enumerate(bullets):
wnd.blit(bullet, (el.x, el.y))
el.x += 10
if el.x > 640:
bullets.pop(i)
if enemy_list_in_game:
for (index, enemy) in enumerate(enemy_list_in_game):
if el.colliderect(enemy):
enemy_list_in_game.pop(index)
bullets.pop(i)
else:
wnd.blit(bg, (bg_x, 0))
wnd.blit(Game_over, (120, 50))
wnd.blit(Tap_to_restart, Ttr_rect)
mouse = pygame.mouse.get_pos()
if Ttr_rect.collidepoint(mouse) and pygame.mouse.get_pressed()[0]:
gameplay = True
bg_sound.play()
player_x = 150
enemy_list_in_game.clear()
bullets.clear()
bullets_left = 5
pygame.display.update()
enemy_list_in_game.append(enemy1_walk[enemy1_anim_count].get_rect(topleft=(635,
255)))
if gameplay and keys[pygame.K_LSHIFT] and bullets_left > 0:
bullets.append(bullet.get_rect(topleft=(player_x + 40, player_y + 40)))
bullets_left -= 1
clock.tick(12)