Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 73.78 KB | None | 0 0
  1. #
  2. # Simple start to a game in PyQt5
  3. # move with arrow keys, spacebar to fire bullets
  4. # Used graphics from https://opengameart.org/content/space-shooter-redux
  5. # (reduced by 50%)
  6. # Got some hints from https://www.youtube.com/watch?v=8ntEQpg7gck series
  7. # and http://zetcode.com/gui/pyqt5/tetris/
  8. #
  9. import sys
  10. from PyQt5.QtCore import (
  11. Qt,
  12. QBasicTimer
  13. )
  14. from PyQt5.QtGui import (
  15. QBrush,
  16. QPixmap,
  17. QImage,
  18. QFont
  19. )
  20. from PyQt5.QtWidgets import (
  21. QApplication,
  22. QGraphicsItem,
  23. QGraphicsPixmapItem,
  24. QGraphicsRectItem,
  25. QGraphicsScene,
  26. QGraphicsView,
  27. QWidget,
  28. QLabel
  29.  
  30. )
  31. import random
  32. import time
  33. import multiprocessing as mp
  34. from multiprocessing import Queue, current_process
  35. import socket
  36.  
  37. HOST = '192.168.100.212' # Symbolic name meaning all available interfaces
  38. PORTSEND = 50005 # Arbitrary non-privileged port
  39. PORTRECV = 50006
  40.  
  41. SCREEN_WIDTH = 1280
  42. SCREEN_HEIGHT = 978
  43. PLAYER_SPEED = 7 # pix/frame
  44. PLAYER_BULLET_X_OFFSETS = [0, 45]
  45. PLAYER_BULLET_Y = 15
  46. BULLET_SPEED = 10 # pix/frame
  47. BULLET_FRAMES = 80
  48. FRAME_TIME_MS = 18 # ms/frame
  49.  
  50. LEVEL = 1 # platforma igraca 1
  51. LEVEL_PLAYER1 = 1 # na kojoj je platformi igrac 1
  52. PLAYER1_LIVES = 3 # zivoti igraca 1
  53. POINTS1 = 0 # poeni igraca 1
  54.  
  55. LEVEL2 = 1 # platforma igraca 2
  56. LEVEL_PLAYER2 = 1 # na kojoj je platformi igrac 2
  57. PLAYER2_LIVES = 3 # zivoti igraca 2
  58. POINTS2 = 0 # poeni igraca 2
  59.  
  60. LEVEL3 = 1 # platforma igraca 3
  61. LEVEL_PLAYER3 = 1 # na kojoj je platformi igrac 3
  62. PLAYER3_LIVES = 3 # zivoti igraca 3
  63. POINTS3 = 0 # poeni igraca 3
  64.  
  65. LEVEL4 = 1 # platforma igraca 4
  66. LEVEL_PLAYER4 = 1 # na kojoj je platformi igrac 4
  67. PLAYER4_LIVES = 3 # zivoti igraca 4
  68. POINTS4 = 0 # poeni igraca 4
  69.  
  70. WINNER = 0 # ko je pobednik -- treba promenuti, radi samo za 2 igraca
  71. CURRENT_LEVEL = 1 # trenutni nivo
  72. NUM_OF_PLAYERS = 2 # broj igraca
  73.  
  74. MONKEY_SPEED = 10
  75. LEVO_DESNO = 1
  76.  
  77. PLAYER_ID = 0
  78. PLAYER1_PIC = ''
  79. PLAYER2_PIC = ''
  80. PLAYER3_PIC = ''
  81. PLAYER4_PIC = ''
  82.  
  83.  
  84. def changeFrameTimems():
  85. global FRAME_TIME_MS
  86. FRAME_TIME_MS -= 1
  87.  
  88.  
  89. def returnPlayerLives():
  90. global PLAYER1_LIVES
  91. PLAYER1_LIVES = 3
  92.  
  93.  
  94. def returnPlayer2Lives():
  95. global PLAYER2_LIVES
  96. PLAYER2_LIVES = 3
  97.  
  98.  
  99. def changePlayer1Lives():
  100. global PLAYER1_LIVES
  101. if (PLAYER1_LIVES == 0):
  102. PLAYER1_LIVES = 0
  103. else:
  104. PLAYER1_LIVES -= 1
  105.  
  106.  
  107. def changePlayer2Lives():
  108. global PLAYER2_LIVES
  109. if (PLAYER2_LIVES == 0):
  110. PLAYER2_LIVES = 0
  111. else:
  112. PLAYER2_LIVES -= 1
  113.  
  114.  
  115. def changeGlobalPlus():
  116. global LEVEL
  117. LEVEL += 1
  118.  
  119.  
  120. def changeGlobalMinus():
  121. global LEVEL
  122. LEVEL -= 1
  123.  
  124.  
  125. def changeGlobalPlus2():
  126. global LEVEL2
  127. LEVEL2 += 1
  128.  
  129.  
  130. def changeGlobalMinus2():
  131. global LEVEL2
  132. LEVEL2 -= 1
  133.  
  134.  
  135. def changeDirection():
  136. global LEVO_DESNO
  137. if (LEVO_DESNO == 1):
  138. LEVO_DESNO = 0
  139. else:
  140. LEVO_DESNO = 1
  141.  
  142.  
  143. def upLevelPlayer1():
  144. global LEVEL_PLAYER1
  145. LEVEL_PLAYER1 += 1
  146.  
  147.  
  148. def ResetPlayer1Level():
  149. global LEVEL_PLAYER1
  150. LEVEL_PLAYER1 = 1
  151.  
  152.  
  153. def Player1Points():
  154. global POINTS1
  155. POINTS1 += 1
  156.  
  157.  
  158. def ResetPlayer1Points():
  159. global POINTS1
  160. POINTS1 = 0
  161.  
  162.  
  163. def setLevelTo1():
  164. global LEVEL
  165. LEVEL = 1
  166.  
  167.  
  168. def upLevelPlayer2():
  169. global LEVEL_PLAYER2
  170. LEVEL_PLAYER2 += 1
  171.  
  172.  
  173. def ResetPlayer2Level():
  174. global LEVEL_PLAYER2
  175. LEVEL_PLAYER2 = 1
  176.  
  177.  
  178. def Player2Points():
  179. global POINTS2
  180. POINTS2 += 1
  181.  
  182.  
  183. def ResetPlayer2Points():
  184. global POINTS2
  185. POINTS2 = 0
  186.  
  187.  
  188. def setLevelTo2():
  189. global LEVEL2
  190. LEVEL2 = 1
  191.  
  192.  
  193. def returnPlayer3Lives(): # kad igrac 3 dodje do princeze pocne novi nivo i on dobije 3 zivota
  194. global PLAYER3_LIVES
  195. PLAYER3_LIVES = 3
  196.  
  197.  
  198. def changePlayer3Lives(): # igrac 3 je izgubio 1 zivot
  199. global PLAYER3_LIVES
  200. if (PLAYER3_LIVES == 0):
  201. PLAYER3_LIVES = 0
  202. else:
  203. PLAYER3_LIVES -= 1
  204.  
  205.  
  206. def changeGlobalPlus3(): # povecava se platforma igraca 3
  207. global LEVEL3
  208. LEVEL3 += 1
  209.  
  210.  
  211. def changeGlobalMinus3(): # smanjuje se platforma igraca 3
  212. global LEVEL3
  213. LEVEL3 -= 1
  214.  
  215.  
  216. def upLevelPlayer3(): # povecava se platforma igraca 3 --ovo treba za poene
  217. global LEVEL_PLAYER3
  218. LEVEL_PLAYER3 += 1
  219.  
  220.  
  221. def ResetPlayer3Level(): # vrati platformu igraca 3 na pocetnu --ovo treba za poene
  222. global LEVEL_PLAYER3
  223. LEVEL_PLAYER3 = 1
  224.  
  225.  
  226. def Player3Points(): # povecaj poene igracu 3
  227. global POINTS3
  228. POINTS3 += 1
  229.  
  230.  
  231. def ResetPlayer3Points(): # resetuj poene igraca 3
  232. global POINTS3
  233. POINTS3 = 0
  234.  
  235.  
  236. def setLevelTo3(): # vrati platformu igraca 3 na pocetnu
  237. global LEVEL3
  238. LEVEL3 = 1
  239.  
  240.  
  241. def returnPlayer4Lives(): # kad igrac 4 dodje do princeze pocne novi nivo i on dobije 3 zivota
  242. global PLAYER4_LIVES
  243. PLAYER4_LIVES = 3
  244.  
  245.  
  246. def changePlayer4Lives(): # igrac 4 je izgubio 1 zivot
  247. global PLAYER4_LIVES
  248. if (PLAYER4_LIVES == 0):
  249. PLAYER4_LIVES = 0
  250. else:
  251. PLAYER4_LIVES -= 1
  252.  
  253.  
  254. def changeGlobalPlus4(): # povecava se platforma igraca 4
  255. global LEVEL4
  256. LEVEL4 += 1
  257.  
  258.  
  259. def changeGlobalMinus4(): # smanjuje se platforma igraca 4
  260. global LEVEL4
  261. LEVEL4 -= 1
  262.  
  263.  
  264. def upLevelPlayer4(): # povecava se platforma igraca 4 --ovo treba za poene
  265. global LEVEL_PLAYER4
  266. LEVEL_PLAYER4 += 1
  267.  
  268.  
  269. def ResetPlayer4Level(): # vrati platformu igraca 4 na pocetnu --ovo treba za poene
  270. global LEVEL_PLAYER4
  271. LEVEL_PLAYER4 = 1
  272.  
  273.  
  274. def Player4Points(): # povecaj poene igracu 4
  275. global POINTS4
  276. POINTS4 += 1
  277.  
  278.  
  279. def ResetPlayer4Points(): # resetuj poene igraca 4
  280. global POINTS4
  281. POINTS4 = 0
  282.  
  283.  
  284. def setLevelTo4(): # vrati platformu igraca 4 na pocetnu
  285. global LEVEL4
  286. LEVEL4 = 1
  287.  
  288.  
  289. def ChangeWinner(number): # promeni pobednika
  290. global WINNER
  291.  
  292. if (number == 0):
  293. WINNER = 0
  294. elif (number == 1):
  295. WINNER = 1
  296. elif (number == 2):
  297. WINNER = 2
  298. elif (number == 3):
  299. WINNER = 3
  300.  
  301.  
  302. def CurrentLVLUP(): # povecaj trenutni nivo
  303. global CURRENT_LEVEL
  304. CURRENT_LEVEL += 1
  305.  
  306.  
  307. class Player(QGraphicsPixmapItem):
  308. def __init__(self, parent=None):
  309. QGraphicsPixmapItem.__init__(self, parent)
  310. self.setPixmap(QPixmap("marioLeft.png"))
  311. global PLAYER1_PIC
  312. PLAYER1_PIC = "marioLeft.png"
  313.  
  314. def game_update(self, keys_pressed, coordinateX, label):
  315. dx = 0
  316. dy = 0
  317. global LEVEL
  318. global PLAYER1_PIC
  319.  
  320. if (LEVEL > LEVEL_PLAYER1):
  321. upLevelPlayer1()
  322. Player1Points()
  323. label.setNum(POINTS1)
  324.  
  325. if (POINTS1 == 0):
  326. label.setNum(POINTS1)
  327.  
  328. if (POINTS1 > 9):
  329. label.setGeometry(1210, 50, 100, 100)
  330. else:
  331. label.setGeometry(1240, 50, 100, 100)
  332.  
  333. if (PLAYER_ID == 1):
  334. if (LEVEL == 1 and PLAYER1_LIVES > 0):
  335. if Qt.Key_Left in keys_pressed and self.x() > 0 and self.y() == 848:
  336. dx -= PLAYER_SPEED
  337. self.setPixmap(QPixmap("marioLeft.png"))
  338. PLAYER1_PIC = "marioLeft.png"
  339. if Qt.Key_Right in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
  340. dx += PLAYER_SPEED
  341. self.setPixmap(QPixmap("marioRight.png"))
  342. PLAYER1_PIC = "marioRight.png"
  343. if Qt.Key_Up in keys_pressed and (
  344. self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
  345. dy -= PLAYER_SPEED
  346. self.setPixmap(QPixmap("marioClimb.png"))
  347. PLAYER1_PIC = "marioClimb.png"
  348. if Qt.Key_Down in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
  349. dy += PLAYER_SPEED
  350. self.setPixmap(QPixmap("marioClimb.png"))
  351. PLAYER1_PIC = "marioClimb.png"
  352. if self.y() == 652:
  353. changeGlobalPlus()
  354.  
  355. if (LEVEL == 2 and PLAYER1_LIVES > 0):
  356. if Qt.Key_Left in keys_pressed and self.x() > 45 and self.y() == 652:
  357. dx -= PLAYER_SPEED
  358. self.setPixmap(QPixmap("marioLeft.png"))
  359. PLAYER1_PIC = "marioLeft.png"
  360. if Qt.Key_Right in keys_pressed and self.x() < 1053 and self.y() == 652:
  361. dx += PLAYER_SPEED
  362. self.setPixmap(QPixmap("marioRight.png"))
  363. PLAYER1_PIC = "marioRight.png"
  364. if Qt.Key_Up in keys_pressed and (
  365. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
  366. int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
  367. dy -= PLAYER_SPEED
  368. self.setPixmap(QPixmap("marioClimb.png"))
  369. PLAYER1_PIC = "marioClimb.png"
  370. if Qt.Key_Down in keys_pressed and (
  371. (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
  372. or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
  373. or (
  374. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
  375. dy += PLAYER_SPEED
  376. self.setPixmap(QPixmap("marioClimb.png"))
  377. PLAYER1_PIC = "marioClimb.png"
  378. if self.y() > 652:
  379. changeGlobalMinus()
  380. if self.y() == 470:
  381. changeGlobalPlus()
  382.  
  383. if (LEVEL == 3 and PLAYER1_LIVES > 0):
  384. if Qt.Key_Left in keys_pressed and self.x() > 150 and self.y() == 470:
  385. dx -= PLAYER_SPEED
  386. self.setPixmap(QPixmap("marioLeft.png"))
  387. PLAYER1_PIC = "marioLeft.png"
  388. if Qt.Key_Right in keys_pressed and self.x() < 1158 and self.y() == 470:
  389. dx += PLAYER_SPEED
  390. self.setPixmap(QPixmap("marioRight.png"))
  391. PLAYER1_PIC = "marioRight.png"
  392. if Qt.Key_Up in keys_pressed and (
  393. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
  394. int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
  395. dy -= PLAYER_SPEED
  396. self.setPixmap(QPixmap("marioClimb.png"))
  397. PLAYER1_PIC = "marioClimb.png"
  398. if Qt.Key_Down in keys_pressed and ((self.y() == 470 and (
  399. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
  400. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
  401. or (
  402. self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
  403. or (
  404. self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
  405. dy += PLAYER_SPEED
  406. self.setPixmap(QPixmap("marioClimb.png"))
  407. PLAYER1_PIC = "marioClimb.png"
  408. if self.y() > 470:
  409. changeGlobalMinus()
  410. if self.y() == 274:
  411. changeGlobalPlus()
  412.  
  413. if (LEVEL == 4 and PLAYER1_LIVES > 0):
  414. if Qt.Key_Left in keys_pressed and self.x() > 38 and self.y() == 274:
  415. dx -= PLAYER_SPEED
  416. self.setPixmap(QPixmap("marioLeft.png"))
  417. PLAYER1_PIC = "marioLeft.png"
  418. if Qt.Key_Right in keys_pressed and self.x() < 1053 and self.y() == 274:
  419. dx += PLAYER_SPEED
  420. self.setPixmap(QPixmap("marioRight.png"))
  421. PLAYER1_PIC = "marioRight.png"
  422. if Qt.Key_Up in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
  423. dy -= PLAYER_SPEED
  424. self.setPixmap(QPixmap("marioClimb.png"))
  425. PLAYER1_PIC = "marioClimb.png"
  426. if Qt.Key_Down in keys_pressed and ((self.y() == 274 and (
  427. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
  428. int(coordinateX[4]) - 44, int(coordinateX[4])))
  429. or (self.y() < 274 and self.x() in range(210, 254))):
  430. dy += PLAYER_SPEED
  431. self.setPixmap(QPixmap("marioClimb.png"))
  432. PLAYER1_PIC = "marioClimb.png"
  433. if self.y() > 274:
  434. changeGlobalMinus()
  435. if self.y() <= 50:
  436. changeGlobalPlus()
  437.  
  438. if (LEVEL == 5 and PLAYER1_LIVES > 0):
  439. if Qt.Key_Left in keys_pressed and self.x() > 227 and self.y() == 50:
  440. dx -= PLAYER_SPEED
  441. self.setPixmap(QPixmap("marioLeft.png"))
  442. PLAYER1_PIC = "marioLeft.png"
  443. if Qt.Key_Right in keys_pressed and self.x() < 528 and self.y() == 50:
  444. dx += PLAYER_SPEED
  445. self.setPixmap(QPixmap("marioRight.png"))
  446. PLAYER1_PIC = "marioRight.png"
  447. if Qt.Key_Down in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
  448. dy += PLAYER_SPEED
  449. self.setPixmap(QPixmap("marioClimb.png"))
  450. PLAYER1_PIC = "marioClimb.png"
  451. if self.y() > 50:
  452. changeGlobalMinus()
  453. self.setPos(self.x() + dx, self.y() + dy)
  454.  
  455.  
  456. class Player2(QGraphicsPixmapItem):
  457. def __init__(self, parent=None):
  458. QGraphicsPixmapItem.__init__(self, parent)
  459. self.setPixmap(QPixmap("luigiRight.png"))
  460. global PLAYER2_PIC
  461. PLAYER2_PIC = "luigiRight.png"
  462.  
  463. def game_update(self, keys_pressed, coordinateX, label):
  464. dx = 0
  465. dy = 0
  466. global LEVEL2
  467. global PLAYER2_PIC
  468.  
  469. if (LEVEL2 > LEVEL_PLAYER2):
  470. upLevelPlayer2()
  471. Player2Points()
  472. label.setNum(POINTS2)
  473.  
  474. if (POINTS2 == 0):
  475. label.setNum(POINTS2)
  476.  
  477. if (PLAYER_ID == 2):
  478. if (LEVEL2 == 1 and PLAYER2_LIVES > 0):
  479. if Qt.Key_A in keys_pressed and self.x() > 0 and self.y() == 848:
  480. dx -= PLAYER_SPEED
  481. self.setPixmap(QPixmap("luigiLeft.png"))
  482. PLAYER2_PIC = "luigiLeft.png"
  483. if Qt.Key_D in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
  484. dx += PLAYER_SPEED
  485. self.setPixmap(QPixmap("luigiRight.png"))
  486. PLAYER2_PIC = "luigiRight.png"
  487. if Qt.Key_W in keys_pressed and (
  488. self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
  489. dy -= PLAYER_SPEED
  490. self.setPixmap(QPixmap("luigiClimb.png"))
  491. PLAYER2_PIC = "luigiClimb.png"
  492. if Qt.Key_S in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
  493. dy += PLAYER_SPEED
  494. self.setPixmap(QPixmap("luigiClimb.png"))
  495. PLAYER2_PIC = "luigiClimb.png"
  496. if self.y() == 652:
  497. changeGlobalPlus2()
  498.  
  499. if (LEVEL2 == 2 and PLAYER2_LIVES > 0):
  500. if Qt.Key_A in keys_pressed and self.x() > 45 and self.y() == 652:
  501. dx -= PLAYER_SPEED
  502. self.setPixmap(QPixmap("luigiLeft.png"))
  503. PLAYER2_PIC = "luigiLeft.png"
  504. if Qt.Key_D in keys_pressed and self.x() < 1053 and self.y() == 652:
  505. dx += PLAYER_SPEED
  506. self.setPixmap(QPixmap("luigiRight.png"))
  507. PLAYER2_PIC = "luigiRight.png"
  508. if Qt.Key_W in keys_pressed and (
  509. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
  510. int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
  511. dy -= PLAYER_SPEED
  512. self.setPixmap(QPixmap("luigiClimb.png"))
  513. PLAYER2_PIC = "luigiClimb.png"
  514. if Qt.Key_S in keys_pressed and (
  515. (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
  516. or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
  517. or (
  518. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
  519. dy += PLAYER_SPEED
  520. self.setPixmap(QPixmap("luigiClimb.png"))
  521. PLAYER2_PIC = "luigiClimb.png"
  522. if self.y() > 652:
  523. changeGlobalMinus2()
  524. if self.y() == 470:
  525. changeGlobalPlus2()
  526.  
  527. if (LEVEL2 == 3 and PLAYER2_LIVES > 0):
  528. if Qt.Key_A in keys_pressed and self.x() > 150 and self.y() == 470:
  529. dx -= PLAYER_SPEED
  530. self.setPixmap(QPixmap("luigiLeft.png"))
  531. PLAYER2_PIC = "luigiLeft.png"
  532. if Qt.Key_D in keys_pressed and self.x() < 1158 and self.y() == 470:
  533. dx += PLAYER_SPEED
  534. self.setPixmap(QPixmap("luigiRight.png"))
  535. PLAYER2_PIC = "luigiRight.png"
  536. if Qt.Key_W in keys_pressed and (
  537. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
  538. int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
  539. dy -= PLAYER_SPEED
  540. self.setPixmap(QPixmap("luigiClimb.png"))
  541. PLAYER2_PIC = "luigiClimb.png"
  542. if Qt.Key_S in keys_pressed and ((self.y() == 470 and (
  543. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
  544. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
  545. or (
  546. self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
  547. or (
  548. self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
  549. dy += PLAYER_SPEED
  550. self.setPixmap(QPixmap("luigiClimb.png"))
  551. PLAYER2_PIC = "luigiClimb.png"
  552. if self.y() > 470:
  553. changeGlobalMinus2()
  554. if self.y() == 274:
  555. changeGlobalPlus2()
  556.  
  557. if (LEVEL2 == 4 and PLAYER2_LIVES > 0):
  558. if Qt.Key_A in keys_pressed and self.x() > 38 and self.y() == 274:
  559. dx -= PLAYER_SPEED
  560. self.setPixmap(QPixmap("luigiLeft.png"))
  561. PLAYER2_PIC = "luigiLeft.png"
  562. if Qt.Key_D in keys_pressed and self.x() < 1053 and self.y() == 274:
  563. dx += PLAYER_SPEED
  564. self.setPixmap(QPixmap("luigiRight.png"))
  565. PLAYER2_PIC = "luigiRight.png"
  566. if Qt.Key_W in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
  567. dy -= PLAYER_SPEED
  568. self.setPixmap(QPixmap("luigiClimb.png"))
  569. PLAYER2_PIC = "luigiClimb.png"
  570. if Qt.Key_S in keys_pressed and ((self.y() == 274 and (
  571. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
  572. int(coordinateX[4]) - 44, int(coordinateX[4])))
  573. or (self.y() < 274 and self.x() in range(210, 254))):
  574. dy += PLAYER_SPEED
  575. self.setPixmap(QPixmap("luigiClimb.png"))
  576. PLAYER2_PIC = "luigiClimb.png"
  577. if self.y() > 274:
  578. changeGlobalMinus2()
  579. if self.y() <= 50:
  580. changeGlobalPlus2()
  581.  
  582. if (LEVEL2 == 5 and PLAYER2_LIVES > 0):
  583. if Qt.Key_A in keys_pressed and self.x() > 227 and self.y() == 50:
  584. dx -= PLAYER_SPEED
  585. self.setPixmap(QPixmap("luigiLeft.png"))
  586. PLAYER2_PIC = "luigiLeft.png"
  587. if Qt.Key_D in keys_pressed and self.x() < 528 and self.y() == 50:
  588. dx += PLAYER_SPEED
  589. self.setPixmap(QPixmap("luigiRight.png"))
  590. PLAYER2_PIC = "luigiRight.png"
  591. if Qt.Key_S in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
  592. dy += PLAYER_SPEED
  593. self.setPixmap(QPixmap("luigiClimb.png"))
  594. PLAYER2_PIC = "luigiClimb.png"
  595. if self.y() > 50:
  596. changeGlobalMinus2()
  597.  
  598. self.setPos(self.x() + dx, self.y() + dy)
  599.  
  600.  
  601. class Player3(QGraphicsPixmapItem):
  602. def __init__(self, parent=None):
  603. QGraphicsPixmapItem.__init__(self, parent)
  604. self.setPixmap(QPixmap("blueLeft.png"))
  605. global PLAYER3_PIC
  606. PLAYER3_PIC = "blueLeft.png"
  607.  
  608. def game_update(self, keys_pressed, coordinateX, label):
  609. dx = 0
  610. dy = 0
  611. global LEVEL3
  612. global PLAYER3_PIC
  613.  
  614. if (LEVEL3 > LEVEL_PLAYER3):
  615. upLevelPlayer3()
  616. Player3Points()
  617. label.setNum(POINTS3)
  618.  
  619. if (POINTS3 == 0):
  620. label.setNum(POINTS3)
  621.  
  622. if (POINTS3 > 9):
  623. label.setGeometry(1050, 50, 100, 100)
  624. else:
  625. label.setGeometry(1080, 50, 100, 100)
  626.  
  627. if (PLAYER_ID == 3):
  628. if (LEVEL3 == 1 and PLAYER3_LIVES > 0):
  629. if Qt.Key_4 in keys_pressed and self.x() > 0 and self.y() == 848:
  630. dx -= PLAYER_SPEED
  631. self.setPixmap(QPixmap("blueLeft.png"))
  632. PLAYER3_PIC = "blueLeft.png"
  633. if Qt.Key_6 in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
  634. dx += PLAYER_SPEED
  635. self.setPixmap(QPixmap("blueRight.png"))
  636. PLAYER3_PIC = "blueRight.png"
  637. if Qt.Key_8 in keys_pressed and (
  638. self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
  639. dy -= PLAYER_SPEED
  640. self.setPixmap(QPixmap("blueClimb.png"))
  641. PLAYER3_PIC = "blueClimb.png"
  642. if Qt.Key_5 in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
  643. dy += PLAYER_SPEED
  644. self.setPixmap(QPixmap("blueClimb.png"))
  645. PLAYER3_PIC = "blueClimb.png"
  646. if self.y() == 652:
  647. changeGlobalPlus3()
  648.  
  649. if (LEVEL3 == 2 and PLAYER3_LIVES > 0):
  650. if Qt.Key_4 in keys_pressed and self.x() > 45 and self.y() == 652:
  651. dx -= PLAYER_SPEED
  652. self.setPixmap(QPixmap("blueLeft.png"))
  653. PLAYER3_PIC = "blueLeft.png"
  654. if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 652:
  655. dx += PLAYER_SPEED
  656. self.setPixmap(QPixmap("blueRight.png"))
  657. PLAYER3_PIC = "blueRight.png"
  658. if Qt.Key_8 in keys_pressed and (
  659. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
  660. int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
  661. dy -= PLAYER_SPEED
  662. self.setPixmap(QPixmap("blueClimb.png"))
  663. PLAYER3_PIC = "blueClimb.png"
  664. if Qt.Key_5 in keys_pressed and (
  665. (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
  666. or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
  667. or (
  668. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
  669. dy += PLAYER_SPEED
  670. self.setPixmap(QPixmap("blueClimb.png"))
  671. PLAYER3_PIC = "blueClimb.png"
  672. if self.y() > 652:
  673. changeGlobalMinus3()
  674. if self.y() == 470:
  675. changeGlobalPlus3()
  676.  
  677. if (LEVEL3 == 3 and PLAYER3_LIVES > 0):
  678. if Qt.Key_4 in keys_pressed and self.x() > 45 and self.y() == 652:
  679. dx -= PLAYER_SPEED
  680. self.setPixmap(QPixmap("blueLeft.png"))
  681. PLAYER3_PIC = "blueLeft.png"
  682. if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 652:
  683. dx += PLAYER_SPEED
  684. self.setPixmap(QPixmap("blueRight.png"))
  685. PLAYER3_PIC = "blueRight.png"
  686. if Qt.Key_8 in keys_pressed and (
  687. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
  688. int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
  689. dy -= PLAYER_SPEED
  690. self.setPixmap(QPixmap("blueClimb.png"))
  691. PLAYER3_PIC = "blueClimb.png"
  692. if Qt.Key_5 in keys_pressed and (
  693. (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
  694. or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
  695. or (
  696. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
  697. dy += PLAYER_SPEED
  698. self.setPixmap(QPixmap("blueClimb.png"))
  699. PLAYER3_PIC = "blueClimb.png"
  700. if self.y() > 470:
  701. changeGlobalMinus3()
  702. if self.y() == 274:
  703. changeGlobalPlus3()
  704.  
  705. if (LEVEL3 == 4 and PLAYER3_LIVES > 0):
  706. if Qt.Key_4 in keys_pressed and self.x() > 38 and self.y() == 274:
  707. dx -= PLAYER_SPEED
  708. self.setPixmap(QPixmap("blueLeft.png"))
  709. PLAYER3_PIC = "blueLeft.png"
  710. if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 274:
  711. dx += PLAYER_SPEED
  712. self.setPixmap(QPixmap("blueRight.png"))
  713. PLAYER3_PIC = "blueRight.png"
  714. if Qt.Key_8 in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
  715. dy -= PLAYER_SPEED
  716. self.setPixmap(QPixmap("blueClimb.png"))
  717. PLAYER3_PIC = "blueClimb.png"
  718. if Qt.Key_5 in keys_pressed and ((self.y() == 274 and (
  719. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
  720. int(coordinateX[4]) - 44, int(coordinateX[4])))
  721. or (self.y() < 274 and self.x() in range(210, 254))):
  722. dy += PLAYER_SPEED
  723. self.setPixmap(QPixmap("blueClimb.png"))
  724. PLAYER3_PIC = "blueClimb.png"
  725. if self.y() > 274:
  726. changeGlobalMinus3()
  727. if self.y() <= 50:
  728. changeGlobalPlus3()
  729.  
  730. if (LEVEL3 == 5 and PLAYER3_LIVES > 0):
  731. if Qt.Key_4 in keys_pressed and self.x() > 227 and self.y() == 50:
  732. dx -= PLAYER_SPEED
  733. self.setPixmap(QPixmap("blueLeft.png"))
  734. PLAYER3_PIC = "blueLeft.png"
  735. if Qt.Key_6 in keys_pressed and self.x() < 528 and self.y() == 50:
  736. dx += PLAYER_SPEED
  737. self.setPixmap(QPixmap("blueRight.png"))
  738. PLAYER3_PIC = "blueRight.png"
  739. if Qt.Key_5 in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
  740. dy += PLAYER_SPEED
  741. self.setPixmap(QPixmap("blueClimb.png"))
  742. PLAYER3_PIC = "blueClimb.png"
  743. if self.y() > 50:
  744. changeGlobalMinus3()
  745.  
  746. self.setPos(self.x() + dx, self.y() + dy)
  747.  
  748.  
  749. class Player4(QGraphicsPixmapItem):
  750. def __init__(self, parent=None):
  751. QGraphicsPixmapItem.__init__(self, parent)
  752. self.setPixmap(QPixmap("purpleRight.png"))
  753.  
  754. def game_update(self, keys_pressed, coordinateX, label):
  755. dx = 0
  756. dy = 0
  757. global LEVEL4
  758.  
  759. if (LEVEL4 > LEVEL_PLAYER4):
  760. upLevelPlayer4()
  761. Player4Points()
  762. label.setNum(POINTS4)
  763.  
  764. if (POINTS4 == 0):
  765. label.setNum(POINTS4)
  766.  
  767. if (LEVEL4 == 1 and PLAYER4_LIVES > 0):
  768. if Qt.Key_J in keys_pressed and self.x() > 0 and self.y() == 848:
  769. dx -= PLAYER_SPEED
  770. self.setPixmap(QPixmap("purpleLeft.png"))
  771. if Qt.Key_L in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
  772. dx += PLAYER_SPEED
  773. self.setPixmap(QPixmap("purpleRight.png"))
  774. if Qt.Key_I in keys_pressed and (
  775. self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
  776. dy -= PLAYER_SPEED
  777. self.setPixmap(QPixmap("purpleClimb.png"))
  778. if Qt.Key_K in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
  779. dy += PLAYER_SPEED
  780. self.setPixmap(QPixmap("purpleClimb.png"))
  781. if self.y() == 652:
  782. changeGlobalPlus4()
  783.  
  784. self.setPos(self.x() + dx, self.y() + dy)
  785.  
  786. if (LEVEL4 == 2 and PLAYER4_LIVES > 0):
  787. if Qt.Key_J in keys_pressed and self.x() > 45 and self.y() == 652:
  788. dx -= PLAYER_SPEED
  789. self.setPixmap(QPixmap("purpleLeft.png"))
  790. if Qt.Key_L in keys_pressed and self.x() < 1053 and self.y() == 652:
  791. dx += PLAYER_SPEED
  792. self.setPixmap(QPixmap("purpleRight.png"))
  793. if Qt.Key_I in keys_pressed and (
  794. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
  795. int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
  796. dy -= PLAYER_SPEED
  797. self.setPixmap(QPixmap("purpleClimb.png"))
  798. if Qt.Key_K in keys_pressed and (
  799. (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
  800. or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
  801. or (self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
  802. dy += PLAYER_SPEED
  803. self.setPixmap(QPixmap("purpleClimb.png"))
  804. if self.y() > 652:
  805. changeGlobalMinus4()
  806. if self.y() == 470:
  807. changeGlobalPlus4()
  808.  
  809. self.setPos(self.x() + dx, self.y() + dy)
  810.  
  811. if (LEVEL4 == 3 and PLAYER4_LIVES > 0):
  812. if Qt.Key_J in keys_pressed and self.x() > 150 and self.y() == 470:
  813. dx -= PLAYER_SPEED
  814. self.setPixmap(QPixmap("purpleLeft.png"))
  815. if Qt.Key_L in keys_pressed and self.x() < 1158 and self.y() == 470:
  816. dx += PLAYER_SPEED
  817. self.setPixmap(QPixmap("purpleRight.png"))
  818. if Qt.Key_I in keys_pressed and (
  819. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
  820. int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
  821. dy -= PLAYER_SPEED
  822. self.setPixmap(QPixmap("purpleClimb.png"))
  823. if Qt.Key_K in keys_pressed and ((self.y() == 470 and (
  824. self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
  825. self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
  826. or (
  827. self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
  828. or (self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
  829. dy += PLAYER_SPEED
  830. self.setPixmap(QPixmap("purpleClimb.png"))
  831. if self.y() > 470:
  832. changeGlobalMinus4()
  833. if self.y() == 274:
  834. changeGlobalPlus4()
  835.  
  836. self.setPos(self.x() + dx, self.y() + dy)
  837.  
  838. if (LEVEL4 == 4 and PLAYER4_LIVES > 0):
  839. if Qt.Key_J in keys_pressed and self.x() > 38 and self.y() == 274:
  840. dx -= PLAYER_SPEED
  841. self.setPixmap(QPixmap("purpleLeft.png"))
  842. if Qt.Key_L in keys_pressed and self.x() < 1053 and self.y() == 274:
  843. dx += PLAYER_SPEED
  844. self.setPixmap(QPixmap("purpleRight.png"))
  845. if Qt.Key_I in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
  846. dy -= PLAYER_SPEED
  847. self.setPixmap(QPixmap("purpleClimb.png"))
  848. if Qt.Key_K in keys_pressed and ((self.y() == 274 and (
  849. self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
  850. int(coordinateX[4]) - 44, int(coordinateX[4])))
  851. or (self.y() < 274 and self.x() in range(210, 254))):
  852. dy += PLAYER_SPEED
  853. self.setPixmap(QPixmap("purpleClimb.png"))
  854. if self.y() > 274:
  855. changeGlobalMinus4()
  856. if self.y() <= 50:
  857. changeGlobalPlus4()
  858.  
  859. self.setPos(self.x() + dx, self.y() + dy)
  860.  
  861. if (LEVEL4 == 5 and PLAYER4_LIVES > 0):
  862. if Qt.Key_J in keys_pressed and self.x() > 227 and self.y() == 50:
  863. dx -= PLAYER_SPEED
  864. self.setPixmap(QPixmap("purpleLeft.png"))
  865. if Qt.Key_L in keys_pressed and self.x() < 528 and self.y() == 50:
  866. dx += PLAYER_SPEED
  867. self.setPixmap(QPixmap("purpleRight.png"))
  868. if Qt.Key_K in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
  869. dy += PLAYER_SPEED
  870. self.setPixmap(QPixmap("purpleClimb.png"))
  871. if self.y() > 50:
  872. changeGlobalMinus4()
  873.  
  874. self.setPos(self.x() + dx, self.y() + dy)
  875.  
  876.  
  877. class PlayerDonkey(QGraphicsPixmapItem):
  878. def __init__(self, q: mp.Queue, parent=None):
  879. QGraphicsPixmapItem.__init__(self, parent)
  880. self.setPixmap(QPixmap("donkey.png"))
  881. self.queue = q
  882.  
  883. def game_update(self, keys_pressed, marioPos, luigiPos, scena, bluePos, purplePos):
  884. dx = 0
  885. dy = 0
  886.  
  887. num = self.queue.get()
  888. if (int(num) >= 980):
  889. changeDirection()
  890. if (int(num) <= 110):
  891. changeDirection()
  892.  
  893. if ((PLAYER1_LIVES > 0) and (
  894. int(self.y()) == (int(marioPos.y()) - 39) and self.x() in range(int(marioPos.x()) - 20,
  895. int(marioPos.x()) + 20))):
  896. changePlayer1Lives()
  897. ResetPlayer1Level()
  898. ResetPlayer1Points()
  899. setLevelTo1()
  900. # time.sleep(0.5)
  901. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
  902. scena.removeItem(scena.label.hide())
  903. scena.removeItem(scena.label2.hide())
  904. scena.removeItem(marioPos)
  905.  
  906. if (WINNER == 0):
  907. pic = QPixmap("marioWins")
  908. else:
  909. pic = QPixmap("luigiWins")
  910.  
  911. # pic = QPixmap("gameOver.png")
  912. scena.addItem(QGraphicsPixmapItem(pic))
  913. elif (PLAYER1_LIVES == 0):
  914. scena.removeItem(marioPos)
  915. scena.removeItem(scena.label.hide())
  916.  
  917. else:
  918. marioPos.setPos(SCREEN_WIDTH - 80,
  919. SCREEN_HEIGHT - 130)
  920. marioPos.setPixmap(QPixmap("marioLeft.png"))
  921.  
  922. if ((PLAYER2_LIVES > 0) and (
  923. int(self.y()) == (int(luigiPos.y()) - 39) and self.x() in range(int(luigiPos.x()) - 20,
  924. int(luigiPos.x()) + 20))):
  925. changePlayer2Lives()
  926. ResetPlayer2Level()
  927. ResetPlayer2Points()
  928. setLevelTo2()
  929. # time.sleep(0.5)
  930.  
  931. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
  932. scena.removeItem(scena.label.hide())
  933. scena.removeItem(scena.label2.hide())
  934. scena.removeItem(luigiPos)
  935.  
  936. if (WINNER == 0):
  937. pic = QPixmap("marioWins")
  938. else:
  939. pic = QPixmap("luigiWins")
  940.  
  941. # pic = QPixmap("gameOver.png")
  942. scena.addItem(QGraphicsPixmapItem(pic))
  943. elif (PLAYER2_LIVES == 0):
  944. scena.removeItem(luigiPos)
  945. scena.removeItem(scena.label2.hide())
  946. else:
  947. luigiPos.setPos(30, 848)
  948. luigiPos.setPixmap(QPixmap("luigiRight.png"))
  949.  
  950. if ((PLAYER3_LIVES > 0) and (
  951. int(self.y()) == (int(bluePos.y()) - 39) and self.x() in range(int(bluePos.x()) - 20,
  952. int(bluePos.x()) + 20))):
  953. changePlayer3Lives()
  954. ResetPlayer3Level()
  955. ResetPlayer3Points()
  956. setLevelTo3()
  957. time.sleep(0.5)
  958.  
  959. if (PLAYER3_LIVES == 0):
  960. scena.removeItem(bluePos)
  961. scena.removeItem(scena.label5.hide())
  962. else:
  963. bluePos.setPos(SCREEN_WIDTH - 150,
  964. SCREEN_HEIGHT - 130)
  965. bluePos.setPixmap(QPixmap("blueLeft.png"))
  966.  
  967. if ((PLAYER4_LIVES > 0) and (
  968. int(self.y()) == (int(purplePos.y()) - 39) and self.x() in range(int(purplePos.x()) - 20,
  969. int(purplePos.x()) + 20))):
  970. changePlayer4Lives()
  971. ResetPlayer4Level()
  972. ResetPlayer4Points()
  973. setLevelTo4()
  974. time.sleep(0.5)
  975.  
  976. if (PLAYER4_LIVES == 0):
  977. scena.removeItem(purplePos)
  978. scena.removeItem(scena.label6.hide())
  979. else:
  980. purplePos.setPos(70, 848)
  981. purplePos.setPixmap(QPixmap("purpleRight.png"))
  982.  
  983. if (int(NUM_OF_PLAYERS) == 2):
  984. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
  985. if (WINNER == 0):
  986. pic = QPixmap("marioWins")
  987. else:
  988. pic = QPixmap("luigiWins")
  989.  
  990. scena.addItem(QGraphicsPixmapItem(pic))
  991. elif (int(NUM_OF_PLAYERS) == 3):
  992. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0):
  993. if (WINNER == 0):
  994. pic = QPixmap("marioWins")
  995. elif (WINNER == 1):
  996. pic = QPixmap("luigiWins")
  997. else:
  998. pic = QPixmap("blueWins")
  999.  
  1000. scena.addItem(QGraphicsPixmapItem(pic))
  1001. elif (int(NUM_OF_PLAYERS) == 4):
  1002. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0 and PLAYER4_LIVES == 0):
  1003. if (WINNER == 0):
  1004. pic = QPixmap("marioWins")
  1005. elif (WINNER == 1):
  1006. pic = QPixmap("luigiWins")
  1007. elif (WINNER == 2):
  1008. pic = QPixmap("blueWins")
  1009. else:
  1010. pic = QPixmap("purpleWins")
  1011.  
  1012. scena.addItem(QGraphicsPixmapItem(pic))
  1013.  
  1014. self.setPos(num, self.y() + dy)
  1015.  
  1016.  
  1017. def donkeyRunner(queue: mp.Queue, zaSkidanje: mp.Queue, levodesno: mp.Queue):
  1018. print("funkcija za queue: ", current_process().pid)
  1019. while True:
  1020. dx = 0
  1021. ld = levodesno.get()
  1022. koordinata = zaSkidanje.get()
  1023. if (koordinata <= 980 and ld == 1):
  1024. dx += MONKEY_SPEED
  1025. if (ld == 0):
  1026. dx -= MONKEY_SPEED
  1027.  
  1028. queue.put(koordinata + dx)
  1029.  
  1030.  
  1031. class PlayerPrincess(QGraphicsPixmapItem):
  1032. def __init__(self, parent=None):
  1033. QGraphicsPixmapItem.__init__(self, parent)
  1034. self.setPixmap(QPixmap("princessHandsDown.png"))
  1035.  
  1036. def game_update(self, playerDX, playerX, playerY, marioPos, player2X, player2Y, luigiPos, scena, label,
  1037. player3X, player3Y, bluePos, player4X, player4Y, purplePos):
  1038. dx = 0
  1039. dy = 0
  1040.  
  1041. if (int(playerDX) in range(100, 200) or int(playerDX) in range(500, 600)):
  1042. self.setPixmap(QPixmap("princessHandsUp.png"))
  1043. else:
  1044. self.setPixmap(QPixmap("princessHandsDown.png"))
  1045.  
  1046. if (int(playerX) in range(440, 520) and playerY == 50):
  1047. # time.sleep(0.5)
  1048. changeFrameTimems()
  1049. returnPlayerLives()
  1050. ResetPlayer1Level()
  1051. setLevelTo1()
  1052. CurrentLVLUP()
  1053. time.sleep(0.1)
  1054.  
  1055. # label.setNum(CURRENT_LEVEL)
  1056.  
  1057. scena.timer.start(FRAME_TIME_MS, scena)
  1058. marioPos.setPos(SCREEN_WIDTH - 80,
  1059. SCREEN_HEIGHT - 130)
  1060. marioPos.setPixmap(QPixmap("marioLeft.png"))
  1061.  
  1062. if (int(player2X) in range(440, 520) and player2Y == 50):
  1063. # time.sleep(0.5)
  1064. changeFrameTimems()
  1065. returnPlayer2Lives()
  1066. ResetPlayer2Level()
  1067. setLevelTo2()
  1068. CurrentLVLUP()
  1069. time.sleep(0.1)
  1070.  
  1071. # label.setNum(CURRENT_LEVEL)
  1072.  
  1073. scena.timer.start(FRAME_TIME_MS, scena)
  1074. luigiPos.setPos(30, 848)
  1075. luigiPos.setPixmap(QPixmap("luigiRight.png"))
  1076.  
  1077. if (player3X == 500 and player3Y == 50):
  1078. # time.sleep(0.5)
  1079. changeFrameTimems()
  1080. returnPlayer3Lives()
  1081. ResetPlayer3Level()
  1082. setLevelTo3()
  1083. CurrentLVLUP()
  1084.  
  1085. # label.setNum(CURRENT_LEVEL)
  1086.  
  1087. scena.timer.start(FRAME_TIME_MS, scena)
  1088. bluePos.setPos(SCREEN_WIDTH - 150,
  1089. SCREEN_HEIGHT - 130)
  1090. bluePos.setPixmap(QPixmap("blueLeft.png"))
  1091.  
  1092. if (player4X == 462 and player4Y == 50):
  1093. # time.sleep(0.5)
  1094. changeFrameTimems()
  1095. returnPlayer4Lives()
  1096. ResetPlayer4Level()
  1097. setLevelTo4()
  1098. CurrentLVLUP()
  1099.  
  1100. # label.setNum(CURRENT_LEVEL)
  1101.  
  1102. scena.timer.start(FRAME_TIME_MS, scena)
  1103. purplePos.setPos(70, 848)
  1104. purplePos.setPixmap(QPixmap("purpleRight.png"))
  1105.  
  1106.  
  1107. class Player1Lives(QGraphicsPixmapItem):
  1108. def __init__(self, q: mp.Queue, parent=None):
  1109. QGraphicsPixmapItem.__init__(self, parent)
  1110. self.setPos(1160, 10)
  1111. self.queue = q
  1112.  
  1113. def listen(self):
  1114. num = self.queue.get()
  1115. self.game_update(num)
  1116.  
  1117. def game_update(self, num):
  1118. broj = num
  1119. if (broj == 3):
  1120. self.setPixmap(QPixmap("3heart.png"))
  1121. self.setPos(1160, 10)
  1122. elif (broj == 2):
  1123. self.setPixmap(QPixmap("2heart.png"))
  1124. self.setPos(1200, 10)
  1125. elif (broj == 1):
  1126. self.setPixmap(QPixmap("1heart.png"))
  1127. self.setPos(1240, 10)
  1128. else:
  1129. ChangeWinner()
  1130. self.hide()
  1131.  
  1132.  
  1133. def runner2(queue: mp.Queue, zaSkidanje: mp.Queue):
  1134. print("funkcija za queue: ", current_process().pid)
  1135. while True:
  1136. broj = zaSkidanje.get()
  1137. queue.put(broj)
  1138.  
  1139.  
  1140. class Player2Lives(QGraphicsPixmapItem):
  1141. def __init__(self, q: mp.Queue, parent=None):
  1142. QGraphicsPixmapItem.__init__(self, parent)
  1143. self.queue = q
  1144.  
  1145. def listen(self):
  1146. num = self.queue.get()
  1147. self.game_update(num)
  1148.  
  1149. def game_update(self, num):
  1150. broj = num
  1151. if (broj == 3):
  1152. self.setPixmap(QPixmap("3heartGreen.png"))
  1153. self.setPos(10, 10)
  1154. elif (broj == 2):
  1155. self.setPixmap(QPixmap("2heartGreen.png"))
  1156. self.setPos(10, 10)
  1157. elif (broj == 1):
  1158. self.setPixmap(QPixmap("1heartGreen.png"))
  1159. self.setPos(10, 10)
  1160. else:
  1161. self.hide()
  1162.  
  1163.  
  1164. class Player3Lives(QGraphicsPixmapItem):
  1165. def __init__(self, parent=None):
  1166. QGraphicsPixmapItem.__init__(self, parent)
  1167.  
  1168. def game_update(self):
  1169. if (PLAYER3_LIVES == 3):
  1170. self.setPixmap(QPixmap("3heartGreenBlue.png"))
  1171. self.setPos(1000, 10)
  1172. elif (PLAYER3_LIVES == 2):
  1173. self.setPixmap(QPixmap("2heartGreenBlue.png"))
  1174. self.setPos(1040, 10)
  1175. elif (PLAYER3_LIVES == 1):
  1176. self.setPixmap(QPixmap("1heartBlue.png"))
  1177. self.setPos(1080, 10)
  1178. else:
  1179. ChangeWinner(2)
  1180. self.hide()
  1181.  
  1182.  
  1183. class Player4Lives(QGraphicsPixmapItem):
  1184. def __init__(self, parent=None):
  1185. QGraphicsPixmapItem.__init__(self, parent)
  1186.  
  1187. def game_update(self):
  1188. if (PLAYER4_LIVES == 3):
  1189. self.setPixmap(QPixmap("3heartPurple.png"))
  1190. self.setPos(150, 10)
  1191. elif (PLAYER4_LIVES == 2):
  1192. self.setPixmap(QPixmap("2heartPurple.png"))
  1193. self.setPos(150, 10)
  1194. elif (PLAYER4_LIVES == 1):
  1195. self.setPixmap(QPixmap("1heartPurple.png"))
  1196. self.setPos(150, 10)
  1197. else:
  1198. ChangeWinner(3)
  1199. self.hide()
  1200.  
  1201.  
  1202. def runner(queue: mp.Queue, zaSkidanje: mp.Queue):
  1203. print("funkcija za queue: ", current_process().pid)
  1204. while True:
  1205. broj = zaSkidanje.get()
  1206. queue.put(broj)
  1207.  
  1208.  
  1209. class Bullet(QGraphicsPixmapItem):
  1210. def __init__(self, offset_x, offset_y, parent=None):
  1211. QGraphicsPixmapItem.__init__(self, parent)
  1212. self.setPixmap(QPixmap("barrel.png"))
  1213. self.offset_x = offset_x
  1214. self.offset_y = offset_y
  1215. self.active = False
  1216. self.frames = 0
  1217.  
  1218. def game_update(self, timer, player, playerP, player2, scena, player3, player4):
  1219. if not self.active:
  1220. if timer.isActive():
  1221. self.active = True
  1222. self.setPos(player.x(), player.y() + 50)
  1223. self.frames = BULLET_FRAMES
  1224. else:
  1225. self.setPos(self.x(), self.y() + BULLET_SPEED)
  1226. self.frames -= 1
  1227. if ((self.y() in range(int(playerP.y()), int(playerP.y()) + 80) and self.x() in range(int(playerP.x()) - 40,
  1228. int(
  1229. playerP.x()) + 80)) and PLAYER1_LIVES > 0):
  1230. playerP.setPixmap(QPixmap("marioDown.png"))
  1231. changePlayer1Lives()
  1232. ResetPlayer1Level()
  1233. ResetPlayer1Points()
  1234. setLevelTo1()
  1235. # time.sleep(1)
  1236.  
  1237. if (PLAYER1_LIVES == 0):
  1238. scena.removeItem(playerP)
  1239. scena.removeItem(scena.label.hide())
  1240. else:
  1241. playerP.setPos(SCREEN_WIDTH - 80,
  1242. SCREEN_HEIGHT - 130)
  1243. playerP.setPixmap(QPixmap("marioLeft.png"))
  1244.  
  1245. if ((PLAYER2_LIVES > 0) and (
  1246. self.y() in range(int(player2.y()), int(player2.y()) + 80) and self.x() in range(
  1247. int(player2.x()) - 40,
  1248. int(player2.x()) + 80))):
  1249. changePlayer2Lives()
  1250. ResetPlayer2Level()
  1251. ResetPlayer2Points()
  1252. setLevelTo2()
  1253. # time.sleep(1)
  1254.  
  1255. if (PLAYER2_LIVES == 0):
  1256. scena.removeItem(player2)
  1257. scena.removeItem(scena.label2.hide())
  1258. else:
  1259. player2.setPos(30, 848)
  1260. player2.setPixmap(QPixmap("luigiRight.png"))
  1261.  
  1262. if ((PLAYER3_LIVES > 0) and (
  1263. self.y() in range(int(player3.y()), int(player3.y()) + 80) and self.x() in range(
  1264. int(player3.x()) - 40,
  1265. int(player3.x()) + 80))):
  1266. changePlayer3Lives()
  1267. ResetPlayer3Level()
  1268. ResetPlayer3Points()
  1269. setLevelTo3()
  1270. # time.sleep(1)
  1271.  
  1272. if (PLAYER3_LIVES == 0):
  1273. scena.removeItem(player3)
  1274. scena.removeItem(scena.label5.hide())
  1275. else:
  1276. player3.setPos(SCREEN_WIDTH - 150,
  1277. SCREEN_HEIGHT - 130)
  1278. player3.setPixmap(QPixmap("blueLeft.png"))
  1279.  
  1280. if ((PLAYER4_LIVES > 0) and (
  1281. self.y() in range(int(player4.y()), int(player4.y()) + 80) and self.x() in range(
  1282. int(player4.x()) - 40,
  1283. int(player4.x()) + 80))):
  1284. changePlayer4Lives()
  1285. ResetPlayer4Level()
  1286. ResetPlayer4Points()
  1287. setLevelTo4()
  1288. # time.sleep(1)
  1289.  
  1290. if (PLAYER4_LIVES == 0):
  1291. scena.removeItem(player4)
  1292. scena.removeItem(scena.label6.hide())
  1293. else:
  1294. player4.setPos(70, 848)
  1295. player4.setPixmap(QPixmap("purpleRight.png"))
  1296.  
  1297. if (int(NUM_OF_PLAYERS) == 2):
  1298. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
  1299. if (WINNER == 0):
  1300. pic = QPixmap("marioWins")
  1301. else:
  1302. pic = QPixmap("luigiWins")
  1303.  
  1304. scena.addItem(QGraphicsPixmapItem(pic))
  1305. elif (int(NUM_OF_PLAYERS) == 3):
  1306. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0):
  1307. if (WINNER == 0):
  1308. pic = QPixmap("marioWins")
  1309. elif (WINNER == 1):
  1310. pic = QPixmap("luigiWins")
  1311. else:
  1312. pic = QPixmap("blueWins")
  1313.  
  1314. scena.addItem(QGraphicsPixmapItem(pic))
  1315. elif (int(NUM_OF_PLAYERS) == 4):
  1316. if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0 and PLAYER4_LIVES == 0):
  1317. if (WINNER == 0):
  1318. pic = QPixmap("marioWins")
  1319. elif (WINNER == 1):
  1320. pic = QPixmap("luigiWins")
  1321. elif (WINNER == 2):
  1322. pic = QPixmap("blueWins")
  1323. else:
  1324. pic = QPixmap("purpleWins")
  1325.  
  1326. scena.addItem(QGraphicsPixmapItem(pic))
  1327.  
  1328. if self.frames <= 0:
  1329. self.active = False
  1330. self.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
  1331.  
  1332.  
  1333. class Ladder(QGraphicsPixmapItem):
  1334. def __init__(self, parent=None):
  1335. QGraphicsPixmapItem.__init__(self, parent)
  1336. self.setPixmap(QPixmap("ladder.png"))
  1337.  
  1338.  
  1339. class Scene(QGraphicsScene):
  1340. def __init__(self, q: mp.Queue, red: mp.Queue, q2: mp.Queue, red0: mp.Queue, monQ: mp.Queue, monQ1: mp.Queue,
  1341. queueLevoDesno: mp.Queue, socSend: socket.socket, socRecv: socket.socket, parent=None):
  1342. QGraphicsScene.__init__(self, parent)
  1343.  
  1344. self.socSend = socSend
  1345. self.socRecv = socRecv
  1346.  
  1347. text = self.socSend.recv(1024)
  1348.  
  1349. # self.socRecv.bind((HOST, PORTRECV))
  1350. # self.socRecv.listen(1)
  1351. # self.conn, addr = self.socRecv.accept()
  1352. #
  1353. # text = ''
  1354. # while True:
  1355. # bin = self.conn.recv(1024)
  1356. # text += str(bin, 'utf-8')
  1357. # if not bin or len(bin) < 1024:
  1358. # break
  1359. # print('Received', text)
  1360.  
  1361. # hold the set of keys we're pressing
  1362. self.keys_pressed = set()
  1363.  
  1364. # use a timer to get 60Hz refresh (hopefully)
  1365. self.timer = QBasicTimer()
  1366. self.timer.start(FRAME_TIME_MS, self)
  1367.  
  1368. bg = QGraphicsRectItem()
  1369. bg.setRect(-1, -1, SCREEN_WIDTH + 2, SCREEN_HEIGHT + 2)
  1370. bg.setBrush(QBrush(Qt.white))
  1371.  
  1372. self.red1 = red
  1373. self.red2 = red0
  1374. self.queueLevoDesno = queueLevoDesno
  1375.  
  1376. self.monkeyPosition = monQ1
  1377.  
  1378. self.addItem(bg)
  1379.  
  1380. pic = QPixmap("backgroundOriginal.png")
  1381.  
  1382. self.addItem(QGraphicsPixmapItem(pic))
  1383.  
  1384. self.ladders = []
  1385. self.laddersCoordinates = eval(text)
  1386.  
  1387. for i in range(5):
  1388. self.ladders.append(Ladder())
  1389.  
  1390. # rand1 = random.randint(73, 1025)
  1391.  
  1392. self.ladders[0].setPos(self.laddersCoordinates[0], 745)
  1393. self.addItem(self.ladders[0])
  1394. # self.laddersCoordinates.append(rand1)
  1395.  
  1396. # rand1 = random.randint(185, 600)
  1397.  
  1398. self.ladders[1].setPos(self.laddersCoordinates[1], 560)
  1399. self.addItem(self.ladders[1])
  1400. # self.laddersCoordinates.append(rand1)
  1401.  
  1402. # rand1 = random.randint(710, 1018)
  1403.  
  1404. self.ladders[2].setPos(self.laddersCoordinates[2], 560)
  1405. self.addItem(self.ladders[2])
  1406. # self.laddersCoordinates.append(rand1)
  1407.  
  1408. # rand1 = random.randint(157, 542)
  1409.  
  1410. self.ladders[3].setPos(self.laddersCoordinates[3], 365)
  1411. self.addItem(self.ladders[3])
  1412. # self.laddersCoordinates.append(rand1)
  1413.  
  1414. # rand1 = random.randint(620, 1032)
  1415.  
  1416. self.ladders[4].setPos(self.laddersCoordinates[4], 365)
  1417. self.addItem(self.ladders[4])
  1418. # self.laddersCoordinates.append(rand1)
  1419.  
  1420. global PLAYER_ID
  1421. PLAYER_ID = self.laddersCoordinates[5]
  1422.  
  1423. self.heart1 = Player1Lives(q2)
  1424. self.heart2 = Player2Lives(q)
  1425. self.heart3 = Player3Lives()
  1426. self.heart4 = Player4Lives()
  1427.  
  1428. if (int(NUM_OF_PLAYERS) == 2):
  1429. self.addItem(self.heart1)
  1430. self.addItem(self.heart2)
  1431.  
  1432. elif (int(NUM_OF_PLAYERS) == 3):
  1433. self.addItem(self.heart1)
  1434. self.addItem(self.heart2)
  1435. self.addItem(self.heart3)
  1436.  
  1437. elif (int(NUM_OF_PLAYERS) == 4):
  1438. self.addItem(self.heart1)
  1439. self.addItem(self.heart2)
  1440. self.addItem(self.heart3)
  1441. self.addItem(self.heart4)
  1442.  
  1443. self.playerD = PlayerDonkey(monQ)
  1444. self.playerD.setPos(640, 235)
  1445. self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y)]
  1446. for b in self.bullets:
  1447. b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
  1448. self.addItem(b)
  1449. self.addItem(self.playerD)
  1450.  
  1451. self.playerP = PlayerPrincess()
  1452. self.playerP.setPos(500, 60)
  1453. self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y)]
  1454. for b in self.bullets:
  1455. b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
  1456. self.addItem(b)
  1457. self.addItem(self.playerP)
  1458.  
  1459. self.player = Player()
  1460. self.player.setPos(SCREEN_WIDTH - 80,
  1461. SCREEN_HEIGHT - 130)
  1462.  
  1463. self.addItem(self.player)
  1464.  
  1465. self.player2 = Player2()
  1466. self.player2.setPos(30, 848)
  1467.  
  1468. self.addItem(self.player2)
  1469.  
  1470. self.player3 = Player3()
  1471. self.player4 = Player4()
  1472.  
  1473. if (int(NUM_OF_PLAYERS) == 2):
  1474. self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
  1475. self.addItem(self.player)
  1476.  
  1477. self.player2.setPos(30, 848)
  1478. self.addItem(self.player2)
  1479.  
  1480. elif (int(NUM_OF_PLAYERS) == 3):
  1481. self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
  1482. self.addItem(self.player)
  1483.  
  1484. self.player2.setPos(30, 848)
  1485. self.addItem(self.player2)
  1486.  
  1487. self.player3.setPos(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 130)
  1488. self.addItem(self.player3)
  1489.  
  1490. elif (int(NUM_OF_PLAYERS) == 4):
  1491. self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
  1492. self.addItem(self.player)
  1493.  
  1494. self.player2.setPos(30, 848)
  1495. self.addItem(self.player2)
  1496.  
  1497. self.player3.setPos(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 130)
  1498. self.addItem(self.player3)
  1499.  
  1500. self.player4.setPos(70, 848)
  1501. self.addItem(self.player4)
  1502.  
  1503. self.view = QGraphicsView(self)
  1504.  
  1505. self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  1506. self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  1507. self.view.show()
  1508. self.view.setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT)
  1509. self.setSceneRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
  1510.  
  1511. self.label = QLabel()
  1512. self.label.setGeometry(1240, 50, 100, 100)
  1513. self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1514. self.label.setStyleSheet('color: white')
  1515. self.label.setAutoFillBackground(True)
  1516.  
  1517. widget = QWidget()
  1518. paleta = widget.palette()
  1519. paleta.setColor(widget.backgroundRole(), Qt.transparent)
  1520. self.label.setPalette(paleta)
  1521. self.label.setNum(POINTS1)
  1522.  
  1523. self.addWidget(self.label)
  1524.  
  1525. self.label2 = QLabel()
  1526. self.label2.setGeometry(10, 50, 100, 100)
  1527. self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1528. self.label2.setStyleSheet('color: white')
  1529. self.label2.setAutoFillBackground(True)
  1530.  
  1531. widget2 = QWidget()
  1532. paleta2 = widget2.palette()
  1533. paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
  1534. self.label2.setPalette(paleta2)
  1535. self.label2.setNum(POINTS2)
  1536.  
  1537. self.addWidget(self.label2)
  1538.  
  1539. self.label3 = QLabel()
  1540. self.label3.setGeometry(600, 0, 100, 40)
  1541. self.label3.setFont(QFont("Times New Roman", 25, QFont.Bold))
  1542. self.label3.setStyleSheet('color: white')
  1543. self.label3.setAutoFillBackground(True)
  1544.  
  1545. widget3 = QWidget()
  1546. paleta3 = widget3.palette()
  1547. paleta3.setColor(widget3.backgroundRole(), Qt.transparent)
  1548. self.label3.setPalette(paleta3)
  1549. self.label3.setText("Level")
  1550.  
  1551. self.addWidget(self.label3)
  1552.  
  1553. self.label4 = QLabel()
  1554. self.label4.setGeometry(700, 0, 100, 40)
  1555. self.label4.setFont(QFont("Times New Roman", 25, QFont.Bold))
  1556. self.label4.setStyleSheet('color: white')
  1557. self.label4.setAutoFillBackground(True)
  1558.  
  1559. widget4 = QWidget()
  1560. paleta4 = widget4.palette()
  1561. paleta4.setColor(widget4.backgroundRole(), Qt.transparent)
  1562. self.label4.setPalette(paleta4)
  1563. self.label4.setNum(CURRENT_LEVEL)
  1564.  
  1565. self.addWidget(self.label4)
  1566.  
  1567. if (int(NUM_OF_PLAYERS) == 2):
  1568. self.label = QLabel()
  1569. self.label.setGeometry(1240, 50, 100, 100)
  1570. self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1571. self.label.setStyleSheet('color: white')
  1572. self.label.setAutoFillBackground(True)
  1573.  
  1574. widget = QWidget()
  1575. paleta = widget.palette()
  1576. paleta.setColor(widget.backgroundRole(), Qt.transparent)
  1577. self.label.setPalette(paleta)
  1578. self.label.setNum(POINTS1)
  1579.  
  1580. self.addWidget(self.label)
  1581.  
  1582. self.label2 = QLabel()
  1583. self.label2.setGeometry(10, 50, 100, 100)
  1584. self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1585. self.label2.setStyleSheet('color: white')
  1586. self.label2.setAutoFillBackground(True)
  1587.  
  1588. widget2 = QWidget()
  1589. paleta2 = widget2.palette()
  1590. paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
  1591. self.label2.setPalette(paleta2)
  1592. self.label2.setNum(POINTS2)
  1593.  
  1594. self.addWidget(self.label2)
  1595. elif (int(NUM_OF_PLAYERS) == 3):
  1596. self.label = QLabel()
  1597. self.label.setGeometry(1240, 50, 100, 100)
  1598. self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1599. self.label.setStyleSheet('color: white')
  1600. self.label.setAutoFillBackground(True)
  1601.  
  1602. widget = QWidget()
  1603. paleta = widget.palette()
  1604. paleta.setColor(widget.backgroundRole(), Qt.transparent)
  1605. self.label.setPalette(paleta)
  1606. self.label.setNum(POINTS1)
  1607.  
  1608. self.addWidget(self.label)
  1609.  
  1610. self.label2 = QLabel()
  1611. self.label2.setGeometry(10, 50, 100, 100)
  1612. self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1613. self.label2.setStyleSheet('color: white')
  1614. self.label2.setAutoFillBackground(True)
  1615.  
  1616. widget2 = QWidget()
  1617. paleta2 = widget2.palette()
  1618. paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
  1619. self.label2.setPalette(paleta2)
  1620. self.label2.setNum(POINTS2)
  1621.  
  1622. self.addWidget(self.label2)
  1623.  
  1624. self.label5 = QLabel()
  1625. self.label5.setGeometry(1080, 50, 100, 100)
  1626. self.label5.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1627. self.label5.setStyleSheet('color: white')
  1628. self.label5.setAutoFillBackground(True)
  1629.  
  1630. widget5 = QWidget()
  1631. paleta5 = widget5.palette()
  1632. paleta5.setColor(widget5.backgroundRole(), Qt.transparent)
  1633. self.label5.setPalette(paleta5)
  1634. self.label5.setNum(POINTS3)
  1635.  
  1636. self.addWidget(self.label5)
  1637. elif (int(NUM_OF_PLAYERS) == 4):
  1638. self.label = QLabel()
  1639. self.label.setGeometry(1240, 50, 100, 100)
  1640. self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1641. self.label.setStyleSheet('color: white')
  1642. self.label.setAutoFillBackground(True)
  1643.  
  1644. widget = QWidget()
  1645. paleta = widget.palette()
  1646. paleta.setColor(widget.backgroundRole(), Qt.transparent)
  1647. self.label.setPalette(paleta)
  1648. self.label.setNum(POINTS1)
  1649.  
  1650. self.addWidget(self.label)
  1651.  
  1652. self.label2 = QLabel()
  1653. self.label2.setGeometry(10, 50, 100, 100)
  1654. self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1655. self.label2.setStyleSheet('color: white')
  1656. self.label2.setAutoFillBackground(True)
  1657.  
  1658. widget2 = QWidget()
  1659. paleta2 = widget2.palette()
  1660. paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
  1661. self.label2.setPalette(paleta2)
  1662. self.label2.setNum(POINTS2)
  1663.  
  1664. self.addWidget(self.label2)
  1665.  
  1666. self.label5 = QLabel()
  1667. self.label5.setGeometry(1080, 50, 100, 100)
  1668. self.label5.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1669. self.label5.setStyleSheet('color: white')
  1670. self.label5.setAutoFillBackground(True)
  1671.  
  1672. widget5 = QWidget()
  1673. paleta5 = widget5.palette()
  1674. paleta5.setColor(widget5.backgroundRole(), Qt.transparent)
  1675. self.label5.setPalette(paleta5)
  1676. self.label5.setNum(POINTS3)
  1677.  
  1678. self.addWidget(self.label5)
  1679.  
  1680. self.label6 = QLabel()
  1681. self.label6.setGeometry(150, 50, 100, 100)
  1682. self.label6.setFont(QFont("Times New Roman", 50, QFont.Bold))
  1683. self.label6.setStyleSheet('color: white')
  1684. self.label6.setAutoFillBackground(True)
  1685.  
  1686. widget6 = QWidget()
  1687. paleta6 = widget6.palette()
  1688. paleta6.setColor(widget6.backgroundRole(), Qt.transparent)
  1689. self.label6.setPalette(paleta6)
  1690. self.label6.setNum(POINTS4)
  1691.  
  1692. self.addWidget(self.label6)
  1693.  
  1694. def keyPressEvent(self, event):
  1695. self.keys_pressed.add(event.key())
  1696.  
  1697. def keyReleaseEvent(self, event):
  1698. self.keys_pressed.remove(event.key())
  1699.  
  1700. def timerEvent(self, event):
  1701. self.game_update()
  1702. self.update()
  1703.  
  1704. def game_update(self):
  1705. global LEVEL
  1706. global LEVEL2
  1707. global LEVEL3
  1708. global LEVEL4
  1709. global POINTS1
  1710. global POINTS2
  1711. global POINTS3
  1712. global POINTS4
  1713. global PLAYER1_LIVES
  1714. global PLAYER2_LIVES
  1715. global PLAYER3_LIVES
  1716. global PLAYER4_LIVES
  1717. global PLAYER2_PIC
  1718. global PLAYER1_PIC
  1719. global PLAYER3_PIC
  1720. global PLAYER4_PIC
  1721. global CURRENT_LEVEL
  1722. global FRAME_TIME_MS
  1723. self.red2.put(PLAYER1_LIVES)
  1724. self.red1.put(PLAYER2_LIVES)
  1725.  
  1726. text2send = str(self.playerD.x())
  1727. self.socSend.sendall(text2send.encode('utf8'))
  1728. text = ''
  1729. while True:
  1730. bin = self.socSend.recv(1024)
  1731. text += str(bin, 'utf-8')
  1732. if not bin or len(bin) < 1024:
  1733. break
  1734.  
  1735. self.monkeyPosition.put(float(text))
  1736. self.queueLevoDesno.put(LEVO_DESNO)
  1737.  
  1738. self.player.game_update(self.keys_pressed, self.laddersCoordinates, self.label)
  1739.  
  1740. posX = str(self.player.x())
  1741. posY = str(self.player.y())
  1742. points1 = str(POINTS1)
  1743. level1 = str(LEVEL)
  1744. curLevel = str(CURRENT_LEVEL)
  1745. koordinata = posX + ',' + posY + ',' + points1 + ',' + level1 + ',' + PLAYER1_PIC
  1746. text2send = str(koordinata)
  1747. self.socSend.sendall(text2send.encode('utf8'))
  1748. text = ''
  1749. while True:
  1750. bin = self.socSend.recv(1024)
  1751. text += str(bin, 'utf-8')
  1752. if not bin or len(bin) < 1024:
  1753. break
  1754. x = text.split(',')
  1755. self.player.setPos(float(x[0]), float(x[1]))
  1756. POINTS1 = int(x[2])
  1757. LEVEL = int(x[3])
  1758. self.player.setPixmap(QPixmap(x[4]))
  1759. # CURRENT_LEVEL = int(x[5])
  1760. # self.label4.setNum(CURRENT_LEVEL)
  1761.  
  1762. currLevel = str(CURRENT_LEVEL) # SLANJE NIVOA I PRIMANJE ISTOG
  1763. time_frame_ms = str(FRAME_TIME_MS)
  1764. text2send = currLevel + ',' + time_frame_ms
  1765. self.socSend.sendall(text2send.encode('utf8'))
  1766. text = ''
  1767. while True:
  1768. bin = self.socSend.recv(1024)
  1769. text += str(bin, 'utf-8')
  1770. if not bin or len(bin) < 1024:
  1771. break
  1772. ret = text.split(',')
  1773. CURRENT_LEVEL = int(ret[0])
  1774. FRAME_TIME_MS = int(ret[1])
  1775. self.label4.setNum(CURRENT_LEVEL)
  1776.  
  1777. self.player2.game_update(self.keys_pressed, self.laddersCoordinates, self.label2)
  1778. posX = str(self.player2.x())
  1779. posY = str(self.player2.y())
  1780. points2 = str(POINTS2)
  1781. level2 = str(LEVEL2)
  1782. curLevel = str(CURRENT_LEVEL)
  1783. koordinata = posX + ',' + posY + ',' + points2 + ',' + level2 + ',' + PLAYER2_PIC
  1784. text2send = str(koordinata)
  1785.  
  1786. self.socSend.sendall(text2send.encode('utf8'))
  1787. text = ''
  1788. while True:
  1789. bin = self.socSend.recv(1024)
  1790. text += str(bin, 'utf-8')
  1791. if not bin or len(bin) < 1024:
  1792. break
  1793. x = text.split(',')
  1794. self.player2.setPos(float(x[0]), float(x[1]))
  1795. POINTS2 = int(x[2])
  1796. LEVEL2 = int(x[3])
  1797. self.player2.setPixmap(QPixmap(x[4]))
  1798. # CURRENT_LEVEL = int(x[5])
  1799. # self.label4.setNum(CURRENT_LEVEL)
  1800.  
  1801.  
  1802. if (int(NUM_OF_PLAYERS) == 3 or int(NUM_OF_PLAYERS) == 4):
  1803. self.player3.game_update(self.keys_pressed, self.laddersCoordinates, self.label5) # PLAYER 3 GAME UPDATE
  1804. posX = str(self.player3.x())
  1805. posY = str(self.player3.y())
  1806. points3 = str(POINTS3)
  1807. level3 = str(LEVEL3)
  1808. curLevel = str(CURRENT_LEVEL)
  1809. koordinata = posX + ',' + posY + ',' + points3 + ',' + level3 + ',' + PLAYER3_PIC
  1810. text2send = str(koordinata)
  1811.  
  1812. self.socSend.sendall(text2send.encode('utf8'))
  1813. text = ''
  1814. while True:
  1815. bin = self.socSend.recv(1024)
  1816. text += str(bin, 'utf-8')
  1817. if not bin or len(bin) < 1024:
  1818. break
  1819. x = text.split(',')
  1820. self.player3.setPos(float(x[0]), float(x[1]))
  1821. POINTS3 = int(x[2])
  1822. LEVEL3 = int(x[3])
  1823. self.player3.setPixmap(QPixmap(x[4]))
  1824.  
  1825. if (int(NUM_OF_PLAYERS) == 4):
  1826. self.player4.game_update(self.keys_pressed, self.laddersCoordinates, self.label6) # PLAYER 4 GAME UPDATE
  1827. posX = str(self.player4.x())
  1828. posY = str(self.player4.y())
  1829. points4 = str(POINTS4)
  1830. level4 = str(LEVEL4)
  1831. curLevel = str(CURRENT_LEVEL)
  1832. koordinata = posX + ',' + posY + ',' + points4 + ',' + level4 + ',' + PLAYER4_PIC
  1833. text2send = str(koordinata)
  1834.  
  1835. self.socSend.sendall(text2send.encode('utf8'))
  1836. text = ''
  1837. while True:
  1838. bin = self.socSend.recv(1024)
  1839. text += str(bin, 'utf-8')
  1840. if not bin or len(bin) < 1024:
  1841. break
  1842. x = text.split(',')
  1843. self.player4.setPos(float(x[0]), float(x[1]))
  1844. POINTS4 = int(x[2])
  1845. LEVEL4 = int(x[3])
  1846. self.player4.setPixmap(QPixmap(x[4]))
  1847.  
  1848. self.playerD.game_update(self.keys_pressed, self.player, self.player2, self, self.player3, self.player4)
  1849. self.playerP.game_update(self.playerD.x(), self.player.x(), self.player.y(), self.player, self.player2.x(),
  1850. self.player2.y(), self.player2, self, self.label4, self.player3.x(), self.player3.y(),
  1851. self.player3, self.player4.x(), self.player4.y(), self.player4)
  1852.  
  1853. self.heart1.listen()
  1854.  
  1855. numOfLives1 = PLAYER1_LIVES
  1856.  
  1857. text2send = str(numOfLives1)
  1858. self.socSend.sendall(text2send.encode('utf8'))
  1859. text = ''
  1860. while True:
  1861. bin = self.socSend.recv(1024)
  1862. text += str(bin, 'utf-8')
  1863. if not bin or len(bin) < 1024:
  1864. break
  1865.  
  1866. PLAYER1_LIVES = int(text)
  1867.  
  1868. self.heart2.listen()
  1869.  
  1870. numOfLives2 = PLAYER2_LIVES
  1871.  
  1872. text2send = str(numOfLives2)
  1873. self.socSend.sendall(text2send.encode('utf8'))
  1874. text = ''
  1875. while True:
  1876. bin = self.socSend.recv(1024)
  1877. text += str(bin, 'utf-8')
  1878. if not bin or len(bin) < 1024:
  1879. break
  1880. PLAYER2_LIVES = int(text)
  1881.  
  1882. if (NUM_OF_PLAYERS == 3 or NUM_OF_PLAYERS == 4):
  1883. self.heart3.game_update() # PLAYER 3 LIVES
  1884. numOfLives3 = PLAYER3_LIVES
  1885. text2send = str(numOfLives3)
  1886. self.socSend.sendall(text2send.encode('utf8'))
  1887. text = ''
  1888. while True:
  1889. bin = self.socSend.recv(1024)
  1890. text += str(bin, 'utf-8')
  1891. if not bin or len(bin) < 1024:
  1892. break
  1893. PLAYER3_LIVES = int(text)
  1894.  
  1895. if (NUM_OF_PLAYERS == 4):
  1896. self.heart4.game_update() # PLAYER 4 LIVES
  1897. numOfLives4 = PLAYER4_LIVES
  1898. text2send = str(numOfLives4)
  1899. self.socSend.sendall(text2send.encode('utf8'))
  1900. text = ''
  1901. while True:
  1902. bin = self.socSend.recv(1024)
  1903. text += str(bin, 'utf-8')
  1904. if not bin or len(bin) < 1024:
  1905. break
  1906. PLAYER4_LIVES = int(text)
  1907.  
  1908. for b in self.bullets:
  1909. b.game_update(self.timer, self.playerD, self.player, self.player2, self, self.player3, self.player4)
  1910. posX = str(b.x())
  1911. posY = str(b.y())
  1912. koordinata = posX + ',' + posY
  1913. text2send = str(koordinata)
  1914. self.socSend.sendall(text2send.encode('utf8'))
  1915. text = ''
  1916. while True:
  1917. bin = self.socSend.recv(1024)
  1918. text += str(bin, 'utf-8')
  1919. if not bin or len(bin) < 1024:
  1920. break
  1921. x = text.split(',')
  1922. b.setPos(float(x[0]), float(x[1]))
  1923.  
  1924.  
  1925. if __name__ == '__main__':
  1926. app = QApplication(sys.argv)
  1927. socketSend = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1928. socketSend.connect((HOST, PORTSEND))
  1929.  
  1930. socketRecv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1931.  
  1932. queue = mp.Queue()
  1933. queue1 = mp.Queue()
  1934. queue2 = mp.Queue()
  1935. queue3 = mp.Queue()
  1936. queueMonkey = mp.Queue()
  1937. queueMonkey1 = mp.Queue()
  1938. queueLevoDesno = mp.Queue()
  1939. proces = mp.Process(target=runner, args=[queue, queue1])
  1940. proces.daemon = True
  1941. proces.start()
  1942. proces2 = mp.Process(target=runner2, args=[queue2, queue3])
  1943. proces2.daemon = True
  1944. proces2.start()
  1945. procesMonkey = mp.Process(target=donkeyRunner, args=[queueMonkey, queueMonkey1, queueLevoDesno])
  1946. procesMonkey.daemon = True
  1947. procesMonkey.start()
  1948. scene = Scene(queue, queue1, queue2, queue3, queueMonkey, queueMonkey1, queueLevoDesno, socketSend, socketRecv)
  1949. print("main: ", current_process().pid)
  1950. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement