Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import os
- # Intialize the pygame
- pygame.init()
- clock = pygame.time.Clock()
- # Color
- white = (255,255,255)
- black = (0,0,0)
- red = (255,0,0)
- green = (0, 255, 0)
- FPS = 27
- # Sprites
- # create the screen
- win = pygame.display.set_mode((1000,600))
- #Title and Icon
- pygame.display.set_caption("Mรคng")
- print(os.getcwd())
- bg = pygame.image.load('7536921_orig.png')
- char = [pygame.image.load('Idle__000.png'), pygame.image.load('Idle__001.png'), pygame.image.load('Idle__002.png'), pygame.image.load('Idle__003.png'), pygame.image.load('Idle__004.png'),pygame.image.load('Idle__005.png'),pygame.image.load('Idle__006.png'),pygame.image.load('Idle__007.png'),pygame.image.load('Idle__008.png'),pygame.image.load('Idle__009.png')]
- x = 50
- y = 50
- width = 64
- height = 64
- vel = 5
- isJump = False
- jumpCount = 0
- left = False
- right = False
- walkCount = 0
- def redrawGameWindow():
- global walkCount
- win.blit(bg, (0, 0))
- if walkCount + 1 >= 27:
- walkCount = 0
- if left:
- win.blit(walkLeft)[walkCount//3], (x,y)
- walkCount += 1
- elif right:
- win.blit(walkRight[walkCount//3], (x,y)
- walkCount +=1
- else:
- win.blit(char, (x, y))
- walkCount = 0
- pygame.display.update()
- run = True
- # Game Loop
- 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
- right = False
- left = True
- elif keys [pygame.K_RIGHT] and x < 1000 - vel - width:
- x += vel
- right = True
- left = False
- else:
- right = False
- left = False
- walkCount = 0
- if not (isJump) :
- if keys [pygame.K_SPACE] :
- isJump = True
- right = False
- left = False
- walkCount = 0
- else:
- if jumpCount >= -10:
- neg = 1
- if jumpCount < 0:
- neg = -1
- y -= (jumpCount ** 2) * 0.5 * neg
- jumpCount -= 1
- else:
- isJump = False
- jumpCount = 10
- win.fill((0,0,0))
- pygame.draw.rect(win, (128, 0, 128), (x, y, width, height))
- pygame.display.update()
- clock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement