Advertisement
LegitBrainless

Untitled

Mar 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.17 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((1800, 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. dioinv = pygame.image.load('dio1.png')
  14. dio = pygame.image.load('dio.png')
  15. font = pygame.font.SysFont('comicsans', 40, True)
  16.  
  17. #Sound
  18. music = pygame.mixer.music.load('jotaro.mp3')
  19. pygame.mixer.music.play(-1)
  20. pygame.mixer.music.set_volume(0.2)
  21.  
  22.  
  23. #classes and definitions
  24. class player(object):
  25. def __init__(self, x, y, width, height):
  26. self.x = x
  27. self.y = y
  28. self.width = width
  29. self.height = height
  30. self.vel = 15
  31. self.hitbox = (137, self.y, self.width, self.height)
  32.  
  33. def draw(self, win):
  34. win.blit(char, (self.x,self.y))
  35. self.hitbox = (137, self.y, self.width, self.height)
  36. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  37.  
  38. def hit(self):
  39. print('hit')
  40. self.score += 50
  41.  
  42. class textbox1(object):
  43. def __init__(self,x,y,width,height):
  44. self.x = x
  45. self.y = y
  46. self.width = width
  47. self.height = height
  48. self.vel = 6
  49. self.hitbox = (self.x, self.y, self.width, self.height)
  50.  
  51. def draw(self, win):
  52. text = font.render('the', 1, (255,255,255))
  53. win.blit(text, (self.x, self.y))
  54. self.hitbox = (self.x, self.y, self.width, self.height)
  55. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  56.  
  57. class textbox2(object):
  58. def __init__(self,x,y,width,height):
  59. self.x = x
  60. self.y = y
  61. self.width = width
  62. self.height = height
  63. self.vel = 6
  64. self.hitbox = (self.x, self.y, self.width, self.height)
  65.  
  66. def draw(self, win):
  67. text = font.render('an', 1, (255,255,255))
  68. win.blit(text, (self.x, self.y))
  69. self.hitbox = (self.x, self.y, self.width, self.height)
  70. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  71.  
  72. class textbox3(object):
  73. def __init__(self,x,y,width,height):
  74. self.x = x
  75. self.y = y
  76. self.width = width
  77. self.height = height
  78. self.vel = 6
  79. self.hitbox = (self.x, self.y, self.width, self.height)
  80.  
  81. def draw(self, win):
  82. text = font.render('a', 1, (255,255,255))
  83. win.blit(text, (self.x, self.y))
  84. self.hitbox = (self.x, self.y, self.width, self.height)
  85. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  86.  
  87. class textbox4(object):
  88. def __init__(self,x,y,width,height):
  89. self.x = x
  90. self.y = y
  91. self.width = width
  92. self.height = height
  93. self.vel = 6
  94. self.hitbox = (self.x, self.y, self.width, self.height)
  95.  
  96. def draw(self, win):
  97. text = font.render('No article', 1, (255,255,255))
  98. win.blit(text, (self.x, self.y))
  99. self.hitbox = (self.x, self.y, self.width, self.height)
  100. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  101.  
  102. class text1(object):
  103. def __init__(self,x,y,width,height):
  104. self.x = x
  105. self.y = y
  106. self.width = width
  107. self.height = height
  108. self.hitbox = (self.x, self.y, self.width, self.height)
  109.  
  110. def draw(self, win):
  111. win.blit(text1, (self.x, self.y))
  112. self.hitbox = (self.x, self.y, self.width, self.height)
  113. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  114.  
  115. class score(object):
  116. def __init__(self,x,y,width,height):
  117. self.x = x
  118. self.y = y
  119. self.width = width
  120. self.height = height
  121. self.hitbox = (self.x, self.y, self.width, self.height)
  122.  
  123. def draw(self, win):
  124. text = font.render('Score: ' + str(man.score), 1, (255,255,255))
  125. win.blit(text, (self.x, self.y))
  126. self.hitbox = (self.x, self.y, self.width, self.height)
  127. #pygame.draw.rect(win, (255,0,0), self.hitbox, 2)
  128.  
  129. class heart(object):
  130. def __init__(self,x,y,width,height):
  131. self.x = x
  132. self.y = y
  133. self.width = width
  134. self.height = height
  135. self.visible = True
  136.  
  137. def draw(self, win):
  138. if self.visible:
  139. win.blit(life, (self.x, self.y))
  140.  
  141. class heart2(object):
  142. def __init__(self,x,y,width,height):
  143. self.x = x
  144. self.y = y
  145. self.width = width
  146. self.height = height
  147. self.visible2 = True
  148.  
  149. def draw(self, win):
  150. if self.visible2:
  151. win.blit(life, (self.x, self.y))
  152.  
  153. class heart3(object):
  154. def __init__(self,x,y,width,height):
  155. self.x = x
  156. self.y = y
  157. self.width = width
  158. self.height = height
  159. self.visible3 = True
  160.  
  161. def draw(self, win):
  162. if self.visible3:
  163. win.blit(life, (self.x, self.y))
  164.  
  165. def level():
  166. article1.vel += 0.25
  167. article2.vel += 0.25
  168. article3.vel += 0.25
  169. article4.vel += 0.25
  170.  
  171.  
  172.  
  173. def drawgamewindow():
  174. win.blit(bg,(0,0))
  175. article1.draw(win)
  176. article2.draw(win)
  177. article3.draw(win)
  178. article4.draw(win)
  179. elu.draw(win)
  180. elu2.draw(win)
  181. elu3.draw(win)
  182. man.draw(win)
  183. text2.draw(win)
  184. text3.draw(win)
  185. pygame.display.update()
  186.  
  187. #k6ik vajalik crap
  188. number = 3 #PEAB MUUTMA SAMAKS, MIS LAUSETE ARV IGAS J2RJENDIS
  189. the = ['... Second World war ended in 1945.','Do you know ... people who live next door','Have you ever visited ... Tower of London ?']
  190. an = ['I am not ... honorable person',"I am ... hour away", "John is ... abortionist"]
  191. a = ['You are ... cruel person', "For his birthday, Steven got ... ballpoint pen","I broke ... glass table"]
  192. empty = ["John himself doesn't go to ... church.",'After ... work Ann usually goes home.','I hate ... violence.']
  193. laused = [the, an, a, empty]
  194. run = True
  195. article1 = textbox1(3000, 125, 1, 25)
  196. article2 = textbox2(3000, 275, 1, 25)
  197. article3 = textbox3(3000, 425, 1, 25)
  198. article4 = textbox4(3000, 575, 1, 25)
  199. suvaline = random.choice(laused)
  200. text2 = text1(100, 50, 100, 50)
  201. valik = random.choice(0,number - 1)
  202. valik2 = suvaline[valik]
  203. text1 = font.render(valik2, 1, (255,255,255))
  204. text3 = score(100, 668, 100, 50)
  205. man = player(100, 100, 65, 125)
  206. elu = heart(300, 668, 100 ,50)
  207. elu2 = heart2(342, 668, 100, 50)
  208. elu3 = heart3(384, 668, 100 ,50)
  209. man.score = 0
  210. viga = 3
  211. combo = 0
  212.  
  213. #mainloop
  214. while run:
  215. pygame.time.delay(20)
  216.  
  217. for event in pygame.event.get():
  218. if event.type == pygame.QUIT:
  219. run = False
  220.  
  221.  
  222. #artiklite liikumine ja muu tegevus
  223. article1.x -= article1.vel
  224. article2.x -= article2.vel
  225. article3.x -= article2.vel
  226. article4.x -= article2.vel
  227.  
  228. #artikkel 1 liikumine
  229. if article1.y - article1.height < man.hitbox[1] + man.hitbox[3] and article1.y + article1.height > man.hitbox[1]:
  230. if article1.x + article1.width > man.hitbox[0] and article1.x < man.hitbox[0] + man.hitbox[2]:
  231. print('1')
  232. if suvaline == (the):
  233. print('6IGE')
  234. man.hit()
  235. article1.x = 1900
  236. article2.x = 1900
  237. article3.x = 1900
  238. article4.x = 1900
  239. del suvaline(valik)
  240. suvaline = random.choice(laused)
  241. valik = random.choice(0,number - 1)
  242. valik2 = suvaline[valik]
  243. text1 = font.render(valik2, 1, (255,255,255))
  244. level()
  245. combo += 1
  246. if combo == 3:
  247. man.score += 50
  248. if combo == 5:
  249. man.score += 50
  250. if combo == 10:
  251. man.score += 150
  252.  
  253. else:
  254. print('vale')
  255. article1.x = 1900
  256. article2.x = 1900
  257. article3.x = 1900
  258. article4.x = 1900
  259. valik.remove(suvaline)
  260. combo = 0
  261. viga -= 1
  262.  
  263. if viga == 0:
  264. article1.vel = 0
  265. article2.vel = 0
  266. article3.vel = 0
  267. article4.vel = 0
  268. else:
  269. valik = random.choice(0,number - 1)
  270. suvaline = random.choice(laused)
  271. valik2 = suvaline[valik]
  272. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  273.  
  274. if viga == 2:
  275. elu3.visible3 = False
  276.  
  277. elif viga == 1:
  278. elu2.visible2 = False
  279. elu3.visible3 = False
  280.  
  281. else:
  282. elu.visible = False
  283. elu2.visible2 = False
  284. elu3.visible3 = False
  285.  
  286. #artikkel 2 liikumine
  287. if article2.y - article2.height < man.hitbox[1] + man.hitbox[3] and article2.y + article2.height > man.hitbox[1]:
  288. if article2.x + article2.width > man.hitbox[0] and article2.x < man.hitbox[0] + man.hitbox[2]:
  289. print('2')
  290. if suvaline == (an):
  291. print('6IGE')
  292. man.hit()
  293. article1.x = 1900
  294. article2.x = 1900
  295. article3.x = 1900
  296. article4.x = 1900
  297. del suvaline(valik)
  298. suvaline = random.choice(laused)
  299. valik = random.choice(0,number - 1)
  300. valik2 = suvaline[valik]
  301. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  302. level()
  303. combo += 1
  304. if combo == 3:
  305. man.score += 50
  306. if combo == 5:
  307. man.score += 50
  308. if combo == 10:
  309. man.score += 150
  310.  
  311.  
  312. else:
  313. print('vale')
  314. article1.x = 1900
  315. article2.x = 1900
  316. article3.x = 1900
  317. article4.x = 1900
  318. combo = 0
  319. viga -= 1
  320.  
  321. if viga == 0:
  322. article1.vel = 0
  323. article2.vel = 0
  324. article3.vel = 0
  325. article4.vel = 0
  326. else:
  327. valik = random.choice(0,number - 1)
  328. suvaline = random.choice(laused)
  329. valik2 = suvaline[valik]
  330. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  331.  
  332. if viga == 2:
  333. elu3.visible3 = False
  334.  
  335. elif viga == 1:
  336. elu2.visible2 = False
  337. elu3.visible3 = False
  338.  
  339. else:
  340. elu.visible = False
  341. elu2.visible2 = False
  342. elu3.visible3 = False
  343.  
  344. #artikkel 3 liikumine
  345. if article3.y - article3.height < man.hitbox[1] + man.hitbox[3] and article3.y + article3.height > man.hitbox[1]:
  346. if article3.x + article3.width > man.hitbox[0] and article3.x < man.hitbox[0] + man.hitbox[2]:
  347. print('3')
  348. if suvaline == (a):
  349. print('6IGE')
  350. man.hit()
  351. article1.x = 1900
  352. article2.x = 1900
  353. article3.x = 1900
  354. article4.x = 1900
  355. del suvaline(valik)
  356. suvaline = random.choice(laused)
  357. valik = random.choice(0,number - 1)
  358. valik2 = suvaline[valik]
  359. suvaline = random.choice(laused)
  360. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  361. level()
  362. combo += 1
  363. if combo == 3:
  364. man.score += 50
  365. if combo == 5:
  366. man.score += 50
  367. if combo == 10:
  368. man.score += 150
  369.  
  370. else:
  371. print('vale')
  372. article1.x = 1900
  373. article2.x = 1900
  374. article3.x = 1900
  375. article4.x = 1900
  376. combo = 0
  377. viga -= 1
  378.  
  379. if viga == 0:
  380. article1.vel = 0
  381. article2.vel = 0
  382. article3.vel = 0
  383. article4.vel = 0
  384. else:
  385.  
  386. valik = random.choice(0,number - 1)
  387. suvaline = random.choice(laused)
  388. valik2 = suvaline[valik]
  389. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  390. if viga == 2:
  391. elu3.visible3 = False
  392.  
  393. elif viga == 1:
  394. elu2.visible2 = False
  395. elu3.visible3 = False
  396.  
  397. else:
  398. elu.visible = False
  399. elu2.visible2 = False
  400. elu3.visible3 = False
  401. #artikkel 4 liikumine
  402. if article4.y - article4.height < man.hitbox[1] + man.hitbox[3] and article4.y + article4.height > man.hitbox[1]:
  403. if article4.x + article4.width > man.hitbox[0] and article4.x < man.hitbox[0] + man.hitbox[2]:
  404. print('4')
  405. if suvaline == (empty):
  406. print('6IGE')
  407. man.hit()
  408. article1.x = 1900
  409. article2.x = 1900
  410. article3.x = 1900
  411. article4.x = 1900
  412. del suvaline(valik)
  413. suvaline = random.choice(laused)
  414. valik = random.choice(0,number - 1)
  415. valik2 = suvaline[valik]
  416. suvaline = random.choice(laused)
  417. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  418. level()
  419. combo += 1
  420. if combo == 3:
  421. man.score += 30
  422. if combo == 5:
  423. man.score += 50
  424. if combo == 10:
  425. man.score += 150
  426.  
  427. else:
  428. print('vale')
  429. article1.x = 1900
  430. article2.x = 1900
  431. article3.x = 1900
  432. article4.x = 1900
  433. valik.remove(suvaline)
  434. combo = 0
  435. viga -= 1
  436.  
  437. if viga == 0:
  438. article1.vel = 0
  439. article2.vel = 0
  440. article3.vel = 0
  441. article4.vel = 0
  442. else:
  443. valik = random.choice(0,number - 1)
  444. suvaline = random.choice(laused)
  445. valik2 = suvaline[valik]
  446. text1 = font.render(random.choice(suvaline), 1, (255,255,255))
  447.  
  448. if viga == 2:
  449. elu3.visible3 = False
  450.  
  451. elif viga == 1:
  452. elu2.visible2 = False
  453. elu3.visible3 = False
  454.  
  455. else:
  456. elu.visible = False
  457. elu2.visible2 = False
  458. elu3.visible3 = False
  459.  
  460. #player movement
  461. keys = pygame.key.get_pressed()
  462.  
  463. if keys[pygame.K_w] and man.y > man.vel + 69:
  464. man.y -= man.vel
  465.  
  466. if keys[pygame.K_s] and man.y < 690 - man.height - man.vel:
  467. man.y += man.vel
  468.  
  469.  
  470. drawgamewindow()
  471.  
  472.  
  473.  
  474.  
  475. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement