import pygame
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((1280, 748))
pygame.display.set_caption("Shedevro Pygame")
BG = pygame.image.load('images/BG.png').convert_alpha()
player = pygame.image.load('images/player_left/Walk_01.png').convert_alpha()
walk_left = [
pygame.image.load('images/player_left/Walk_01.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_02.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_03.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_04.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_05.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_06.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_07.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_08.png').convert_alpha(),
]
ghost = pygame.image.load('images/ghost.png').convert_alpha()
ghost_list_in_game = []
player_anim_count = 0
BG_x = 0
player_speed = 5
player_x = 500
player_y = 480
is_jump = False
jump_count = 7
BG_Sound = pygame.mixer.Sound('Sounds/BGM.mp3')
BG_Sound.play()
ghost_timer = pygame.USEREVENT + 1
pygame.time.set_timer(ghost_timer, 999999)
gameplay = True
running = True
while running:
keys = pygame.key.get_pressed()
screen.blit(BG, (BG_x, 0))
screen.blit(BG, (BG_x + 1280, 0))
if gameplay:
player_rect = walk_left[0].get_rect(topleft=(player_x, player_y))
if ghost_list_in_game:
for (i, el) in enumerate(ghost_list_in_game):
screen.blit(ghost, el)
el.x -= 20
if el.x < -10:
ghost_list_in_game.pop(i)
if player_rect.colliderect(el):
gameplay = False
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
is_jump = False
jump_count = 7
if player_anim_count == 3:
player_anim_count = 0
else:
player_anim_count += 1
BG_x -= 5
if BG_x == -618:
BG_x = 0
else:
screen.fill((0, 0, 0))
else:
screen.fill((87, 88, 89))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if event.type == ghost_timer:
ghost_list_in_game.append(ghost.get_rect(topleft=(1282, 480)))
clock.tick(10)
clock = pygame.time.Clock()
pygame.init()
screen = pygame.display.set_mode((1280, 748))
pygame.display.set_caption("Shedevro Pygame")
BG = pygame.image.load('images/BG.png').convert_alpha()
player = pygame.image.load('images/player_left/Walk_01.png').convert_alpha()
walk_left = [
pygame.image.load('images/player_left/Walk_01.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_02.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_03.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_04.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_05.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_06.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_07.png').convert_alpha(),
pygame.image.load('images/player_left/Walk_08.png').convert_alpha(),
]
ghost = pygame.image.load('images/ghost.png').convert_alpha()
ghost_list_in_game = []
player_anim_count = 0
BG_x = 0
player_speed = 5
player_x = 500
player_y = 480
is_jump = False
jump_count = 7
BG_Sound = pygame.mixer.Sound('Sounds/BGM.mp3')
BG_Sound.play()
ghost_timer = pygame.USEREVENT + 1
pygame.time.set_timer(ghost_timer, 999999)
gameplay = True
running = True
while running:
keys = pygame.key.get_pressed()
screen.blit(BG, (BG_x, 0))
screen.blit(BG, (BG_x + 1280, 0))
if gameplay:
player_rect = walk_left[0].get_rect(topleft=(player_x, player_y))
if ghost_list_in_game:
for (i, el) in enumerate(ghost_list_in_game):
screen.blit(ghost, el)
el.x -= 20
if el.x < -10:
ghost_list_in_game.pop(i)
if player_rect.colliderect(el):
gameplay = False
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
is_jump = False
jump_count = 7
if player_anim_count == 3:
player_anim_count = 0
else:
player_anim_count += 1
BG_x -= 5
if BG_x == -618:
BG_x = 0
else:
screen.fill((0, 0, 0))
else:
screen.fill((87, 88, 89))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
if event.type == ghost_timer:
ghost_list_in_game.append(ghost.get_rect(topleft=(1282, 480)))
clock.tick(10)