Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
  155. 155
  156. 156
  157. 157
  158. 158
  159. 159
  160. 160
  161. 161
  162. 162
  163. 163
  164. 164
  165. 165
  166. 166
  167. 167
  168. 168
  169. 169
  170. 170
  171. 171
  172. 172
  173. 173
  174. 174
  175. 175
  176. 176
  177. 177
  178. 178
  179. 179
  180. 180
  181. 181
  182. 182
  183. 183
  184. 184
  185. 185
  186. 186
  187. 187
  188. 188
  189. 189
  190. 190
  191. 191
  192. 192
  193. 193
  194. 194
  195. 195
  196. 196
  197. 197
  198. 198
  199. 199
  200. 200
  201.  
  202. import pygame
  203. import random
  204.  
  205. pygame.mixer.pre_init(44100, -16, 1, 512)
  206.  
  207. pygame.init()
  208.  
  209. scrW = 800
  210. scrH = 600
  211.  
  212. win = pygame.display.set_mode((scrW, scrH))
  213.  
  214. pygame.display.set_caption("Animals")
  215.  
  216. bg = pygame.image.load('images/grassland11.png')
  217.  
  218. walkLeft = [pygame.image.load('images/sprites/animals/animals_13.png'),
  219. pygame.image.load('images/sprites/animals/animals_14.png'),
  220. pygame.image.load('images/sprites/animals/animals_15.png'),
  221. pygame.image.load('images/sprites/animals/animals_14.png')]
  222. walkRight = [pygame.image.load('images/sprites/animals/animals_25.png'),
  223. pygame.image.load('images/sprites/animals/animals_26.png'),
  224. pygame.image.load('images/sprites/animals/animals_27.png'),
  225. pygame.image.load('images/sprites/animals/animals_26.png')]
  226. walkUp = [pygame.image.load('images/sprites/animals/animals_37.png'),
  227. pygame.image.load('images/sprites/animals/animals_39.png'),
  228. pygame.image.load('images/sprites/animals/animals_37.png'),
  229. pygame.image.load('images/sprites/animals/animals_39.png')]
  230. walkDown = [pygame.image.load('images/sprites/animals/animals_01.png'),
  231. pygame.image.load('images/sprites/animals/animals_03.png'),
  232. pygame.image.load('images/sprites/animals/animals_01.png'),
  233. pygame.image.load('images/sprites/animals/animals_03.png')]
  234. dogcookie = [pygame.image.load('images/dogc.png'), pygame.image.load('images/dogc2.png'),
  235. pygame.image.load('images/dogc3.png'), pygame.image.load('images/dogc4.png')]
  236.  
  237. clock = pygame.time.Clock()
  238.  
  239. score = 0
  240.  
  241. pygame.mixer.music.load('sound/nintendogs.mp3')
  242. pygame.mixer.music.play(-1)
  243. font = pygame.font.SysFont("comicsans", 40, True)
  244. sound_bis = pygame.mixer.Sound("sound/coin.wav")
  245. pygame.mixer.Sound.set_volume(sound_bis, 0.25)
  246.  
  247.  
  248. class Player:
  249.  
  250. def __init__(self, x, y, width, height):
  251.  
  252. self.x = x
  253. self.y = y
  254. self.width = int(width)
  255. self.height = int(height)
  256. self.vel = 5
  257. self.left = False
  258. self.right = False
  259. self.up = False
  260. self.down = False
  261. self.walkCount = 0
  262. self.mana = 100
  263.  
  264. def draw(self):
  265. if self.walkCount == 15:
  266. self.walkCount = 0
  267.  
  268. if self.left:
  269. win.blit(walkLeft[self.walkCount // 4], (self.x, self.y))
  270. self.walkCount += 1
  271. elif self.right:
  272. win.blit(walkRight[self.walkCount // 4], (self.x, self.y))
  273. self.walkCount += 1
  274. elif self.up:
  275. win.blit(walkUp[self.walkCount // 8], (self.x, self.y))
  276. self.walkCount += 1
  277. else:
  278. win.blit(walkDown[self.walkCount // 8], (self.x, self.y))
  279. self.walkCount += 1
  280.  
  281. pygame.draw.rect(win, (0, 0, 255), (10, 545, self.mana, 10))
  282.  
  283.  
  284. class Objects:
  285.  
  286. def __init__(self):
  287. self.rng_x = random.randint(2, 18)
  288. self.rng_y = random.randint(2, 13)
  289. self.walkCount = 0
  290.  
  291. def draw(self):
  292. if self.walkCount == 19:
  293. self.walkCount = 0
  294. win.blit(dogcookie[self.walkCount // 5], (self.rng_x * 40, self.rng_y * 40))
  295. self.walkCount += 1
  296.  
  297.  
  298. def redraw():
  299. win.blit(bg, (0, 0))
  300.  
  301. text = font.render("Score: " + str(score), 1, (255, 255, 255))
  302. win.blit(text, (10, 565))
  303. dog.draw()
  304. biscoito.draw()
  305.  
  306. pygame.display.update()
  307.  
  308.  
  309. # main
  310. dog = Player(200, 200, 64, 64)
  311. biscoito = Objects()
  312. run = True
  313. while run:
  314.  
  315. clock.tick(30)
  316.  
  317. for event in pygame.event.get():
  318. if event.type == pygame.QUIT:
  319. run = False
  320.  
  321. keys = pygame.key.get_pressed() # KEYS
  322.  
  323. if keys[pygame.K_LEFT] and dog.x >= dog.vel:
  324. dog.x -= dog.vel
  325. dog.left = True
  326. dog.right = False
  327. dog.up = False
  328. dog.down = False
  329.  
  330. if keys[pygame.K_LEFT] and dog.x < dog.vel:
  331. dog.x = 0
  332. dog.left = True
  333. dog.right = False
  334. dog.up = False
  335. dog.down = False
  336.  
  337. elif keys[pygame.K_RIGHT] and dog.x <= scrW - dog.width - dog.vel:
  338. dog.x += dog.vel
  339. dog.right = True
  340. dog.left = False
  341. dog.up = False
  342. dog.down = False
  343.  
  344. if keys[pygame.K_RIGHT] and dog.x > scrW - dog.width - dog.vel:
  345. dog.x = scrW - dog.width
  346. dog.right = True
  347. dog.left = False
  348. dog.down = False
  349. dog.up = False
  350. elif keys[pygame.K_UP] and dog.y >= dog.vel:
  351. dog.y -= dog.vel
  352. dog.up = True
  353. dog.down = False
  354. dog.left = False
  355. dog.right = False
  356.  
  357. if keys[pygame.K_UP] and dog.y < dog.vel:
  358. dog.y = 0
  359. dog.up = True
  360. dog.down = False
  361. dog.left = False
  362. dog.right = False
  363.  
  364. elif keys[pygame.K_DOWN] and dog.y <= scrH - dog.height - dog.vel:
  365. dog.y += dog.vel
  366. dog.down = True
  367. dog.up = False
  368. dog.left = False
  369. dog.right = False
  370.  
  371. if keys[pygame.K_DOWN] and dog.y > scrH - dog.height - dog.vel:
  372. dog.y = scrH - dog.height
  373. dog.down = True
  374. dog.up = False
  375. dog.left = False
  376. dog.right = False
  377.  
  378. if keys[pygame.K_SPACE]:
  379. if dog.mana > 1:
  380. dog.mana -= 1
  381. dog.vel = 8
  382. else:
  383. dog.vel = 5
  384.  
  385. if not keys[pygame.K_SPACE]:
  386. dog.vel = 5
  387.  
  388. if biscoito.rng_x * 40 - 64 <= dog.x <= biscoito.rng_x * 40 + 48 \
  389. and biscoito.rng_y * 40 - 64 <= dog.y <= biscoito.rng_y * 40 + 32:
  390. if dog.mana <= 100:
  391. dog.mana += 10
  392. sound_bis.play()
  393. biscoito.rng_x = random.randint(2, 18)
  394. biscoito.rng_y = random.randint(2, 13)
  395. score += 1
  396.  
  397. redraw()
  398.  
  399. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement