Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  1. import pygame
  2. import random
  3. pygame.init()
  4.  
  5.  
  6. #score200 no article läks mehest läbi
  7. #Graphics
  8. win = pygame.display.set_mode((1366, 768))
  9. pygame.display.set_caption("Jotaro's revenge")
  10. bg = pygame.image.load('bg.png')
  11. char = pygame.image.load('ora.png')
  12. life = pygame.image.load('heart.png')
  13. font = pygame.font.SysFont('comicsans', 40, True)
  14.  
  15. #Sound
  16. music = pygame.mixer.music.load('jotaro.mp3')
  17. pygame.mixer.music.play(-1)
  18. pygame.mixer.music.set_volume(0.2)
  19.  
  20.  
  21. #classes and definitions
  22. class player(object):
  23. def __init__(self, x, y, width, height):
  24. self.x = x
  25. self.y = y
  26. self.width = width
  27. self.height = height
  28. self.vel = 15
  29. self.hitbox = (137, self.y, self.width, self.height)
  30.  
  31. def draw(self, win):
  32. win.blit(char, (self.x,self.y))
  33. self.hitbox = (137, self.y, self.width, self.height)
  34. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  35.  
  36. def hit(self):
  37. print('hit')
  38. self.score += 50
  39.  
  40. class textbox1(object):
  41. def __init__(self,x,y,width,height):
  42. self.x = x
  43. self.y = y
  44. self.width = width
  45. self.height = height
  46. self.vel = 6
  47. self.hitbox = (self.x, self.y, self.width, self.height)
  48.  
  49. def draw(self, win):
  50. text = font.render('the', 1, (255,255,255))
  51. win.blit(text, (self.x, self.y))
  52. self.hitbox = (self.x, self.y, self.width, self.height)
  53. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  54.  
  55. class textbox2(object):
  56. def __init__(self,x,y,width,height):
  57. self.x = x
  58. self.y = y
  59. self.width = width
  60. self.height = height
  61. self.vel = 6
  62. self.hitbox = (self.x, self.y, self.width, self.height)
  63.  
  64. def draw(self, win):
  65. text = font.render('an', 1, (255,255,255))
  66. win.blit(text, (self.x, self.y))
  67. self.hitbox = (self.x, self.y, self.width, self.height)
  68. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  69.  
  70. class textbox3(object):
  71. def __init__(self,x,y,width,height):
  72. self.x = x
  73. self.y = y
  74. self.width = width
  75. self.height = height
  76. self.vel = 6
  77. self.hitbox = (self.x, self.y, self.width, self.height)
  78.  
  79. def draw(self, win):
  80. text = font.render('a', 1, (255,255,255))
  81. win.blit(text, (self.x, self.y))
  82. self.hitbox = (self.x, self.y, self.width, self.height)
  83. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  84.  
  85. class textbox4(object):
  86. def __init__(self,x,y,width,height):
  87. self.x = x
  88. self.y = y
  89. self.width = width
  90. self.height = height
  91. self.vel = 6
  92. self.hitbox = (self.x, self.y, self.width, self.height)
  93.  
  94. def draw(self, win):
  95. text = font.render('No article', 1, (255,255,255))
  96. win.blit(text, (self.x, self.y))
  97. self.hitbox = (self.x, self.y, self.width, self.height)
  98. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  99.  
  100. class text1(object):
  101. def __init__(self,x,y,width,height):
  102. self.x = x
  103. self.y = y
  104. self.width = width
  105. self.height = height
  106. self.hitbox = (self.x, self.y, self.width, self.height)
  107.  
  108. def draw(self, win):
  109. win.blit(text1, (self.x, self.y))
  110. self.hitbox = (self.x, self.y, self.width, self.height)
  111. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  112.  
  113. class score(object):
  114. def __init__(self,x,y,width,height):
  115. self.x = x
  116. self.y = y
  117. self.width = width
  118. self.height = height
  119. self.hitbox = (self.x, self.y, self.width, self.height)
  120.  
  121. def draw(self, win):
  122. text = font.render('Score: ' + str(man.score), 1, (255,255,255))
  123. win.blit(text, (self.x, self.y))
  124. self.hitbox = (self.x, self.y, self.width, self.height)
  125. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  126.  
  127. class heart(object):
  128. def __init__(self,x,y,width,height):
  129. self.x = x
  130. self.y = y
  131. self.width = width
  132. self.height = height
  133.  
  134. def draw(self, win):
  135. win.blit(life, (self.x, self.y))
  136.  
  137. def level():
  138. article1.vel += 0.25
  139. article2.vel += 0.25
  140. article3.vel += 0.25
  141. article4.vel += 0.25
  142.  
  143.  
  144.  
  145. def drawgamewindow():
  146. win.blit(bg,(0,0))
  147. article1.draw(win)
  148. article2.draw(win)
  149. article3.draw(win)
  150. article4.draw(win)
  151. elu.draw(win)
  152. man.draw(win)
  153. text2.draw(win)
  154. text3.draw(win)
  155. pygame.display.update()
  156.  
  157. #k6ik vajalik crap
  158. the = ['... Second World war ended in 1945.','Do you know ... people who live next door','Have you ever visited ... Tower of London ?']
  159. an = ['I am not ... honorable person',"I am ... hour away", "John is ... abortionist"]
  160. a = ['You are ... cruel person', "For his birthday, Steven got ... ballpoint pen","I broke ... glass table"]
  161. empty = ["John himself doesn't go to ... church.",'After ... work Ann usually goes home.','I hate ... violence.']
  162. laused = [the, an, a, empty]
  163. run = True
  164. article1 = textbox1(1400, 100, 1, 25)
  165. article2 = textbox2(1400, 250, 1, 25)
  166. article3 = textbox3(1400, 400, 1, 25)
  167. article4 = textbox4(1400, 550, 1, 25)
  168. suvaline = random.choice(laused)
  169. text2 = text1(100, 50, 100, 50)
  170. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  171. text3 = score(100, 668, 100, 50)
  172. man = player(100, 100, 65, 125)
  173. elu = heart(300, 668, 100 ,50)
  174. man.score = 0
  175. viga = 3
  176. combo = 0
  177.  
  178. #mainloop
  179. while run:
  180. pygame.time.delay(20)
  181.  
  182. for event in pygame.event.get():
  183. if event.type == pygame.QUIT:
  184. run = False
  185.  
  186. #artiklite liikumine ja muu tegevus
  187. article1.x -= article1.vel
  188. article2.x -= article2.vel
  189. article3.x -= article2.vel
  190. article4.x -= article2.vel
  191.  
  192. if article1.y - article1.height < man.hitbox[1] + man.hitbox[3] and article1.y + article1.height > man.hitbox[1]:
  193. if article1.x + article1.width > man.hitbox[0] and article1.x < man.hitbox[0] + man.hitbox[2]:
  194. print('1')
  195. if suvaline == (the):
  196. print('6IGE')
  197. man.hit()
  198. article1.x = 1400
  199. article2.x = 1400
  200. article3.x = 1400
  201. article4.x = 1400
  202. suvaline = random.choice(laused)
  203. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  204. level()
  205. combo += 1
  206. if combo == 3:
  207. man.score += 50
  208. if combo == 5:
  209. man.score += 50
  210. if combo == 10:
  211. man.score += 150
  212.  
  213. else:
  214. print('vale')
  215. article1.x = 1400
  216. article2.x = 1400
  217. article3.x = 1400
  218. article4.x = 1400
  219. combo = 0
  220.  
  221. if viga == 0:
  222. article1.vel = 0
  223. article2.vel = 0
  224. article3.vel = 0
  225. article4.vel = 0
  226. else:
  227. suvaline = random.choice(laused)
  228. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  229. viga -= 1
  230.  
  231. if article2.y - article2.height < man.hitbox[1] + man.hitbox[3] and article2.y + article2.height > man.hitbox[1]:
  232. if article2.x + article2.width > man.hitbox[0] and article2.x < man.hitbox[0] + man.hitbox[2]:
  233. print('2')
  234. if suvaline == (an):
  235. print('6IGE')
  236. man.hit()
  237. article1.x = 1400
  238. article2.x = 1400
  239. article3.x = 1400
  240. article4.x = 1400
  241. suvaline = random.choice(laused)
  242. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  243. level()
  244. combo += 1
  245. if combo == 3:
  246. man.score += 50
  247. if combo == 5:
  248. man.score += 50
  249. if combo == 10:
  250. man.score += 150
  251.  
  252.  
  253. else:
  254. print('vale')
  255. article1.x = 1400
  256. article2.x = 1400
  257. article3.x = 1400
  258. article4.x = 1400
  259. combo = 0
  260. if viga == 0:
  261. article1.vel = 0
  262. article2.vel = 0
  263. article3.vel = 0
  264. article4.vel = 0
  265. else:
  266. suvaline = random.choice(laused)
  267. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  268. viga -= 1
  269.  
  270.  
  271. if article3.y - article3.height < man.hitbox[1] + man.hitbox[3] and article3.y + article3.height > man.hitbox[1]:
  272. if article3.x + article3.width > man.hitbox[0] and article3.x < man.hitbox[0] + man.hitbox[2]:
  273. print('3')
  274. if suvaline == (a):
  275. print('6IGE')
  276. man.hit()
  277. article1.x = 1400
  278. article2.x = 1400
  279. article3.x = 1400
  280. article4.x = 1400
  281. suvaline = random.choice(laused)
  282. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  283. level()
  284. combo += 1
  285. if combo == 3:
  286. man.score += 50
  287. if combo == 5:
  288. man.score += 50
  289. if combo == 10:
  290. man.score += 150
  291.  
  292. else:
  293. print('vale')
  294. article1.x = 1400
  295. article2.x = 1400
  296. article3.x = 1400
  297. article4.x = 1400
  298. combo = 0
  299. if viga == 0:
  300. article1.vel = 0
  301. article2.vel = 0
  302. article3.vel = 0
  303. article4.vel = 0
  304. else:
  305. suvaline = random.choice(laused)
  306. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  307. viga -= 1
  308.  
  309. if article4.y - article4.height < man.hitbox[1] + man.hitbox[3] and article4.y + article4.height > man.hitbox[1]:
  310. if article4.x + article4.width > man.hitbox[0] and article4.x < man.hitbox[0] + man.hitbox[2]:
  311. print('4')
  312. if suvaline == (empty):
  313. print('6IGE')
  314. man.hit()
  315. article1.x = 1400
  316. article2.x = 1400
  317. article3.x = 1400
  318. article4.x = 1400
  319. suvaline = random.choice(laused)
  320. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  321. level()
  322. combo += 1
  323. if combo == 3:
  324. man.score += 30
  325. if combo == 5:
  326. man.score += 50
  327. if combo == 10:
  328. man.score += 150
  329.  
  330. else:
  331. print('vale')
  332. article1.x = 1400
  333. article2.x = 1400
  334. article3.x = 1400
  335. article4.x = 1400
  336. combo = 0
  337. if viga == 0:
  338. article1.vel = 0
  339. article2.vel = 0
  340. article3.vel = 0
  341. article4.vel = 0
  342. else:
  343. suvaline = random.choice(laused)
  344. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  345. viga -= 1
  346.  
  347. #player movement
  348. keys = pygame.key.get_pressed()
  349.  
  350. if keys[pygame.K_w] and man.y > man.vel :
  351. man.y -= man.vel
  352.  
  353. if keys[pygame.K_s] and man.y < 700 - man.height - man.vel:
  354. man.y += man.vel
  355.  
  356.  
  357. drawgamewindow()
  358.  
  359.  
  360.  
  361.  
  362. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement