Guest User

Untitled

a guest
Jun 1st, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.69 KB | None | 0 0
  1. import pygame
  2. import math
  3. pygame.init()
  4. # ---------- MUSIC SECTION
  5. pygame.mixer.init()
  6.  
  7.  
  8. music = pygame.mixer.music.load("backgroundsong.wav")
  9. pygame.mixer.music.play(-1)
  10.  
  11. # shooting sound
  12. shootsound = pygame.mixer.Sound("shootsound.wav")
  13.  
  14. # hit the ice bergs sound
  15. icesound = pygame.mixer.Sound("shoot.wav")
  16.  
  17. # hurt sound
  18. hurtsound = pygame.mixer.Sound("hite.wav")
  19.  
  20. # jumpsound
  21. jumpsound = pygame.mixer.Sound("sjump.wav")
  22.  
  23. #coin sound
  24. coinsound = pygame.mixer.Sound("coinssound.wav")
  25.  
  26. # enemy hit sound
  27. hitesound = pygame.mixer.Sound("h.wav")
  28.  
  29. # enemy death sound
  30. deathsound = pygame.mixer.Sound("death.wav")
  31.  
  32. # health gain
  33. healthsound = pygame.mixer.Sound("pw.wav")
  34.  
  35. # ---------------------------------
  36.  
  37.  
  38.  
  39.  
  40. # window
  41. window = pygame.display.set_mode((800,800))
  42. pygame.display.set_caption("new World")
  43. #
  44. # error bloccks
  45. erblock = pygame.image.load("error.png")
  46.  
  47. # trees images
  48. treo = pygame.image.load("tree.png")
  49.  
  50. # mountains
  51. mounto = pygame.image.load("mount.png")
  52.  
  53. # platform images
  54. blocks = pygame.image.load("block.png")
  55.  
  56. # coins image
  57. heart = pygame.image.load("heart.png")
  58.  
  59. # heart image
  60. heartingss = pygame.image.load("health.png")
  61.  
  62.  
  63.  
  64. # define the shooting sound for the player ------------------------
  65.  
  66.  
  67.  
  68.  
  69. #---------------------------------------------
  70.  
  71.  
  72. # window
  73. window = pygame.display.set_mode((800,800))
  74. pygame.display.set_caption("new World")
  75. #
  76. # error bloccks
  77. erblock = pygame.image.load("error.png")
  78.  
  79. # trees images
  80. treo = pygame.image.load("tree.png")
  81.  
  82. # mountains
  83. mounto = pygame.image.load("mount.png")
  84.  
  85. # platform images
  86. blocks = pygame.image.load("block.png")
  87.  
  88. # coins image
  89. heart = pygame.image.load("heart.png")
  90.  
  91. # heart image
  92. heartingss = pygame.image.load("health.png")
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. # background
  101. bg = pygame.image.load("bg.png")
  102.  
  103.  
  104. # ice mountains
  105. ice = pygame.image.load("ice1.png")
  106.  
  107. #
  108. icyy = pygame.image.load("ice2.png")
  109. # player projectiles
  110. slash = pygame.image.load("heart.png")
  111. # space bar key
  112. spi = [
  113. pygame.image.load("j1.png"),
  114. pygame.image.load("j2.png")]
  115.  
  116. standingright = [pygame.image.load("d1.png"),
  117. pygame.image.load("d2.png"),
  118. pygame.image.load("d3.png"),
  119. pygame.image.load("d4.png"),
  120. pygame.image.load("d5.png"),
  121. pygame.image.load("d6.png"),
  122. pygame.image.load("d7.png"),
  123. pygame.image.load("d8.png"),
  124. pygame.image.load("d9.png"),
  125. pygame.image.load("d10.png"),
  126. pygame.image.load("d11.png"),
  127. pygame.image.load("d12.png"),
  128. pygame.image.load("d13.png"),
  129. pygame.image.load("d14.png"),
  130. pygame.image.load("d15.png")]
  131.  
  132. standingleft =[pygame.image.load("s1.png"),
  133. pygame.image.load("s2.png"),
  134. pygame.image.load("s3.png"),
  135. pygame.image.load("s4.png"),
  136. pygame.image.load("s5.png"),
  137. pygame.image.load("s6.png"),
  138. pygame.image.load("s7.png"),
  139. pygame.image.load("s8.png"),
  140. pygame.image.load("s9.png"),
  141. pygame.image.load("s10.png"),
  142. pygame.image.load("s11.png"),
  143. pygame.image.load("s12.png"),
  144. pygame.image.load("s13.png"),
  145. pygame.image.load("s14.png"),
  146. pygame.image.load("s15.png")]
  147.  
  148.  
  149.  
  150. rights = [pygame.image.load("L1.png"),
  151. pygame.image.load("L2.png"),
  152. pygame.image.load("L3.png"),
  153. pygame.image.load("L4.png"),
  154. pygame.image.load("L5.png"),
  155. pygame.image.load("L6.png"),
  156. pygame.image.load("L7.png"),
  157. pygame.image.load("L8.png"),
  158. pygame.image.load("L9.png"),
  159. pygame.image.load("L10.png"),
  160. pygame.image.load("L11.png"),
  161. pygame.image.load("L12.png"),
  162. pygame.image.load("L13.png"),
  163. pygame.image.load("L14.png"),
  164. pygame.image.load("L15.png")]
  165.  
  166.  
  167. lefts = [pygame.image.load("e1.png"),
  168. pygame.image.load("e2.png"),
  169. pygame.image.load("e3.png"),
  170. pygame.image.load("e4.png"),
  171. pygame.image.load("e5.png"),
  172. pygame.image.load("e6.png"),
  173. pygame.image.load("e7.png"),
  174. pygame.image.load("e8.png"),
  175. pygame.image.load("e9.png"),
  176. pygame.image.load("e10.png"),
  177. pygame.image.load("e11.png"),
  178. pygame.image.load("e12.png"),
  179. pygame.image.load("e13.png"),
  180. pygame.image.load("e14.png"),
  181. pygame.image.load("e15.png")]
  182.  
  183. games = [pygame.image.load("key1.png"),
  184. pygame.image.load("key2.png"),
  185. pygame.image.load("key3.png"),
  186. pygame.image.load("key4.png"),
  187. pygame.image.load("key5.png"),
  188. pygame.image.load("key6.png"),
  189. pygame.image.load("key7.png")]
  190.  
  191.  
  192.  
  193.  
  194.  
  195. # trees
  196. tree = pygame.image.load("treo.png")
  197.  
  198. # bushes
  199. bushes = pygame.image.load("bush.png")
  200. #
  201. class tree:
  202. def __init__(self,x,y,height,width,color):
  203. self.x = x
  204. self.y = y
  205. self.height = height
  206. self.width = width
  207. self.errors = pygame.image.load("treo.png")
  208. self.color = color
  209. self.rect = pygame.Rect(x,y,height,width)
  210. def draw(self):
  211. self.rect.topleft = (self.x,self.y)
  212. window.blit(self.errors,self.rect)
  213. black = (0,0,0)
  214. tree1 = tree(150,300,60,60,black)
  215. trees = [tree1]
  216.  
  217.  
  218. class bush:
  219. def __init__(self,x,y,height,width,color):
  220. self.x = x
  221. self.y = y
  222. self.height = height
  223. self.width = width
  224. self.errors = pygame.image.load("bush.png")
  225. self.color = color
  226. self.rect = pygame.Rect(x,y,height,width)
  227. def draw(self):
  228. self.rect.topleft = (self.x,self.y)
  229. window.blit(self.errors,self.rect)
  230. bush1 = bush(-987210,-87510,100,100,black)
  231. bushes = [bush1]
  232.  
  233. # erro block class
  234. class error:
  235. def __init__(self,x,y,height,width,color):
  236. self.x = x
  237. self.y = y
  238. self.height = height
  239. self.width = width
  240. self.erblock = pygame.image.load("error.png")
  241. self.color = color
  242. self.rect = pygame.Rect(x,y,height,width)
  243. def draw(self):
  244. self.rect.topleft = (self.x,self.y)
  245. player_rect = erblock.get_rect(center = self.rect.center)
  246. player_rect.centerx += 20 # 10 is just an example
  247. player_rect.centery += -20 # 15 is just an example
  248. window.blit(self.erblock,self.rect)
  249. white = (255,255,255)
  250. error1 = error(-60,504,50,50,white)
  251. errors = [error1]
  252. platformGroup = pygame.sprite.Group
  253. platformList = []
  254. level = ["p ",
  255. "p ",
  256. "p ",
  257. "p ",
  258. "p ",
  259. "p ",
  260. "p ",
  261. "p ",
  262. "p ",
  263. "p ",
  264. " ",]
  265. for iy, row in enumerate(level):
  266. for ix, col in enumerate(row):
  267. if col == "p":
  268. new_platforms = error(-60, iy*70, 50,60,(255,255,255))
  269. errors.append(new_platforms)
  270.  
  271.  
  272. # my players class
  273. # player class
  274.  
  275. class player:
  276. def __init__(self,x,y,height,width,color):
  277. self.x = x
  278. self.y = y
  279. self.color = color
  280. self.height = height
  281. self.width = width
  282. self.speed = 5
  283. self.isJump = False
  284. self.JumpCount = 10
  285. self.fall = 0
  286. #hit box
  287. self.hitbox = (self.x + 20, self.y, 28, 60)
  288. self.stand = pygame.image.load("stands.png")
  289. self.rights = [pygame.image.load("L1.png"),
  290. pygame.image.load("L2.png"),
  291. pygame.image.load("L3.png"),
  292. pygame.image.load("L4.png"),
  293. pygame.image.load("L5.png"),
  294. pygame.image.load("L6.png"),
  295. pygame.image.load("L7.png"),
  296. pygame.image.load("L8.png"),
  297. pygame.image.load("L9.png"),
  298. pygame.image.load("L10.png"),
  299. pygame.image.load("L11.png"),
  300. pygame.image.load("L12.png"),
  301. pygame.image.load("L13.png"),
  302. pygame.image.load("L14.png"),
  303. pygame.image.load("L15.png")]
  304. self.lefts = [pygame.image.load("e1.png"),
  305. pygame.image.load("e2.png"),
  306. pygame.image.load("e3.png"),
  307. pygame.image.load("e4.png"),
  308. pygame.image.load("e5.png"),
  309. pygame.image.load("e6.png"),
  310. pygame.image.load("e7.png"),
  311. pygame.image.load("e8.png"),
  312. pygame.image.load("e9.png"),
  313. pygame.image.load("e10.png"),
  314. pygame.image.load("e11.png"),
  315. pygame.image.load("e12.png"),
  316. pygame.image.load("e13.png"),
  317. pygame.image.load("e14.png"),
  318. pygame.image.load("e15.png")]
  319. self.standingright = [pygame.image.load("d1.png"),
  320. pygame.image.load("d2.png"),
  321. pygame.image.load("d3.png"),
  322. pygame.image.load("d4.png"),
  323. pygame.image.load("d5.png"),
  324. pygame.image.load("d6.png"),
  325. pygame.image.load("d7.png"),
  326. pygame.image.load("d8.png"),
  327. pygame.image.load("d9.png"),
  328. pygame.image.load("d10.png"),
  329. pygame.image.load("d11.png"),
  330. pygame.image.load("d12.png"),
  331. pygame.image.load("d13.png"),
  332. pygame.image.load("d14.png"),
  333. pygame.image.load("d15.png")]
  334. self.standingleft =[pygame.image.load("s1.png"),
  335. pygame.image.load("s2.png"),
  336. pygame.image.load("s3.png"),
  337. pygame.image.load("s4.png"),
  338. pygame.image.load("s5.png"),
  339. pygame.image.load("s6.png"),
  340. pygame.image.load("s7.png"),
  341. pygame.image.load("s8.png"),
  342. pygame.image.load("s9.png"),
  343. pygame.image.load("s10.png"),
  344. pygame.image.load("s11.png"),
  345. pygame.image.load("s12.png"),
  346. pygame.image.load("s13.png"),
  347. pygame.image.load("s14.png"),
  348. pygame.image.load("s15.png")]
  349. self.rights = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.rights]
  350. self.lefts = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.lefts]
  351. self.standingright = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.standingright]
  352. self.standingleft = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.standingleft]
  353. self.bo_index = 0
  354. self.anim_index = 0
  355. self.stans_index = 0
  356. self.direction = "right"
  357. self.direction = "left"
  358. self.direction = "standright"
  359. self.direction = "standleft"
  360. self.health = 10
  361. self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  362. # playerman hitbox
  363. self.hits = (self.x + 20, self.y, 28,60)
  364.  
  365. self.rect = pygame.rect = pygame.Rect(self.x,self.y,width, height)
  366.  
  367.  
  368.  
  369. def draw(self):
  370. self.rect.topleft = (self.x,self.y)
  371.  
  372. if self.direction == "right":
  373. image_list = self.rights
  374. elif self.direction == "standright":
  375. image_list = self.standingright
  376. elif self.direction == "left":
  377. image_list = self.lefts
  378. else:
  379. image_list = self.standingleft
  380.  
  381. if self.anim_index >= len(image_list):
  382. self.anim_index = 0
  383. player_image = image_list[self.anim_index]
  384. self.anim_index += 1
  385.  
  386. player_rect = player_image.get_rect(center = self.rect.center)
  387. player_rect.centerx += 20 # 10 is just an example
  388. player_rect.centery += -20 # 15 is just an example
  389. window.blit(player_image, player_rect)
  390. self.hits = (self.x + 20, self.y, 28,60)
  391. pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 80, 10)) # NEW
  392. pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 80 - (5 * (10 - self.health)), 10))
  393. self.hitbox = (self.x + -30, self.y + 0, 31, 57)
  394.  
  395.  
  396. # health icon
  397. heat = pygame.image.load("health.png")
  398. # player icon
  399. icon = pygame.image.load("icon.png")
  400.  
  401.  
  402. # floor platforms class
  403. class platform:
  404. def __init__(self,x,y,height,width,color):
  405. self.x = x
  406. self.y = y
  407. self.height = height
  408. self.width = width
  409. self.color = color
  410. self.blocks = pygame.image.load("block.png")
  411. self.rect = pygame.Rect(x,y,height,width)
  412. def draw(self):
  413. self.rect.topleft = (self.x,self.y)
  414. window.blit(self.blocks,self.rect)
  415.  
  416.  
  417.  
  418. # trees class
  419. class icess:
  420. def __init__(self,x,y,height,width,color):
  421. self.x = x
  422. self.y = y
  423. self.height = height
  424. self.width = width
  425. self.color = color
  426. self.icyy = pygame.image.load("ice2.png")
  427. self.icyy = pygame.transform.scale(self.icyy,(self.icyy.get_width()-44,self.icyy.get_height()-44))
  428. self.rect = pygame.Rect(x,y,height,width)
  429. self.hitbox = (self.x + 5, self.y + 1, 10, 72)
  430. def draw(self):
  431. self.rect.topleft = (self.x,self.y)
  432. player_rect = icyy.get_rect(center = self.rect.center)
  433. player_rect.centerx += 0 # 10 is just an example
  434. player_rect.centery += -50 # 15 is just an example
  435. window.blit(icyy, player_rect)
  436. self.hitbox = (self.x + 5, self.y + 1, 10, 72)
  437. black = (0,0,0)
  438. ice1 = icess(255450,16540,50434,134320,black)
  439. icing = [ice1]
  440. #
  441.  
  442. class dice:
  443. def __init__(self,x,y,height,width,color):
  444. self.x = x
  445. self.y = y
  446. self.height = height
  447. self.width = width
  448. self.color = color
  449. self.ice = pygame.image.load("ice1.png")
  450. self.ice = pygame.transform.scale(self.ice,(self.ice.get_width()-44,self.ice.get_height()-44))
  451. self.rect = pygame.Rect(x,y,height,width)
  452. # the hitbox our projectiles will be colliding with
  453. self.hitbox = (self.x + 0, self.y + 1, 10, 72)
  454. def draw(self):
  455. self.rect.topleft = (self.x,self.y)
  456. player_rect = ice.get_rect(center = self.rect.center)
  457. player_rect.centerx += -14 # 10 is just an example
  458. player_rect.centery += -15 # 15 is just an example
  459. window.blit(ice, player_rect)
  460. # hit box our projectile will be colliding with
  461. self.hitbox = (self.x + 0, self.y + 1, 10, 72)
  462.  
  463.  
  464. black = (0,0,0)
  465. ice2 = dice(254550,494540,10,30,black)
  466. dicing = [ice2]
  467.  
  468. # keys left right up[ down
  469. class Snow:
  470.  
  471. def __init__(self, x, y, height, width, color):
  472. self.color = color
  473. self.x = x
  474. self.y = y
  475. self.height = height
  476. self.width = width
  477. self.games = [
  478. pygame.image.load("key1.png"),
  479. pygame.image.load("key2.png"),
  480. pygame.image.load("key3.png"),
  481. pygame.image.load("key4.png"),
  482. pygame.image.load("key5.png"),
  483. pygame.image.load("key6.png"),
  484. pygame.image.load("key7.png")
  485. ]
  486. self.anim_index = 0
  487. self.direction = "idk"
  488. self.rect = pygame.Rect(x,y,height,width)
  489. self.delay = 150
  490. self.next_frame = pygame.time.get_ticks() + self.delay
  491.  
  492. def draw(self):
  493. self.rect.topleft = (self.x,self.y)
  494. if self.direction == "idk":
  495. window.blit(self.games[self.anim_index], self.rect)
  496.  
  497. if pygame.time.get_ticks() >= self.next_frame:
  498. self.next_frame = pygame.time.get_ticks() + self.delay
  499.  
  500. self.anim_index += 1
  501. if self.anim_index == len(self.games):
  502. self.anim_index = 0
  503.  
  504. black = (0,0,)
  505. snow1 = Snow(340,550,50,150,black)
  506. snowing = [snow1]
  507.  
  508. # space bar key
  509.  
  510. class spie:
  511. def __init__(self,x,y,height,width,color):
  512.  
  513. self.color = color
  514. self.x = x
  515. self.y = y
  516. self.height = height
  517. self.width = width
  518. self.spi = [
  519. pygame.image.load("j1.png"),
  520. pygame.image.load("j2.png")]
  521. self.anim_index = 0
  522. self.direction = "so"
  523. self.rect = pygame.Rect(x,y,height,width)
  524. self.delay = 150
  525. self.next_frame = pygame.time.get_ticks() + self.delay
  526. def draw(self):
  527. self.rect.topleft = (self.x,self.y)
  528. if self.direction == "so":
  529. window.blit(self.spi[self.anim_index], self.rect)
  530.  
  531. if pygame.time.get_ticks() >= self.next_frame:
  532. self.next_frame = pygame.time.get_ticks() + self.delay
  533.  
  534. self.anim_index += 1
  535. if self.anim_index == len(self.spi):
  536. self.anim_index = 0
  537.  
  538. black = (0,0,)
  539. spie1 = spie(10,640,50,150,black)
  540. spies = [spie1]
  541.  
  542.  
  543. # coins class
  544. class coin:
  545. def __init__(self,x,y,height,width,color):
  546. self.x = x
  547. self.y = y
  548. self.heart = pygame.image.load("heart.png")
  549. self.height = height
  550. self.width = width
  551. self.color = color
  552. self.rect = pygame.Rect(x,y,height,width)
  553. def draw(self):
  554. self.rect.topleft = (self.x,self.y)
  555. player_rect = heart.get_rect(center = self.rect.center)
  556. player_rect.centerx += 0 # 10 is just an example
  557. player_rect.centery += 0 # 15 is just an example
  558. window.blit(heart, player_rect)
  559.  
  560.  
  561. # bullet class
  562.  
  563.  
  564. class projectile(object):
  565. def __init__(self, x, y, dirx, diry, color):
  566. self.x = x
  567. self.y = y
  568. self.dirx = dirx
  569. self.diry = diry
  570. self.slash = pygame.image.load("heart.png")
  571. self.rect = self.slash.get_rect()
  572. self.rect.topleft = ( self.x, self.y )
  573. self.speed = 10
  574. self.color = color
  575. def move(self):
  576. self.x += self.dirx * self.speed
  577. self.y += self.diry * self.speed
  578. def draw(self, window):
  579. self.rect.topleft = (round(self.x), round(self.y))
  580. window.blit(self.slash,self.rect)
  581.  
  582.  
  583.  
  584. # enemys bullets
  585. class enemybullets(object):
  586. def __init__(self, x, y, dirx, diry, color):
  587. self.x = x
  588. self.y = y
  589. self.dirx = dirx
  590. self.diry = diry
  591. self.slash = pygame.image.load("heart.png")
  592. self.rect = self.slash.get_rect()
  593. self.rect.topleft = ( self.x, self.y )
  594. self.speed = 10
  595. self.color = color
  596. def move(self):
  597. self.x += self.dirx * self.speed
  598. self.y += self.diry * self.speed
  599. def draw(self, window):
  600. self.rect.topleft = (round(self.x), round(self.y))
  601. window.blit(self.slash,self.rect)
  602.  
  603.  
  604.  
  605. # players icon
  606. class icon:
  607. def __init__(self,x,y,height,width,color):
  608. self.x = x
  609. self.y = y
  610. self.height = height
  611. self.width = width
  612. self.color = color
  613. self.icon = pygame.image.load("icon.png")
  614. self.icon = pygame.transform.scale(self.icon,(self.icon.get_width()//3,self.icon.get_height()//3))
  615. self.rect = pygame.Rect(x,y,height,width)
  616. def draw(self):
  617. self.rect.topleft = (self.x,self.y)
  618. window.blit(self.icon,self.rect)
  619.  
  620. sigh = pygame.image.load("alert.png")
  621. class alrt:
  622. def __init__(self,x,y,height,width,color):
  623. self.x = x
  624. self.y = y
  625. self.sigh = pygame.image.load("alert.png")
  626. self.sigh = pygame.transform.scale(self.sigh,(self.sigh.get_width()*3,self.sigh.get_height()*3))
  627. self.height = height
  628. self.width = width
  629. self.color = color
  630. self.rect = pygame.Rect(x,y,height,width)
  631. def draw(self):
  632. self.rect.topleft = (self.x,self.y)
  633. player_rect = sigh.get_rect(center = self.rect.center)
  634. player_rect.centerx += 10 # 10 is just an example
  635. player_rect.centery += -15 # 15 is just an example
  636. window.blit(self.sigh,self.rect)
  637. black = (0,0,0)
  638. alert1 = alrt(170,370,50,50,black)
  639. alerting = [alert1]
  640.  
  641. # exit image
  642. exits = pygame.image.load("exit.png")
  643. class exi:
  644. def __init__(self,x,y,height,width,color):
  645. self.x = x
  646. self.y = y
  647. self.color = color
  648. self.height = height
  649. self.width = width
  650. self.exits = pygame.image.load("exit.png")
  651. self.exits = pygame.transform.scale(self.exits,(self.exits.get_width()*3,self.exits.get_height()*3))
  652. self.rect = pygame.Rect(x,y,height,width)
  653. def draw(self):
  654. self.rect.topleft = (self.x,self.y)
  655. window.blit(self.exits,self.rect)
  656.  
  657. # define the text class
  658. black = (0,0,0)
  659. exit1 = exi(160,140,40,40,black)
  660. exiting = [exit1]
  661.  
  662.  
  663. # text imgae
  664. te = pygame.image.load("text.png")
  665. # text class
  666. class texto:
  667. def __init__(self,x,y,height,width,color):
  668. self.x = x
  669. self.y = y
  670. self.height = height
  671. self.width = width
  672. self.color = color
  673. self.te = pygame.image.load("text.png")
  674. self.te = pygame.transform.scale(self.te,(self.te.get_width()-20,self.te.get_height()-20))
  675. self.rect = pygame.Rect(x,y,height,width)
  676. def draw(self):
  677. self.rect.topleft = (self.x,self.y)
  678. window.blit(self.te,self.rect)
  679. pygame.draw.rect(window,self.color,self.rect)
  680. # define text class
  681. black = (0,0,0)
  682. text1 = texto(50,100,50,50,black)
  683. texting = [text1]
  684.  
  685.  
  686. # house image
  687. housee = pygame.image.load("house.png")
  688. # house
  689. class house:
  690. def __init__(self,x,y,height,width,color):
  691. self.x = x
  692. self.y =y
  693. self.height = height
  694. self.width = width
  695. self.color = color
  696. self.housee = pygame.image.load("house.png")
  697. self.rect = pygame.Rect(x,y,height,width)
  698. def draw(self):
  699. self.rect.topleft = (self.x,self.y)
  700. window.blit(self.housee,self.rect)
  701. # define the house class
  702. white = (255,255,255)
  703. house1 = house(50,290,60,60,white)
  704. housing = [house1]
  705. # player image
  706. man = [pygame.image.load("i1.png"),
  707. pygame.image.load("i1.png"),
  708. pygame.image.load("i2.png"),
  709. pygame.image.load("i3.png"),
  710. pygame.image.load("i4.png"),
  711. pygame.image.load("i5.png"),
  712. pygame.image.load("i6.png"),
  713. pygame.image.load("i7.png"),
  714. pygame.image.load("i8.png"),
  715. pygame.image.load("i9.png"),
  716. pygame.image.load("i10.png"),
  717. pygame.image.load("i11.png"),
  718. pygame.image.load("i12.png"),
  719. pygame.image.load("i13.png"),
  720. pygame.image.load("i14.png"),
  721. pygame.image.load("i15.png")]
  722.  
  723.  
  724.  
  725. # player villager
  726. class villager:
  727. def __init__(self,x,y,height,width,color):
  728. self.x = x
  729. self.y = y
  730. self.height = height
  731. self.width = width
  732. self.color = color
  733. self.man =[
  734. pygame.image.load("i1.png"),
  735. pygame.image.load("i1.png"),
  736. pygame.image.load("i2.png"),
  737. pygame.image.load("i3.png"),
  738. pygame.image.load("i4.png"),
  739. pygame.image.load("i5.png"),
  740. pygame.image.load("i6.png"),
  741. pygame.image.load("i7.png"),
  742. pygame.image.load("i8.png"),
  743. pygame.image.load("i9.png"),
  744. pygame.image.load("i10.png"),
  745. pygame.image.load("i11.png"),
  746. pygame.image.load("i12.png"),
  747. pygame.image.load("i13.png"),
  748. pygame.image.load("i14.png"),
  749. pygame.image.load("i15.png")]
  750. self.direction = "so"
  751. self.anim_index = 0
  752. self.so_index = 0
  753. self.man = [pygame.transform.scale(image,(image.get_width()//5,image.get_height()//5)) for image in self.man]
  754. self.rect = pygame.Rect(x,y,height,width)
  755. def draw(self):
  756. self.rect.topleft = (self.x,self.y)
  757. if self.direction == "so":
  758. window.blit(self.man[self.anim_index], self.rect)
  759.  
  760. self.anim_index += 1
  761. if self.anim_index == len(self.man):
  762. self.anim_index = 0
  763.  
  764.  
  765.  
  766. # image of the sigh
  767. sighimage = pygame.image.load("sigh.png")
  768. # level 1 sigh class
  769. class sign:
  770. def __init__(self,x,y,height,width,color):
  771. self.x = x
  772. self.y = y
  773. self.color = color
  774. self.height = height
  775. self.width = width
  776. self.sighimage = pygame.image.load("sigh.png")
  777. self.sighimage = pygame.transform.scale(self.sighimage,(self.sighimage.get_width()-10,self.sighimage.get_height()-10))
  778. self.rect = pygame.Rect(x,y,height,width)
  779. def draw(self):
  780. self.rect.topleft = (self.x,self.y)
  781. window.blit(self.sighimage,self.rect)
  782.  
  783. # define level 1 sighn
  784. black = (0,0,0)
  785. sighn1 = sign(-33,300,50,50,black)
  786. signs = [sighn1]
  787.  
  788.  
  789.  
  790. # enemy animations
  791. esleft = [pygame.image.load("esleft1.png"),
  792. pygame.image.load("esleft1.png"),
  793. pygame.image.load("esleft2.png"),
  794. pygame.image.load("esleft3.png"),
  795. pygame.image.load("esleft4.png"),
  796. pygame.image.load("esleft5.png"),
  797. pygame.image.load("esleft6.png"),
  798. pygame.image.load("esleft7.png"),
  799. pygame.image.load("esleft8.png"),
  800. pygame.image.load("esleft9.png"),
  801. pygame.image.load("esleft10.png"),
  802. pygame.image.load("esleft11.png"),
  803. pygame.image.load("esleft12.png"),
  804. pygame.image.load("esleft13.png"),
  805. pygame.image.load("esleft14.png"),
  806. pygame.image.load("esleft15.png"),
  807. pygame.image.load("esleft16.png"),
  808. pygame.image.load("esleft17.png"),
  809. ]
  810.  
  811.  
  812. esright = [pygame.image.load("esright1.png"),
  813. pygame.image.load("esright1.png"),
  814. pygame.image.load("esright2.png"),
  815. pygame.image.load("esright3.png"),
  816. pygame.image.load("esright4.png"),
  817. pygame.image.load("esright5.png"),
  818. pygame.image.load("esright6.png"),
  819. pygame.image.load("esright7.png"),
  820. pygame.image.load("esright8.png"),
  821. pygame.image.load("esright9.png"),
  822. pygame.image.load("esright10.png"),
  823. pygame.image.load("esright11.png"),
  824. pygame.image.load("esright12.png"),
  825. pygame.image.load("esright13.png"),
  826. pygame.image.load("esright14.png"),
  827. pygame.image.load("esright15.png"),
  828. pygame.image.load("esright16.png"),
  829. pygame.image.load("esright17.png"),
  830. ]
  831.  
  832.  
  833. class enemys:
  834. def __init__(self,x,y,height,width,end):
  835. self.x = x
  836. self.y =y
  837. self.esright = [pygame.image.load("esright1.png"),
  838. pygame.image.load("esright1.png"),
  839. pygame.image.load("esright2.png"),
  840. pygame.image.load("esright3.png"),
  841. pygame.image.load("esright4.png"),
  842. pygame.image.load("esright5.png"),
  843. pygame.image.load("esright6.png"),
  844. pygame.image.load("esright7.png"),
  845. pygame.image.load("esright8.png"),
  846. pygame.image.load("esright9.png"),
  847. pygame.image.load("esright10.png"),
  848. pygame.image.load("esright11.png"),
  849. pygame.image.load("esright12.png"),
  850. pygame.image.load("esright13.png"),
  851. pygame.image.load("esright14.png"),
  852. pygame.image.load("esright15.png"),
  853. pygame.image.load("esright16.png"),
  854. pygame.image.load("esright17.png"),
  855. ]
  856. self.esleft = [pygame.image.load("esleft1.png"),
  857. pygame.image.load("esleft1.png"),
  858. pygame.image.load("esleft2.png"),
  859. pygame.image.load("esleft3.png"),
  860. pygame.image.load("esleft4.png"),
  861. pygame.image.load("esleft5.png"),
  862. pygame.image.load("esleft6.png"),
  863. pygame.image.load("esleft7.png"),
  864. pygame.image.load("esleft8.png"),
  865. pygame.image.load("esleft9.png"),
  866. pygame.image.load("esleft10.png"),
  867. pygame.image.load("esleft11.png"),
  868. pygame.image.load("esleft12.png"),
  869. pygame.image.load("esleft13.png"),
  870. pygame.image.load("esleft14.png"),
  871. pygame.image.load("esleft15.png"),
  872. pygame.image.load("esleft16.png"),
  873. pygame.image.load("esleft17.png"),
  874. ]
  875. self.esright = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esright]
  876. self.esleft = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esleft]
  877. self.height = height
  878. self.width = width
  879. self.anim_index = 0
  880. self.distance = 80
  881. self.speed = 8
  882. self.vel = 3
  883. self.path = [x,end]
  884. self.Walking_index = 0
  885. self.hitbox = (self.x + 17, self.y + 2, 31, 57)
  886. self.rect = pygame.Rect(x,y,height,width)
  887. # enemys health
  888. self.health = 10
  889. self.visible = True
  890.  
  891. # this makes the enemy move right and left
  892. def draw(self,window):
  893. self.move()
  894. if self.Walking_index + 1 >= 33:
  895. self.Walking_index = 0
  896. if self.vel > 0:
  897. window.blit(self.esright[self.Walking_index//3], (self.x,self.y))
  898. self.Walking_index += 1
  899. else:
  900. window.blit(self.esleft[self.Walking_index//3], (self.x,self.y))
  901. self.Walking_index += 1
  902.  
  903. # this moves the enemy left and right
  904. def move(self):
  905. if self.visible:
  906. if self.vel > 0:
  907. if self.x + self.vel < self.path[1]:
  908. self.x += self.vel
  909. else:
  910. self.vel = self.vel * -1
  911. self.Walking_index = 0
  912. else:
  913. if self.x - self.vel > self.path[0]:
  914. self.x += self.vel
  915. else:
  916. self.vel = self.vel * -1
  917. self.Walking_index = 0
  918. # the hit box for the enemy the health
  919. pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 70, 10)) # NEW
  920. pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 20, 70 - (5 * (10 - self.health)), 10))
  921. self.hitbox = (self.x + 47, self.y + 31, 50, 72)
  922.  
  923.  
  924. # THIS PART MAKES the enemy not scroll with the player
  925. def scroll(self,sx, sy):
  926. self.x += sx
  927. self.y += sy
  928. self.path[0] += sx
  929. self.path[1] += sx
  930.  
  931.  
  932. # position image
  933. thisispos = pygame.image.load("poslol.png")
  934. # poisiton class health UP
  935. class pos5:
  936. def __init__(self,x,y,height,width,color):
  937. self.x = x
  938. self.y = y
  939. self.height = height
  940. self.width = width
  941. self.color = color
  942. self.thisispos = pygame.image.load("poslol.png")
  943. self.rect = pygame.Rect(x,y,height,width)
  944. self.thisispos = pygame.transform.scale(self.thisispos,(self.thisispos.get_width()//8,self.thisispos.get_height()//8))
  945. # the hitbox our projectiles will be colliding with
  946. self.hitbox = (self.x + 47, self.y + 31, 50, 72)
  947. def draw(self):
  948. self.rect.topleft = (self.x,self.y)
  949. player_rect = thisispos.get_rect(center = self.rect.center)
  950. player_rect.centerx += -14 # 10 is just an example
  951. player_rect.centery += -15 # 15 is just an example
  952. # hit box our projectile will be colliding with
  953. self.hitbox = (self.x + 37, self.y + 33, 29, 52) # NEW
  954. window.blit(self.thisispos,self.rect)
  955. pygame.draw.rect(window, (255,0,0), self.hitbox,2)
  956.  
  957.  
  958. # define the pos class
  959. black = (0,0,0)
  960. pos1 = pos5(650,390,50,50,black)
  961. poses = [pos1]
  962.  
  963.  
  964.  
  965. # enemy icon image
  966. enemyi = pygame.image.load("ei.png")
  967. # enemy icon class
  968. class enemyicon:
  969. def __init__(self,x,y,height,width,color):
  970. self.x = x
  971. self.y = y
  972. self.height = height
  973. self.width = width
  974. self.color = color
  975. self.enemyi = pygame.image.load("ei.png")
  976. self.rect = pygame.Rect(x,y,height,width)
  977. self.enemyi = pygame.transform.scale(self.enemyi,(self.enemyi.get_width()//3,self.enemyi.get_height()//3))
  978. def draw(self):
  979. self.rect.topleft = (self.x,self.y)
  980. window.blit(self.enemyi,self.rect)
  981.  
  982.  
  983. # define enemy icon class
  984. black = (0,0,0)
  985. enemyi1 = enemyicon(0,70,50,50,black)
  986. enemyicons = [enemyi1]
  987.  
  988. # define the enemy class
  989. black = (0,0,0)
  990. enemys1 = enemys(400,399,104,64,500)
  991. enemying = [enemys1]
  992.  
  993.  
  994. # define the villager class
  995. red = (255,255,0)
  996. villager1 = villager(150,400,20,20,red)
  997. villaging = [villager1]
  998.  
  999.  
  1000. # define players icon
  1001. black = (0,0,0)
  1002. icon1 = icon(10,-10,90,50,black)
  1003. icons = [icon1]
  1004.  
  1005. # colors
  1006. White = (255,255,255)
  1007. Black = ((0,0,0))
  1008. Yellow = ((231,253,0))
  1009.  
  1010. # frames per second
  1011. FPS = 60
  1012. clock = pygame.time.Clock()
  1013.  
  1014.  
  1015. # define player class
  1016. playerman = player(50,450,30,30,Black)
  1017.  
  1018. # coins
  1019. coin1 = coin(340,450,30,30, Yellow)
  1020. coin2 = coin(370,450,30,30, Yellow)
  1021. coin3 = coin(370,420,30,30, Yellow)
  1022. coin4 = coin(340,420,30,30, Yellow)
  1023. coin5 = coin(480,450,30,30, Yellow)
  1024. coin6 = coin(530,450,30,30, Yellow)
  1025.  
  1026. Coins_list = [coin1,coin2,coin3,coin4,coin5,coin6]
  1027.  
  1028. # define platforms class
  1029. plat = platform(-1000,500,7900,20,White)
  1030. platforms = [plat]
  1031. platformGroup = pygame.sprite.Group
  1032. platformList = []
  1033. level = [" ",
  1034. " t ",
  1035. " to to to to ",
  1036. "p p p p p p p p p p p p p p p p p ",
  1037. " ",
  1038. " ",
  1039. " p " ,
  1040. " b b b b b b b ",
  1041. " s s s s p p ",
  1042. " b b b ",
  1043. "p p p p p p p p p p p p p p p p p p p ",]
  1044.  
  1045.  
  1046.  
  1047. for iy, row in enumerate(level):
  1048. for ix, col in enumerate(row):
  1049. if col == "p":
  1050. new_platforms = platform(ix*10, iy*50, 10,10,(255,255,255))
  1051. platforms.append(new_platforms)
  1052.  
  1053. for iy, row in enumerate(level):
  1054. for ix, col in enumerate(row):
  1055. if col == "s":
  1056. new_platforms = dice(ix*30, iy*50, 10,250,(255,255,255))
  1057. dicing.append(new_platforms)
  1058.  
  1059. for iy, row in enumerate(level):
  1060. for ix, col in enumerate(row):
  1061. if col == "t":
  1062. new_platforms = icess(ix*30, iy*110, 10,10,(255,255,255))
  1063. icing.append(new_platforms)
  1064. for iy, row in enumerate(level):
  1065. for ix, cols in enumerate(row):
  1066. if cols == "b":
  1067. new_platforms = bush(ix*20, iy*15, 10,10,(255,255,255))
  1068. bushes.append(new_platforms)
  1069.  
  1070.  
  1071.  
  1072. for iy, row in enumerate(level):
  1073. for ix, cols in enumerate(row):
  1074. if cols == "o":
  1075. new_platforms = tree(ix*20, iy* -20, 10,10,(255,255,255))
  1076. trees.append(new_platforms)
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089. # coin scoring
  1090. font = pygame.font.Font('times.ttf',29)
  1091. score = 0
  1092. text = font.render("Hearts = " + str(score), True, (255,255,255))
  1093. textRect = text.get_rect()
  1094. textRect.center = ((80,70))
  1095.  
  1096.  
  1097.  
  1098. # varabile for image text sighns
  1099. sign_clicked = False
  1100. # main game loop
  1101. bullets = []
  1102. runninggame = True
  1103. while runninggame:
  1104. clock.tick(FPS)
  1105. for event in pygame.event.get():
  1106. if event.type == pygame.QUIT:
  1107. runninggame = False
  1108.  
  1109.  
  1110. # -------- shoot the bullets when you click your mouse
  1111.  
  1112.  
  1113. if event.type == pygame.MOUSEBUTTONDOWN:
  1114.  
  1115.  
  1116.  
  1117.  
  1118. # this is for the bullets
  1119. if len(bullets) < 2:
  1120. shootsound.play()
  1121.  
  1122. start_x, start_y = playerman.x+playerman.width//2, playerman.y + playerman.height-54
  1123. mouse_x, mouse_y = event.pos
  1124.  
  1125. dir_x, dir_y = mouse_x - start_x, mouse_y - start_y
  1126. distance = math.sqrt(dir_x**2 + dir_y**2)
  1127. if distance > 0:
  1128. new_bullet = projectile(start_x, start_y, dir_x/distance, dir_y/distance, (0,0,0))
  1129. bullets.append(new_bullet)
  1130.  
  1131.  
  1132. # this is displaying the bullets for the player
  1133. for bullet in bullets[:]:
  1134. bullet.move()
  1135. if bullet.x < 0 or bullet.x > 900 or bullet.y < 0 or bullet.y > 900:
  1136. bullets.pop(bullets.index(bullet))
  1137.  
  1138. # collision for enemy health bar
  1139. for bullet in bullets:
  1140. if bullet.rect.colliderect(enemys1.hitbox):
  1141.  
  1142. if enemys1.health > -5:
  1143. enemys1.health -= 1
  1144. bullets.pop(bullets.index(bullet))
  1145. hitesound.play()
  1146. # this part is when we collide with our enemy it load -5 text on the screen
  1147. font1 = pygame.font.SysFont('BLOODY.tff', 100)
  1148. stext = font1.render('-5', 1, (255,0,0))
  1149. window.blit(stext, (450 - (stext.get_width()/2),300))
  1150. pygame.display.update()
  1151.  
  1152.  
  1153.  
  1154. else:
  1155. for one in range(len(enemying)-1,-1,-1):
  1156. deathsound.play()
  1157. del enemying[one]
  1158.  
  1159.  
  1160.  
  1161. # if collides with the sharp tiles
  1162. for bullet in bullets:
  1163. for icess in icing:
  1164. if bullet.rect.colliderect(icess.hitbox):
  1165. bullets.pop(bullets.index(bullet))
  1166. icesound.play()
  1167. print("YO YOU COLLIDED THAT SHIT")
  1168. for bullet in bullets:
  1169. for dice in dicing:
  1170. if bullet.rect.colliderect(dice.hitbox):
  1171. bullets.pop(bullets.index(bullet))
  1172. icesound.play()
  1173. print("yo fam you collided with that sharp thing")
  1174.  
  1175.  
  1176.  
  1177. # health players
  1178. for dice in dicing:
  1179. if playerman.rect.colliderect(dice.hitbox):
  1180. hurtsound.play()
  1181. if playerman.health > -6:
  1182. playerman.health -= 1
  1183. playerman.x = 10
  1184.  
  1185.  
  1186. else:
  1187. print("cant delete him")
  1188. for error in errors:
  1189. if playerman.rect.colliderect(error.rect):
  1190. playerman.x += 15
  1191.  
  1192.  
  1193. for pos5 in poses:
  1194. if playerman.rect.colliderect(pos5.rect):
  1195. healthsound.play()
  1196. playerman.health += 5
  1197. del poses[one]
  1198.  
  1199.  
  1200. # ------------------------ this part displays the health +5 when gaining health
  1201. #make sure to fix the freezing later with stakcoverflow
  1202. font2 = pygame.font.SysFont('comicsans', 100)
  1203. sstext = font2.render('+5', 1, (0,255,0))
  1204. window.blit(sstext, (450 - (sstext.get_width()/2),200))
  1205. pygame.display.update()
  1206. hs = 1111111111111110
  1207. while hs < 10:
  1208. pygame.time.delay(50)
  1209. hs += 10
  1210. hs = 10
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221. # camera left and right movement
  1222. if playerman.y < 250:
  1223. playerman.y += 1
  1224. for platform in platforms:
  1225. platform.y += playerman.speed
  1226. for coin in Coins_list:
  1227. coin.y += playerman.speed
  1228. for error in errors:
  1229. error.y += playerman.speed
  1230. for dice in dicing:
  1231. dice.y += playerman.speed
  1232. for icess in icing:
  1233. icess.y += playerman.speed
  1234. for bush in bushes:
  1235. bush.y += playerman.speed
  1236. for spie in spies:
  1237. spie.y += playerman.speed
  1238. for Snow in snowing:
  1239. Snow.y += playerman.speed
  1240. for alrt in alerting:
  1241. alrt.y += playerman.speed
  1242. for villager in villaging:
  1243. villager.y += playerman.speed
  1244. for house in housing:
  1245. house.y += playerman.speed
  1246. for tree in trees:
  1247. tree.y += playerman.speed
  1248. for sign in signs:
  1249. sign.y += playerman.speed
  1250. for pos5 in poses:
  1251. pos5.y += playerman.speed
  1252.  
  1253. for enemys in enemying:
  1254. enemys.scroll(0,+ -playerman.speed)
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269. # camera up movement:
  1270. if playerman.y > 500:
  1271. playerman.y -= playerman.fall
  1272. for platform in platforms:
  1273. platform.y -= playerman.fall
  1274. for coin in Coins_list:
  1275. coin.y -= playerman.fall
  1276. for error in errors:
  1277. error.y -= playerman.fall
  1278. for dice in dicing:
  1279. dice.y -= playerman.fall
  1280. for icess in icing:
  1281. icess.y -= playerman.fall
  1282. for bush in bushes:
  1283. bush.y -= playerman.fall
  1284. for spie in spies:
  1285. spie.y -= playerman.fall
  1286. for Snow in snowing:
  1287. Snow.y -= playerman.fall
  1288. for villager in villaging:
  1289. villager.y -= playerman.fall
  1290. for house in housing:
  1291. house.y -= playerman.fall
  1292. for alrt in alerting:
  1293. alrt.y -= playerman.fall
  1294. for tree in trees:
  1295. tree.y -= playerman.fall
  1296. for sign in signs:
  1297. sign.y -= playerman.fall
  1298. for pos5 in poses:
  1299. pos5.y -= playerman.fall
  1300. for enemys in enemying:
  1301. enemys.scroll(0, -playerman.fall)
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314. # key binds for the player
  1315. keys = pygame.key.get_pressed()
  1316. if keys[pygame.K_a]:
  1317. playerman.x -= playerman.speed
  1318. playerman.direction = "left"
  1319. # camera controll for left
  1320. if playerman.x < 100:
  1321. playerman.x += playerman.speed
  1322. for platform in platforms:
  1323. platform.x += playerman.speed
  1324. for coin in Coins_list:
  1325. coin.x += playerman.speed
  1326. for error in errors:
  1327. error.x += playerman.speed
  1328. for dice in dicing:
  1329. dice.x += playerman.speed
  1330. for icess in icing:
  1331. icess.x += playerman.speed
  1332. for bush in bushes:
  1333. bush.x += playerman.speed
  1334. for spie in spies:
  1335. spie.x += playerman.speed
  1336. for Snow in snowing:
  1337. Snow.x += playerman.speed
  1338. for villager in villaging:
  1339. villager.x += playerman.speed
  1340. for house in housing:
  1341. house.x += playerman.speed
  1342. for alrt in alerting:
  1343. alrt.x += playerman.speed
  1344. for tree in trees:
  1345. tree.x += playerman.speed
  1346. for sign in signs:
  1347. sign.x += playerman.speed
  1348. for pos5 in poses:
  1349. pos5.x += playerman.speed
  1350.  
  1351.  
  1352. for enemys in enemying:
  1353. enemys.scroll(playerman.speed,0)
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361. elif keys[pygame.K_d]:
  1362. playerman.x += playerman.speed
  1363. playerman.direction = "right"
  1364. # camera for right:
  1365. if playerman.x > 400:
  1366. playerman.x -= playerman.speed
  1367. for platform in platforms:
  1368. platform.x -= playerman.speed
  1369. for coin in Coins_list:
  1370. coin.x -= playerman.speed
  1371. for error in errors:
  1372. error.x -= playerman.speed
  1373. for dice in dicing:
  1374. dice.x -= playerman.speed
  1375. for icess in icing:
  1376. icess.x -= playerman.speed
  1377. for bush in bushes:
  1378. bush.x -= playerman.speed
  1379. for spie in spies:
  1380. spie.x -= playerman.speed
  1381. for Snow in snowing:
  1382. Snow.x -= playerman.speed
  1383. for villager in villaging:
  1384. villager.x -= playerman.speed
  1385. for house in housing:
  1386. house.x -= playerman.speed
  1387. for alrt in alerting:
  1388. alrt.x -= playerman.speed
  1389. for tree in trees:
  1390. tree.x -= playerman.speed
  1391. for sign in signs:
  1392. sign.x -= playerman.speed
  1393. for pos5 in poses:
  1394. pos5.x -= playerman.speed
  1395.  
  1396. for enemys in enemying:
  1397. enemys.scroll(-playerman.speed, 0)
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403. else:
  1404. if playerman.direction == "right":
  1405. playerman.direction = "standright"
  1406. else:
  1407. if playerman.direction == "left":
  1408. playerman.direction = "standleft"
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414. if not playerman.isJump:
  1415. playerman.y += playerman.fall
  1416. playerman.fall += 1
  1417. collide = False
  1418. playerman.isJump = False
  1419. for platform in platforms:
  1420. if playerman.rect.colliderect(platform.rect):
  1421. collide = True
  1422. isJump = False
  1423. playerman.y = platform.rect.top - playerman.height + 1
  1424. if playerman.rect.right > platform.rect.left and playerman.rect.left < platform.rect.left - playerman.width:
  1425. playerman.x = platform.rect.left - playerman.width
  1426. if playerman.rect.left < platform.rect.right and playerman.rect.right > platform.rect.right + playerman.width:
  1427. playerman.x = platform.rect.right
  1428.  
  1429.  
  1430. for one in range(len(Coins_list)-1,-1,-1):
  1431. if playerman.rect.colliderect(Coins_list[one].rect):
  1432. coinsound.play()
  1433. del Coins_list[one]
  1434. score += 1
  1435. text = font.render("Hearts = " + str(score), True, (255,255,255))
  1436. textRect.center = ((80,70))
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444. if collide:
  1445. if keys[pygame.K_SPACE]:
  1446. jumpsound.play()
  1447. playerman.isJump = True
  1448. playerman.fall = 0
  1449. else:
  1450. if playerman.JumpCount >= 0:
  1451. playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount))*0.3
  1452. playerman.JumpCount -= 1
  1453. else:
  1454. playerman.isJump = False
  1455. playerman.JumpCount = 10
  1456.  
  1457.  
  1458.  
  1459. # display the player and the screen
  1460. window.fill((106, 237, 249))
  1461. window.blit(bg,(0,0))
  1462. for pos5 in poses:
  1463. pos5.draw()
  1464. for spie in spies:
  1465. spie.draw()
  1466. for tree in trees:
  1467. tree.draw()
  1468. for bush in bushes:
  1469. bush.draw()
  1470. for icess in icing:
  1471. icess.draw()
  1472. for dice in dicing:
  1473. dice.draw()
  1474. for Snow in snowing:
  1475. Snow.draw()
  1476. for sign in signs:
  1477. sign.draw()
  1478. for error in errors:
  1479. error.draw()
  1480. for house in housing:
  1481. house.draw()
  1482. playerman.draw()
  1483. for coin in Coins_list:
  1484. coin.draw()
  1485. for platform in platforms:
  1486. platform.draw()
  1487.  
  1488.  
  1489. for enemys in enemying:
  1490. enemys.draw(window)
  1491. for icon in icons:
  1492. icon.draw()
  1493. for villager in villaging:
  1494. villager.draw()
  1495.  
  1496. for enemyicon in enemyicons:
  1497. enemyicon.draw()
  1498. for alrt in alerting:
  1499. alrt.draw()
  1500.  
  1501.  
  1502.  
  1503. for bullet in bullets:
  1504. bullet.draw(window)
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510. window.blit(text,textRect)
  1511.  
  1512.  
  1513. pygame.display.update()
  1514.  
  1515.  
  1516.  
  1517. pygame.quit()
Add Comment
Please, Sign In to add comment