import pygame
pygame.init()
clock = pygame.time.Clock()
window = pygame.display.set_mode((1280, 720))
runned = True
color_bg = 0
pygame.display.set_caption('My Game')
icon = pygame.image.load('png/icon.png')
bg = pygame.image.load('png/bg.jpg')
pygame.display.set_icon(icon)
#Переменные
player_BIG = pygame.image.load('png/right/1.png')
player = pygame.transform.rotozoom(player_BIG, 0, 0.5)
right_2 = pygame.image.load('png/right/2.png')
right_3 = pygame.image.load('png/right/3.png')
right_4 = pygame.image.load('png/right/4.png')
right_2_SMALL = pygame.transform.rotozoom(right_2, 0, 0.5)
right_3_SMALL = pygame.transform.rotozoom(right_3, 0, 0.5)
right_4_SMALL = pygame.transform.rotozoom(right_4, 0, 0.5)
left_2 = pygame.image.load('png/left/2.png')
left_3 = pygame.image.load('png/left/3.png')
left_4 = pygame.image.load('png/left/4.png')
left_2_SMALL = pygame.transform.rotozoom(left_2, 0, 0.5)
left_3_SMALL = pygame.transform.rotozoom(left_3, 0, 0.5)
left_4_SMALL = pygame.transform.rotozoom(left_4, 0, 0.5)
player_cord = [250, 475]
player_anim_count = 1
key = pygame.key.get_pressed()
is_jump = False
jump_count = 7
#Функции
def MoveRight():
global player_anim_count
global player_cord
global player
player_cord[0] += 19
if player_anim_count == 4:
player_anim_count = 1
else:
player_anim_count += 1
if player_anim_count == 2:
player = right_2_SMALL
elif player_anim_count == 3:
player = right_3_SMALL
elif player_anim_count == 4:
player = right_4_SMALL
def MoveLeft():
global player_anim_count
global player_cord
global player
if player_anim_count == 4:
player_anim_count = 1
else:
player_anim_count += 1
if player_anim_count == 2:
player = left_2_SMALL
elif player_anim_count == 3:
player = left_3_SMALL
elif player_anim_count == 4:
player = left_4_SMALL
player_cord[0] -= 19
while runned:
window.blit(bg, (0,0))
window.blit(player, (player_cord))
pygame.display.update()
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
runned = False
pygame.quit()
if not is_jump:
if keys[pygame.K_SPACE]:
is_jump = True
else:
if jump_count >= -7:
if jump_count >0:
player_cord[1] -= (jump_count ** 2) / 2
else:
player_cord[1] += (jump_count ** 2) / 2
jump_count -= 1
else:
is_jump = False
jump_count = 7
if keys[pygame.K_d]:
MoveRight()
elif keys[pygame.K_a]:
MoveLeft()
clock.tick(20)