Advertisement
LegitBrainless

Untitled

Mar 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. import pygame
  2. import random
  3. pygame.init()
  4.  
  5. #Graphics
  6. win = pygame.display.set_mode((1800, 700))
  7. pygame.display.set_caption("Jotaro's revenge")
  8. bg = pygame.image.load('bg.png')
  9. char = pygame.image.load('ora.png')
  10. font = pygame.font.SysFont('comicsans', 40, True)
  11.  
  12. #Sound
  13. music = pygame.mixer.music.load('jotaro.mp3')
  14. pygame.mixer.music.play(-1)
  15. pygame.mixer.music.set_volume(0.2)
  16.  
  17.  
  18. #classes and definitions
  19. class player(object):
  20. def __init__(self, x, y, width, height):
  21. self.x = x
  22. self.y = y
  23. self.width = width
  24. self.height = height
  25. self.vel = 15
  26. self.hitbox = (137, self.y, self.width, self.height)
  27.  
  28. def draw(self, win):
  29. win.blit(char, (self.x,self.y))
  30. self.hitbox = (137, self.y, self.width, self.height)
  31. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  32.  
  33. def hit(self):
  34. print('hit')
  35. self.score += 50
  36.  
  37. class textbox1(object):
  38. def __init__(self,x,y,width,height):
  39. self.x = x
  40. self.y = y
  41. self.width = width
  42. self.height = height
  43. self.vel = 6
  44. self.hitbox = (self.x, self.y, self.width, self.height)
  45.  
  46. def draw(self, win):
  47. text = font.render('the', 1, (255,255,255))
  48. win.blit(text, (self.x, self.y))
  49. self.hitbox = (self.x, self.y, self.width, self.height)
  50. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  51.  
  52. class textbox2(object):
  53. def __init__(self,x,y,width,height):
  54. self.x = x
  55. self.y = y
  56. self.width = width
  57. self.height = height
  58. self.vel = 6
  59. self.hitbox = (self.x, self.y, self.width, self.height)
  60.  
  61. def draw(self, win):
  62. text = font.render('an', 1, (255,255,255))
  63. win.blit(text, (self.x, self.y))
  64. self.hitbox = (self.x, self.y, self.width, self.height)
  65. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  66.  
  67. class textbox3(object):
  68. def __init__(self,x,y,width,height):
  69. self.x = x
  70. self.y = y
  71. self.width = width
  72. self.height = height
  73. self.vel = 6
  74. self.hitbox = (self.x, self.y, self.width, self.height)
  75.  
  76. def draw(self, win):
  77. text = font.render('a', 1, (255,255,255))
  78. win.blit(text, (self.x, self.y))
  79. self.hitbox = (self.x, self.y, self.width, self.height)
  80. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  81.  
  82. class textbox4(object):
  83. def __init__(self,x,y,width,height):
  84. self.x = x
  85. self.y = y
  86. self.width = width
  87. self.height = height
  88. self.vel = 6
  89. self.hitbox = (self.x, self.y, self.width, self.height)
  90.  
  91. def draw(self, win):
  92. text = font.render('No article', 1, (255,255,255))
  93. win.blit(text, (self.x, self.y))
  94. self.hitbox = (self.x, self.y, self.width, self.height)
  95. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  96.  
  97. class text1(object):
  98. def __init__(self,x,y,width,height):
  99. self.x = x
  100. self.y = y
  101. self.width = width
  102. self.height = height
  103. self.hitbox = (self.x, self.y, self.width, self.height)
  104.  
  105. def draw(self, win):
  106. win.blit(text1, (self.x, self.y))
  107. self.hitbox = (self.x, self.y, self.width, self.height)
  108. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  109.  
  110. def drawgamewindow():
  111. win.blit(bg,(0,0))
  112. article1.draw(win)
  113. article2.draw(win)
  114. article3.draw(win)
  115. article4.draw(win)
  116. man.draw(win)
  117. text2.draw(win)
  118. pygame.display.update()
  119.  
  120. #k6ik vajalik crap
  121. the = ['... Second World war ended in 1945.','Do you know ... people who live next door','Have you ever visited ... Tower of London ?']
  122. an = ['I am not ... honorable person',"I am ... hour away", "John is ... abortionist"]
  123. a = ['You are ... cruel person', "For his birthday, Steven got ... ballpoint pen","I broke ... glass table"]
  124. empty = ["John himself doesn't go to ... church.",'After ... work Ann usually goes home.','I hate ... violence.']
  125. laused = [the, an, a, empty]
  126. run = True
  127. article1 = textbox1(2000, 100, 100, 50)
  128. article2 = textbox2(2000, 250, 100, 50)
  129. article3 = textbox3(2000, 400, 100, 50)
  130. article4 = textbox4(2000, 550, 100, 50)
  131. text2 = text1(100, 50, 100, 50)
  132. text1 = font.render(random.choice(the), 1, (255,255,255))
  133. man = player(100, 100, 65, 125)
  134. man.score = 0
  135.  
  136. #SEESIIN
  137.  
  138. #mainloop
  139. while run:
  140. pygame.time.delay(20)
  141.  
  142. #player movement
  143. for event in pygame.event.get():
  144. if event.type == pygame.QUIT:
  145. run = False
  146.  
  147. #artiklite liikumine
  148. article1.x -= article1.vel
  149. article2.x -= article2.vel
  150. article3.x -= article2.vel
  151. article4.x -= article2.vel
  152.  
  153. if article1.y - article1.height < man.hitbox[1] + man.hitbox[3] and article1.y + article1.height > man.hitbox[1]:
  154. if article1.x + article1.width > man.hitbox[0] and article1.x < man.hitbox[0] + man.hitbox[2]:
  155. man.hit()
  156. print('1')
  157.  
  158. if article2.y - article2.height < man.hitbox[1] + man.hitbox[3] and article2.y + article2.height > man.hitbox[1]:
  159. if article2.x + article2.width > man.hitbox[0] and article2.x < man.hitbox[0] + man.hitbox[2]:
  160. man.hit()
  161. print('2')
  162.  
  163. if article3.y - article3.height < man.hitbox[1] + man.hitbox[3] and article3.y + article3.height > man.hitbox[1]:
  164. if article3.x + article3.width > man.hitbox[0] and article3.x < man.hitbox[0] + man.hitbox[2]:
  165. man.hit()
  166. print('3')
  167.  
  168. if article4.y - article4.height < man.hitbox[1] + man.hitbox[3] and article4.y + article4.height > man.hitbox[1]:
  169. if article4.x + article4.width > man.hitbox[0] and article4.x < man.hitbox[0] + man.hitbox[2]:
  170. man.hit()
  171. print('4')
  172.  
  173. #player movement
  174. keys = pygame.key.get_pressed()
  175.  
  176. if keys[pygame.K_w] and man.y > man.vel :
  177. man.y -= man.vel
  178.  
  179. if keys[pygame.K_s] and man.y < 700 - man.height - man.vel:
  180. man.y += man.vel
  181.  
  182.  
  183. drawgamewindow()
  184.  
  185.  
  186.  
  187.  
  188. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement