I create the game "Mario." algorithm). It is only necessary that this all happen gradually, not immediately. Code:
import sys,time,pygame,random pygame.init() playSurface = pygame.display.set_mode((800, 600)) pygame.display.set_caption("Марио") fpsController = pygame.time.Clock() white = pygame.Color(255,255,255) x1 = 100 y1 = 300 mario = pygame.image.load("Mario.png") mario = pygame.transform.scale(mario,(50,60)) move_2 = False move_3 = False move_4 = False def music(): pygame.mixer.init() pygame.mixer.music.load('music.mp3') pygame.mixer.music.play(loops=-1) while True: playSurface.blit (mario, [x1, y1]) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit () sys.exit () elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit () sys.exit() if event.key == ord("m"): music() if event.key == ord ("n"): pygame.mixer.music.stop () if event.key == pygame.K_RIGHT: move_2 = True if event.key == pygame.K_SPACE: move_3 = True if event.key == pygame.K_LEFT: move_4 = True if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: move_2 = False if event.key == pygame.K_UP: move_3 = False if event.key == pygame.K_LEFT: move_4 = False # if event.type == pygame.MOUSEBUTTONDOWN: # x, y = event.pos if x1 >= 500: y1 += 5 if move_2 == True: x1 += 5 if x1 >= 730: x1 = 750 if move_3 == True: if move_4 == True: x1 -= 5 if x1 < 15: x1 = 15 pygame.display.flip() playSurface.fill(white) fpsController.tick(15)
// Тут вам надо написать код, there will be no one for you who will not write anything, this is for you to freelance forums. - Igor Igoryanych