Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. import pygame
  2. import os
  3.  
  4. # Intialize the pygame
  5. pygame.init()
  6.  
  7. clock = pygame.time.Clock()
  8.  
  9. # Color
  10. white = (255,255,255)
  11. black = (0,0,0)
  12. red = (255,0,0)
  13. green = (0, 255, 0)
  14.  
  15. FPS = 27
  16. # Sprites
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. # create the screen
  26. win = pygame.display.set_mode((1000,600))
  27.  
  28. #Title and Icon
  29. pygame.display.set_caption("Mรคng")
  30. print(os.getcwd())
  31.  
  32. bg = pygame.image.load('7536921_orig.png')
  33. 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')]
  34. x = 50
  35. y = 50
  36. width = 64
  37. height = 64
  38. vel = 5
  39. isJump = False
  40. jumpCount = 0
  41. left = False
  42. right = False
  43. walkCount = 0
  44.  
  45.  
  46. def redrawGameWindow():
  47. global walkCount
  48.  
  49. win.blit(bg, (0, 0))
  50. if walkCount + 1 >= 27:
  51. walkCount = 0
  52.  
  53.  
  54.  
  55. if left:
  56. win.blit(walkLeft)[walkCount//3], (x,y)
  57. walkCount += 1
  58. elif right:
  59. win.blit(walkRight[walkCount//3], (x,y)
  60.  
  61. walkCount +=1
  62. else:
  63. win.blit(char, (x, y))
  64. walkCount = 0
  65.  
  66. pygame.display.update()
  67.  
  68.  
  69.  
  70. run = True
  71.  
  72.  
  73.  
  74.  
  75. # Game Loop
  76. running = True
  77. while running:
  78. clock.tick(27)
  79.  
  80. for event in pygame.event.get():
  81. if event.type == pygame.QUIT:
  82. running = False
  83.  
  84. keys = pygame.key.get_pressed()
  85.  
  86. if keys [pygame.K_LEFT] and x > vel:
  87. x -= vel
  88. right = False
  89. left = True
  90. elif keys [pygame.K_RIGHT] and x < 1000 - vel - width:
  91. x += vel
  92. right = True
  93. left = False
  94. else:
  95. right = False
  96. left = False
  97. walkCount = 0
  98.  
  99. if not (isJump) :
  100. if keys [pygame.K_SPACE] :
  101. isJump = True
  102. right = False
  103. left = False
  104. walkCount = 0
  105. else:
  106. if jumpCount >= -10:
  107. neg = 1
  108. if jumpCount < 0:
  109. neg = -1
  110. y -= (jumpCount ** 2) * 0.5 * neg
  111. jumpCount -= 1
  112. else:
  113. isJump = False
  114. jumpCount = 10
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. win.fill((0,0,0))
  122. pygame.draw.rect(win, (128, 0, 128), (x, y, width, height))
  123. pygame.display.update()
  124. clock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement