Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import pygame
- from time import sleep
- print('Введите имя файла уровня:')
- lev = input()
- f = open(lev, 'r')
- jh, ih = 3, 3
- initial = 1
- vis = 0
- pole = []
- for i in f:
- t = i.split()
- vis += 1
- shir = len(t)
- pole.append(t)
- f.close()
- f, h = urllib.request.urlretrieve('https://yastatic.net/s3/lyceum/content/image/pygame/mar.png')
- img_pers = open(f)
- f, h = urllib.request.urlretrieve('https://yastatic.net/s3/lyceum/content/image/pygame/box.png')
- img_korobka = open(f)
- f, h = urllib.request.urlretrieve('https://yastatic.net/s3/lyceum/content/image/pygame/grass.png')
- img_trava = open(f)
- f, h = urllib.request.urlretrieve('https://i.ibb.co/c6bDyqC/fon.png')
- img_zastavka = open(f)
- if __name__ == '__main__':
- pygame.init()
- pygame.display.set_caption('Перемещение героя')
- x, y = 0, 0
- size = width, height = shir * 50, vis * 50
- sc = pygame.display.set_mode(size)
- img_pers = pygame.image.load(img_pers)
- img_korobka = pygame.image.load(img_korobka).convert()
- img_trava = pygame.image.load(img_trava).convert()
- img_zastavka = pygame.image.load(img_zastavka).convert()
- img_zastavka = pygame.transform.scale(img_zastavka, (shir * 50, vis * 50))
- sleep(1)
- sc.blit(img_zastavka, (0, 0))
- pygame.display.update()
- while True:
- for i in pygame.event.get():
- if i.type == pygame.QUIT:
- pygame.quit()
- elif i.type == pygame.KEYDOWN:
- if initial == 1:
- for ii in range(len(pole)):
- for j in range(len(pole[0])):
- if pole[ii][j] == 'X':
- sc.blit(img_korobka, (j * 50, ii * 50))
- elif pole[ii][j] == '0':
- sc.blit(img_trava, (j * 50, ii * 50))
- sc.blit(img_pers, (jh * 50 + 14, ih * 50 + 10))
- pygame.display.update()
- initial = 0
- if i.key == pygame.K_DOWN:
- if ih + 1 < len(pole):
- if pole[ih + 1][jh] == '0':
- sc.blit(img_trava, (jh * 50, ih * 50))
- ih += 1
- sc.blit(img_pers, (jh * 50 + 14, ih * 50 + 10))
- pygame.display.update()
- elif i.key == pygame.K_UP:
- if ih - 1 >= 0:
- if pole[ih - 1][jh] == '0':
- sc.blit(img_trava, (jh * 50, ih * 50))
- ih -= 1
- sc.blit(img_pers, (jh * 50 + 14, ih * 50 + 10))
- pygame.display.update()
- elif i.key == pygame.K_LEFT:
- if jh - 1 >= 0:
- if pole[ih][jh - 1] == '0':
- sc.blit(img_trava, (jh * 50, ih * 50))
- jh -= 1
- sc.blit(img_pers, (jh * 50 + 14, ih * 50 + 10))
- pygame.display.update()
- elif i.key == pygame.K_RIGHT:
- if jh + 1 < len(pole[0]):
- if pole[ih][jh + 1] == '0':
- sc.blit(img_trava, (jh * 50, ih * 50))
- jh += 1
- sc.blit(img_pers, (jh * 50 + 14, ih * 50 + 10))
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement