Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pydoc import importfile
- from turtle import width
- import pygame
- from pygame.locals import *
- from pygame import mixer
- pygame.init()
- width = 1000
- height = 500
- window = pygame.display.set_mode((width, height))
- bg_img = pygame.image.load('bg.jpg')
- bg_img = pygame.transform.scale(bg_img, (width, height))
- mixer.init()
- mixer.music.load('musicbg.wav')
- mixer.music.play()
- walkRight = [pygame.image.load('images_lab/R1.png'), pygame.image.load('images_lab/R2.png'),
- pygame.image.load(
- 'images_lab/R3.png'), pygame.image.load('images_lab/R4.png'),
- pygame.image.load(
- 'images_lab/R5.png'), pygame.image.load('images_lab/R6.png'),
- pygame.image.load(
- 'images_lab/R7.png'), pygame.image.load('images_lab/R8.png'),
- pygame.image.load('images_lab/R9.png')]
- walkLeft = [pygame.image.load('images_lab/L1.png'), pygame.image.load('images_lab/L2.png'),
- pygame.image.load(
- 'images_lab/L3.png'), pygame.image.load('images_lab/L4.png'),
- pygame.image.load(
- 'images_lab/L5.png'), pygame.image.load('images_lab/L6.png'),
- pygame.image.load(
- 'images_lab/L7.png'), pygame.image.load('images_lab/L8.png'),
- pygame.image.load('images_lab/L9.png')]
- char = pygame.image.load('images_lab/standing.png')
- x = 50
- y = 290
- person_width = 40
- person_height = 60
- vel = 5
- clock = pygame.time.Clock()
- isJump = False
- jumpCount = 10
- left = False
- right = False
- walkCount = 0
- def redrawGameWindow():
- global walkCount
- window.blit(bg_img, (0, 0))
- if walkCount + 1 >= 27:
- walkCount = 0
- if left:
- window.blit(walkLeft[walkCount//3], (x, y))
- walkCount += 1
- elif right:
- window.blit(walkRight[walkCount//3], (x, y))
- walkCount += 1
- else:
- window.blit(char, (x, y))
- walkCount = 0
- pygame.display.update()
- running = True
- while running:
- clock.tick(27)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT] and x > vel:
- x -= vel
- left = True
- right = False
- elif keys[pygame.K_RIGHT] and x < 760 - vel - person_width:
- x += vel
- left = False
- right = True
- else:
- left = False
- right = False
- walkCount = 0
- if not(isJump):
- if keys[pygame.K_SPACE]:
- isJump = True
- left = False
- right = False
- walkCount = 0
- else:
- if jumpCount >= -10:
- y -= (jumpCount * abs(jumpCount)) * 0.5
- jumpCount -= 1
- else:
- jumpCount = 10
- isJump = False
- redrawGameWindow()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement