suspensed_

Untitled

May 13th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. import pygame as pg
  2.  
  3. pg.init()
  4. win = pg.display.set_mode((1440, 800))
  5. pg.display.set_caption('Cubes Game')
  6. clock = pg.time.Clock()
  7.  
  8. bg = pg.image.load('sprites/bg.png')
  9. walkRight = [pg.image.load('sprites/run1.png'),
  10. pg.image.load('sprites/run2.png'),
  11. pg.image.load('sprites/run3.png'),
  12. pg.image.load('sprites/run4.png'),
  13. pg.image.load('sprites/run5.png'),
  14. pg.image.load('sprites/run6.png'),
  15. pg.image.load('sprites/run7.png')]
  16.  
  17. walkLeft =[pg.image.load('sprites/lrun1.png'),
  18. pg.image.load('sprites/lrun2.png'),
  19. pg.image.load('sprites/lrun3.png'),
  20. pg.image.load('sprites/lrun4.png'),
  21. pg.image.load('sprites/lrun5.png'),
  22. pg.image.load('sprites/lrun6.png'),
  23. pg.image.load('sprites/lrun7.png'),]
  24.  
  25. playerStand = [pg.image.load('sprites/idle1.png'),
  26. pg.image.load('sprites/idle2.png'),
  27. pg.image.load('sprites/idle3.png'),
  28. pg.image.load('sprites/idle4.png'),
  29. pg.image.load('sprites/idle5.png'),
  30. pg.image.load('sprites/idle6.png'),
  31. pg.image.load('sprites/idle7.png'),]
  32.  
  33. playerStandLeft = [pg.image.load('sprites/L_idle1.png'),
  34. pg.image.load('sprites/L_idle2.png'),
  35. pg.image.load('sprites/L_idle3.png'),
  36. pg.image.load('sprites/L_idle4.png'),
  37. pg.image.load('sprites/L_idle5.png'),
  38. pg.image.load('sprites/L_idle6.png'),
  39. pg.image.load('sprites/L_idle7.png'),]
  40.  
  41.  
  42. class player():
  43. def __init__(self, hp, x, y, widht, height, speed, isJump, jumpCount, left, right, stay, animCount, lastMove):
  44. self.hp = hp
  45. self.x = x
  46. self.y = y
  47. self.widht = widht
  48. self.height = height
  49. self.speed = speed
  50. self.isJump = isJump
  51. self.jumpCount = jumpCount
  52. self.left = left
  53. self.right = right
  54. self.stay = stay
  55. self.animCount = animCount
  56. self.lastMove = lastMove
  57.  
  58.  
  59. class shell():
  60. def __init__(self, x, y, radius, color, facing):
  61. self.x = x
  62. self.y = y
  63. self.radius = radius
  64. self.color = color
  65. self.facing = facing
  66. self.vel = 20 * facing
  67. def draw(self, win):
  68. pg.draw.circle(win, self.color, (self.x, self.y),self.radius)
  69.  
  70.  
  71. def drawWindow():
  72. global animCount
  73. win.blit(bg, (0,0))
  74. if animCount + 1 >= 35:
  75. animCount = 0
  76. if left:
  77. win.blit(walkLeft[animCount // 5], (x,y))
  78. animCount += 1
  79. elif right:
  80. win.blit(walkRight[animCount // 5], (x,y))
  81. animCount += 1
  82. elif stay:
  83. if lastMove == 'right':
  84. win.blit(playerStand [animCount // 5], (x,y))
  85. animCount += 1
  86. else:
  87. win.blit(playerStandLeft [animCount // 5], (x,y))
  88. animCount += 1
  89.  
  90. for bullet in bullets:
  91. bullet.draw(win)
  92.  
  93. pg.display.update()
  94.  
  95. run = True
  96. bullets = []
  97. while run:
  98. clock.tick(35)
  99. for event in pg.event.get():
  100. if event.type == pg.QUIT:
  101. run = False
  102. for bullet in bullets:
  103. if bullet.x < 1440 and bullet.x > 0:
  104. bullet.x += bullet.vel
  105. else:
  106. bullets.pop(bullets.index(bullet))
  107. keys = pg.key.get_pressed()
  108. if keys[pg.K_f]:
  109. if lastMove == "right":
  110. facing = 1
  111. else:
  112. facing = -1
  113. if len(bullets) < 5:
  114. bullets.append(shell(round(x + widht // 2), round(y + height // 2), 5, (255,0,0), facing))
  115. if keys[pg.K_LEFT] and x > 1 or keys[pg.K_a] and x > 1:
  116. x -= speed
  117. left = True
  118. right = False
  119. stay = False
  120. lastMove = 'left'
  121. elif keys[pg.K_RIGHT] and x < 1380 or keys[pg.K_d] and x < 1380:
  122. x += speed
  123. left = False
  124. right = True
  125. stay = False
  126. lastMove = 'right'
  127. else:
  128. left = False
  129. right = False
  130. stay = True
  131.  
  132. if not(isJump):
  133. if keys[pg.K_SPACE]:
  134. isJump = True
  135. else:
  136. if jumpCount >= -10:
  137. if jumpCount < 0:
  138. y += (jumpCount ** 2) / 2
  139. else:
  140. y -= (jumpCount ** 2) / 2
  141.  
  142. jumpCount -= 1
  143.  
  144. else:
  145. isJump = False
  146. jumpCount = 10
  147. drawWindow()
  148. pg.quit()
Add Comment
Please, Sign In to add comment