Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- #Display resolution
- pygame.init()
- win = pygame.display.set_mode((500, 500))
- #Game name
- pygame.display.set_caption('BAD GUY')
- #Player
- x = 250
- y = 475
- width = 20
- height = 25
- speed = 20
- #To close the game
- run = True
- while run:
- pygame.time.delay(100)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- #Move rigth/left
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT] and x > 5:
- x -= speed
- if keys[pygame.K_RIGHT] and x < 500 -width - 5:
- x += speed
- #Jump
- if not(isJump):
- if keys[pygame.K_UP] and y > 5:
- y -= speed
- if keys[pygame.K_DOWN] and y < 500 -width - 5:
- y += speed
- if keys[pygame.K_SPACE]:
- isJump = True
- else:
- if jumpCount >= 10:
- if jumpCount < 0:
- y += (jumpCount ** 2) / 2
- y -= (jumpCount ** 2) / 2
- jumpCount -= 1
- else:
- isJump = False
- jumpCount = 10
- #Background and hero color
- win.fill((0,0,0))
- pygame.draw.rect(win, (0,0,255), (x, y, width, height))
- pygame.display.update()
- #Exit game
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement