Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import pygame as pg
  2. pg.init()
  3. winHeight=600
  4. winWidth = 1020
  5. x=10
  6. y=560
  7. size = 37
  8. bg = pg.image.load("scenes/Background/bg.png")
  9. walkList = [pg.image.load("player/Run/run-00.png"),pg.image.load("player/Run/run-01.png"),pg.image.load("player/Run/run-02.png"),pg.image.load("player/Run/run-03.png"),pg.image.load("player/Run/run-04.png"),pg.image.load("player/Run/run-05.png")]
  10. char = pg.image.load("player/idle/idle-00.png")
  11. vel = 3
  12. win = pg.display.set_mode((winWidth,winHeight))
  13. pg.display.set_caption("SMAS 'EM By IKEA KID")
  14. run = True
  15. jumCount = 7
  16. isJump = False
  17. AnimationCounter = 0
  18.  
  19. def Animation():
  20. direction = win.blit(walkList[AnimationCounter], (x, y))
  21. if pg.event == pg.K_LEFT:
  22. return direction
  23. elif pg.event == pg.K_RIGHT:
  24. direction=pg.transform.flip(direction,False,True)
  25. return direction
  26. def RedrawWindow():
  27. global AnimationCounter
  28. win.blit(bg, (0,0))
  29.  
  30. if AnimationCounter +1 >= 6:
  31. AnimationCounter = 0
  32. if walk:
  33. Animation()
  34. AnimationCounter += 1
  35. elif not walk:
  36. win.blit(char,(x,y))
  37.  
  38. pg.display.update()
  39.  
  40. while run:
  41. pg.time.delay(15)
  42. for event in pg.event.get():
  43. if event.type == pg.QUIT:
  44. run = False
  45. keys = pg.key.get_pressed()
  46.  
  47. if keys[pg.K_LEFT] and x > vel:
  48. x -= vel
  49. walk = True
  50. elif keys[pg.K_RIGHT] and x+size < winWidth-vel:
  51. x += vel
  52. walk = True
  53. flip = True
  54. else:
  55. AnimationCounter = 0
  56. walk = False
  57. if not(isJump):
  58. if keys[pg.K_SPACE]:
  59. isJump = True
  60. else:
  61.  
  62. if jumCount >= -7:
  63. neg = 1
  64. if jumCount < 0:
  65. neg = -1
  66. y -= (jumCount**2)*0.5*neg
  67. jumCount-=0.5
  68. else:
  69. isJump = False
  70. jumCount = 7
  71.  
  72. RedrawWindow()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement