Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Simple start to a game in PyQt5
- # move with arrow keys, spacebar to fire bullets
- # Used graphics from https://opengameart.org/content/space-shooter-redux
- # (reduced by 50%)
- # Got some hints from https://www.youtube.com/watch?v=8ntEQpg7gck series
- # and http://zetcode.com/gui/pyqt5/tetris/
- #
- import sys
- from PyQt5.QtCore import (
- Qt,
- QBasicTimer
- )
- from PyQt5.QtGui import (
- QBrush,
- QPixmap,
- QImage,
- QFont
- )
- from PyQt5.QtWidgets import (
- QApplication,
- QGraphicsItem,
- QGraphicsPixmapItem,
- QGraphicsRectItem,
- QGraphicsScene,
- QGraphicsView,
- QWidget,
- QLabel
- )
- import random
- import time
- import multiprocessing as mp
- from multiprocessing import Queue, current_process
- import socket
- HOST = '192.168.100.212' # Symbolic name meaning all available interfaces
- PORTSEND = 50005 # Arbitrary non-privileged port
- PORTRECV = 50006
- SCREEN_WIDTH = 1280
- SCREEN_HEIGHT = 978
- PLAYER_SPEED = 7 # pix/frame
- PLAYER_BULLET_X_OFFSETS = [0, 45]
- PLAYER_BULLET_Y = 15
- BULLET_SPEED = 10 # pix/frame
- BULLET_FRAMES = 80
- FRAME_TIME_MS = 18 # ms/frame
- LEVEL = 1 # platforma igraca 1
- LEVEL_PLAYER1 = 1 # na kojoj je platformi igrac 1
- PLAYER1_LIVES = 3 # zivoti igraca 1
- POINTS1 = 0 # poeni igraca 1
- LEVEL2 = 1 # platforma igraca 2
- LEVEL_PLAYER2 = 1 # na kojoj je platformi igrac 2
- PLAYER2_LIVES = 3 # zivoti igraca 2
- POINTS2 = 0 # poeni igraca 2
- LEVEL3 = 1 # platforma igraca 3
- LEVEL_PLAYER3 = 1 # na kojoj je platformi igrac 3
- PLAYER3_LIVES = 3 # zivoti igraca 3
- POINTS3 = 0 # poeni igraca 3
- LEVEL4 = 1 # platforma igraca 4
- LEVEL_PLAYER4 = 1 # na kojoj je platformi igrac 4
- PLAYER4_LIVES = 3 # zivoti igraca 4
- POINTS4 = 0 # poeni igraca 4
- WINNER = 0 # ko je pobednik -- treba promenuti, radi samo za 2 igraca
- CURRENT_LEVEL = 1 # trenutni nivo
- NUM_OF_PLAYERS = 2 # broj igraca
- MONKEY_SPEED = 10
- LEVO_DESNO = 1
- PLAYER_ID = 0
- PLAYER1_PIC = ''
- PLAYER2_PIC = ''
- PLAYER3_PIC = ''
- PLAYER4_PIC = ''
- def changeFrameTimems():
- global FRAME_TIME_MS
- FRAME_TIME_MS -= 1
- def returnPlayerLives():
- global PLAYER1_LIVES
- PLAYER1_LIVES = 3
- def returnPlayer2Lives():
- global PLAYER2_LIVES
- PLAYER2_LIVES = 3
- def changePlayer1Lives():
- global PLAYER1_LIVES
- if (PLAYER1_LIVES == 0):
- PLAYER1_LIVES = 0
- else:
- PLAYER1_LIVES -= 1
- def changePlayer2Lives():
- global PLAYER2_LIVES
- if (PLAYER2_LIVES == 0):
- PLAYER2_LIVES = 0
- else:
- PLAYER2_LIVES -= 1
- def changeGlobalPlus():
- global LEVEL
- LEVEL += 1
- def changeGlobalMinus():
- global LEVEL
- LEVEL -= 1
- def changeGlobalPlus2():
- global LEVEL2
- LEVEL2 += 1
- def changeGlobalMinus2():
- global LEVEL2
- LEVEL2 -= 1
- def changeDirection():
- global LEVO_DESNO
- if (LEVO_DESNO == 1):
- LEVO_DESNO = 0
- else:
- LEVO_DESNO = 1
- def upLevelPlayer1():
- global LEVEL_PLAYER1
- LEVEL_PLAYER1 += 1
- def ResetPlayer1Level():
- global LEVEL_PLAYER1
- LEVEL_PLAYER1 = 1
- def Player1Points():
- global POINTS1
- POINTS1 += 1
- def ResetPlayer1Points():
- global POINTS1
- POINTS1 = 0
- def setLevelTo1():
- global LEVEL
- LEVEL = 1
- def upLevelPlayer2():
- global LEVEL_PLAYER2
- LEVEL_PLAYER2 += 1
- def ResetPlayer2Level():
- global LEVEL_PLAYER2
- LEVEL_PLAYER2 = 1
- def Player2Points():
- global POINTS2
- POINTS2 += 1
- def ResetPlayer2Points():
- global POINTS2
- POINTS2 = 0
- def setLevelTo2():
- global LEVEL2
- LEVEL2 = 1
- def returnPlayer3Lives(): # kad igrac 3 dodje do princeze pocne novi nivo i on dobije 3 zivota
- global PLAYER3_LIVES
- PLAYER3_LIVES = 3
- def changePlayer3Lives(): # igrac 3 je izgubio 1 zivot
- global PLAYER3_LIVES
- if (PLAYER3_LIVES == 0):
- PLAYER3_LIVES = 0
- else:
- PLAYER3_LIVES -= 1
- def changeGlobalPlus3(): # povecava se platforma igraca 3
- global LEVEL3
- LEVEL3 += 1
- def changeGlobalMinus3(): # smanjuje se platforma igraca 3
- global LEVEL3
- LEVEL3 -= 1
- def upLevelPlayer3(): # povecava se platforma igraca 3 --ovo treba za poene
- global LEVEL_PLAYER3
- LEVEL_PLAYER3 += 1
- def ResetPlayer3Level(): # vrati platformu igraca 3 na pocetnu --ovo treba za poene
- global LEVEL_PLAYER3
- LEVEL_PLAYER3 = 1
- def Player3Points(): # povecaj poene igracu 3
- global POINTS3
- POINTS3 += 1
- def ResetPlayer3Points(): # resetuj poene igraca 3
- global POINTS3
- POINTS3 = 0
- def setLevelTo3(): # vrati platformu igraca 3 na pocetnu
- global LEVEL3
- LEVEL3 = 1
- def returnPlayer4Lives(): # kad igrac 4 dodje do princeze pocne novi nivo i on dobije 3 zivota
- global PLAYER4_LIVES
- PLAYER4_LIVES = 3
- def changePlayer4Lives(): # igrac 4 je izgubio 1 zivot
- global PLAYER4_LIVES
- if (PLAYER4_LIVES == 0):
- PLAYER4_LIVES = 0
- else:
- PLAYER4_LIVES -= 1
- def changeGlobalPlus4(): # povecava se platforma igraca 4
- global LEVEL4
- LEVEL4 += 1
- def changeGlobalMinus4(): # smanjuje se platforma igraca 4
- global LEVEL4
- LEVEL4 -= 1
- def upLevelPlayer4(): # povecava se platforma igraca 4 --ovo treba za poene
- global LEVEL_PLAYER4
- LEVEL_PLAYER4 += 1
- def ResetPlayer4Level(): # vrati platformu igraca 4 na pocetnu --ovo treba za poene
- global LEVEL_PLAYER4
- LEVEL_PLAYER4 = 1
- def Player4Points(): # povecaj poene igracu 4
- global POINTS4
- POINTS4 += 1
- def ResetPlayer4Points(): # resetuj poene igraca 4
- global POINTS4
- POINTS4 = 0
- def setLevelTo4(): # vrati platformu igraca 4 na pocetnu
- global LEVEL4
- LEVEL4 = 1
- def ChangeWinner(number): # promeni pobednika
- global WINNER
- if (number == 0):
- WINNER = 0
- elif (number == 1):
- WINNER = 1
- elif (number == 2):
- WINNER = 2
- elif (number == 3):
- WINNER = 3
- def CurrentLVLUP(): # povecaj trenutni nivo
- global CURRENT_LEVEL
- CURRENT_LEVEL += 1
- class Player(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("marioLeft.png"))
- global PLAYER1_PIC
- PLAYER1_PIC = "marioLeft.png"
- def game_update(self, keys_pressed, coordinateX, label):
- dx = 0
- dy = 0
- global LEVEL
- global PLAYER1_PIC
- if (LEVEL > LEVEL_PLAYER1):
- upLevelPlayer1()
- Player1Points()
- label.setNum(POINTS1)
- if (POINTS1 == 0):
- label.setNum(POINTS1)
- if (POINTS1 > 9):
- label.setGeometry(1210, 50, 100, 100)
- else:
- label.setGeometry(1240, 50, 100, 100)
- if (PLAYER_ID == 1):
- if (LEVEL == 1 and PLAYER1_LIVES > 0):
- if Qt.Key_Left in keys_pressed and self.x() > 0 and self.y() == 848:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioLeft.png"))
- PLAYER1_PIC = "marioLeft.png"
- if Qt.Key_Right in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("marioRight.png"))
- PLAYER1_PIC = "marioRight.png"
- if Qt.Key_Up in keys_pressed and (
- self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if Qt.Key_Down in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if self.y() == 652:
- changeGlobalPlus()
- if (LEVEL == 2 and PLAYER1_LIVES > 0):
- if Qt.Key_Left in keys_pressed and self.x() > 45 and self.y() == 652:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioLeft.png"))
- PLAYER1_PIC = "marioLeft.png"
- if Qt.Key_Right in keys_pressed and self.x() < 1053 and self.y() == 652:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("marioRight.png"))
- PLAYER1_PIC = "marioRight.png"
- if Qt.Key_Up in keys_pressed and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
- int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if Qt.Key_Down in keys_pressed and (
- (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
- or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
- or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if self.y() > 652:
- changeGlobalMinus()
- if self.y() == 470:
- changeGlobalPlus()
- if (LEVEL == 3 and PLAYER1_LIVES > 0):
- if Qt.Key_Left in keys_pressed and self.x() > 150 and self.y() == 470:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioLeft.png"))
- PLAYER1_PIC = "marioLeft.png"
- if Qt.Key_Right in keys_pressed and self.x() < 1158 and self.y() == 470:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("marioRight.png"))
- PLAYER1_PIC = "marioRight.png"
- if Qt.Key_Up in keys_pressed and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if Qt.Key_Down in keys_pressed and ((self.y() == 470 and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
- or (
- self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
- or (
- self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if self.y() > 470:
- changeGlobalMinus()
- if self.y() == 274:
- changeGlobalPlus()
- if (LEVEL == 4 and PLAYER1_LIVES > 0):
- if Qt.Key_Left in keys_pressed and self.x() > 38 and self.y() == 274:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioLeft.png"))
- PLAYER1_PIC = "marioLeft.png"
- if Qt.Key_Right in keys_pressed and self.x() < 1053 and self.y() == 274:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("marioRight.png"))
- PLAYER1_PIC = "marioRight.png"
- if Qt.Key_Up in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if Qt.Key_Down in keys_pressed and ((self.y() == 274 and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4])))
- or (self.y() < 274 and self.x() in range(210, 254))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if self.y() > 274:
- changeGlobalMinus()
- if self.y() <= 50:
- changeGlobalPlus()
- if (LEVEL == 5 and PLAYER1_LIVES > 0):
- if Qt.Key_Left in keys_pressed and self.x() > 227 and self.y() == 50:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("marioLeft.png"))
- PLAYER1_PIC = "marioLeft.png"
- if Qt.Key_Right in keys_pressed and self.x() < 528 and self.y() == 50:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("marioRight.png"))
- PLAYER1_PIC = "marioRight.png"
- if Qt.Key_Down in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("marioClimb.png"))
- PLAYER1_PIC = "marioClimb.png"
- if self.y() > 50:
- changeGlobalMinus()
- self.setPos(self.x() + dx, self.y() + dy)
- class Player2(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("luigiRight.png"))
- global PLAYER2_PIC
- PLAYER2_PIC = "luigiRight.png"
- def game_update(self, keys_pressed, coordinateX, label):
- dx = 0
- dy = 0
- global LEVEL2
- global PLAYER2_PIC
- if (LEVEL2 > LEVEL_PLAYER2):
- upLevelPlayer2()
- Player2Points()
- label.setNum(POINTS2)
- if (POINTS2 == 0):
- label.setNum(POINTS2)
- if (PLAYER_ID == 2):
- if (LEVEL2 == 1 and PLAYER2_LIVES > 0):
- if Qt.Key_A in keys_pressed and self.x() > 0 and self.y() == 848:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiLeft.png"))
- PLAYER2_PIC = "luigiLeft.png"
- if Qt.Key_D in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiRight.png"))
- PLAYER2_PIC = "luigiRight.png"
- if Qt.Key_W in keys_pressed and (
- self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if Qt.Key_S in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if self.y() == 652:
- changeGlobalPlus2()
- if (LEVEL2 == 2 and PLAYER2_LIVES > 0):
- if Qt.Key_A in keys_pressed and self.x() > 45 and self.y() == 652:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiLeft.png"))
- PLAYER2_PIC = "luigiLeft.png"
- if Qt.Key_D in keys_pressed and self.x() < 1053 and self.y() == 652:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiRight.png"))
- PLAYER2_PIC = "luigiRight.png"
- if Qt.Key_W in keys_pressed and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
- int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if Qt.Key_S in keys_pressed and (
- (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
- or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
- or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if self.y() > 652:
- changeGlobalMinus2()
- if self.y() == 470:
- changeGlobalPlus2()
- if (LEVEL2 == 3 and PLAYER2_LIVES > 0):
- if Qt.Key_A in keys_pressed and self.x() > 150 and self.y() == 470:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiLeft.png"))
- PLAYER2_PIC = "luigiLeft.png"
- if Qt.Key_D in keys_pressed and self.x() < 1158 and self.y() == 470:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiRight.png"))
- PLAYER2_PIC = "luigiRight.png"
- if Qt.Key_W in keys_pressed and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if Qt.Key_S in keys_pressed and ((self.y() == 470 and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
- or (
- self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
- or (
- self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if self.y() > 470:
- changeGlobalMinus2()
- if self.y() == 274:
- changeGlobalPlus2()
- if (LEVEL2 == 4 and PLAYER2_LIVES > 0):
- if Qt.Key_A in keys_pressed and self.x() > 38 and self.y() == 274:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiLeft.png"))
- PLAYER2_PIC = "luigiLeft.png"
- if Qt.Key_D in keys_pressed and self.x() < 1053 and self.y() == 274:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiRight.png"))
- PLAYER2_PIC = "luigiRight.png"
- if Qt.Key_W in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if Qt.Key_S in keys_pressed and ((self.y() == 274 and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4])))
- or (self.y() < 274 and self.x() in range(210, 254))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if self.y() > 274:
- changeGlobalMinus2()
- if self.y() <= 50:
- changeGlobalPlus2()
- if (LEVEL2 == 5 and PLAYER2_LIVES > 0):
- if Qt.Key_A in keys_pressed and self.x() > 227 and self.y() == 50:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("luigiLeft.png"))
- PLAYER2_PIC = "luigiLeft.png"
- if Qt.Key_D in keys_pressed and self.x() < 528 and self.y() == 50:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiRight.png"))
- PLAYER2_PIC = "luigiRight.png"
- if Qt.Key_S in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("luigiClimb.png"))
- PLAYER2_PIC = "luigiClimb.png"
- if self.y() > 50:
- changeGlobalMinus2()
- self.setPos(self.x() + dx, self.y() + dy)
- class Player3(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("blueLeft.png"))
- global PLAYER3_PIC
- PLAYER3_PIC = "blueLeft.png"
- def game_update(self, keys_pressed, coordinateX, label):
- dx = 0
- dy = 0
- global LEVEL3
- global PLAYER3_PIC
- if (LEVEL3 > LEVEL_PLAYER3):
- upLevelPlayer3()
- Player3Points()
- label.setNum(POINTS3)
- if (POINTS3 == 0):
- label.setNum(POINTS3)
- if (POINTS3 > 9):
- label.setGeometry(1050, 50, 100, 100)
- else:
- label.setGeometry(1080, 50, 100, 100)
- if (PLAYER_ID == 3):
- if (LEVEL3 == 1 and PLAYER3_LIVES > 0):
- if Qt.Key_4 in keys_pressed and self.x() > 0 and self.y() == 848:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueLeft.png"))
- PLAYER3_PIC = "blueLeft.png"
- if Qt.Key_6 in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("blueRight.png"))
- PLAYER3_PIC = "blueRight.png"
- if Qt.Key_8 in keys_pressed and (
- self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if Qt.Key_5 in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if self.y() == 652:
- changeGlobalPlus3()
- if (LEVEL3 == 2 and PLAYER3_LIVES > 0):
- if Qt.Key_4 in keys_pressed and self.x() > 45 and self.y() == 652:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueLeft.png"))
- PLAYER3_PIC = "blueLeft.png"
- if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 652:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("blueRight.png"))
- PLAYER3_PIC = "blueRight.png"
- if Qt.Key_8 in keys_pressed and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
- int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if Qt.Key_5 in keys_pressed and (
- (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
- or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
- or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if self.y() > 652:
- changeGlobalMinus3()
- if self.y() == 470:
- changeGlobalPlus3()
- if (LEVEL3 == 3 and PLAYER3_LIVES > 0):
- if Qt.Key_4 in keys_pressed and self.x() > 45 and self.y() == 652:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueLeft.png"))
- PLAYER3_PIC = "blueLeft.png"
- if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 652:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("blueRight.png"))
- PLAYER3_PIC = "blueRight.png"
- if Qt.Key_8 in keys_pressed and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
- int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if Qt.Key_5 in keys_pressed and (
- (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
- or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
- or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if self.y() > 470:
- changeGlobalMinus3()
- if self.y() == 274:
- changeGlobalPlus3()
- if (LEVEL3 == 4 and PLAYER3_LIVES > 0):
- if Qt.Key_4 in keys_pressed and self.x() > 38 and self.y() == 274:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueLeft.png"))
- PLAYER3_PIC = "blueLeft.png"
- if Qt.Key_6 in keys_pressed and self.x() < 1053 and self.y() == 274:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("blueRight.png"))
- PLAYER3_PIC = "blueRight.png"
- if Qt.Key_8 in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if Qt.Key_5 in keys_pressed and ((self.y() == 274 and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4])))
- or (self.y() < 274 and self.x() in range(210, 254))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if self.y() > 274:
- changeGlobalMinus3()
- if self.y() <= 50:
- changeGlobalPlus3()
- if (LEVEL3 == 5 and PLAYER3_LIVES > 0):
- if Qt.Key_4 in keys_pressed and self.x() > 227 and self.y() == 50:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("blueLeft.png"))
- PLAYER3_PIC = "blueLeft.png"
- if Qt.Key_6 in keys_pressed and self.x() < 528 and self.y() == 50:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("blueRight.png"))
- PLAYER3_PIC = "blueRight.png"
- if Qt.Key_5 in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("blueClimb.png"))
- PLAYER3_PIC = "blueClimb.png"
- if self.y() > 50:
- changeGlobalMinus3()
- self.setPos(self.x() + dx, self.y() + dy)
- class Player4(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("purpleRight.png"))
- def game_update(self, keys_pressed, coordinateX, label):
- dx = 0
- dy = 0
- global LEVEL4
- if (LEVEL4 > LEVEL_PLAYER4):
- upLevelPlayer4()
- Player4Points()
- label.setNum(POINTS4)
- if (POINTS4 == 0):
- label.setNum(POINTS4)
- if (LEVEL4 == 1 and PLAYER4_LIVES > 0):
- if Qt.Key_J in keys_pressed and self.x() > 0 and self.y() == 848:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleLeft.png"))
- if Qt.Key_L in keys_pressed and self.x() < SCREEN_WIDTH - 80 and self.y() == 848:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleRight.png"))
- if Qt.Key_I in keys_pressed and (
- self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0]))) and self.y() > 652:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if Qt.Key_K in keys_pressed and self.y() < SCREEN_HEIGHT - 130:
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if self.y() == 652:
- changeGlobalPlus4()
- self.setPos(self.x() + dx, self.y() + dy)
- if (LEVEL4 == 2 and PLAYER4_LIVES > 0):
- if Qt.Key_J in keys_pressed and self.x() > 45 and self.y() == 652:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleLeft.png"))
- if Qt.Key_L in keys_pressed and self.x() < 1053 and self.y() == 652:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleRight.png"))
- if Qt.Key_I in keys_pressed and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or self.x() in range(
- int(coordinateX[2]) - 44, int(coordinateX[2]))) and self.y() > 470:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if Qt.Key_K in keys_pressed and (
- (self.y() == 652 and self.x() in range(int(coordinateX[0]) - 44, int(coordinateX[0])))
- or (self.y() < 652 and (self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1]))
- or (self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2])))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if self.y() > 652:
- changeGlobalMinus4()
- if self.y() == 470:
- changeGlobalPlus4()
- self.setPos(self.x() + dx, self.y() + dy)
- if (LEVEL4 == 3 and PLAYER4_LIVES > 0):
- if Qt.Key_J in keys_pressed and self.x() > 150 and self.y() == 470:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleLeft.png"))
- if Qt.Key_L in keys_pressed and self.x() < 1158 and self.y() == 470:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleRight.png"))
- if Qt.Key_I in keys_pressed and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3])) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4]))) and self.y() > 274:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if Qt.Key_K in keys_pressed and ((self.y() == 470 and (
- self.x() in range(int(coordinateX[1]) - 44, int(coordinateX[1])) or (
- self.x() in range(int(coordinateX[2]) - 44, int(coordinateX[2]))))
- or (
- self.y() < 470 and (self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))
- or (self.x() in range(int(coordinateX[4]) - 44, int(coordinateX[4]))))))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if self.y() > 470:
- changeGlobalMinus4()
- if self.y() == 274:
- changeGlobalPlus4()
- self.setPos(self.x() + dx, self.y() + dy)
- if (LEVEL4 == 4 and PLAYER4_LIVES > 0):
- if Qt.Key_J in keys_pressed and self.x() > 38 and self.y() == 274:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleLeft.png"))
- if Qt.Key_L in keys_pressed and self.x() < 1053 and self.y() == 274:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleRight.png"))
- if Qt.Key_I in keys_pressed and (self.x() in range(210, 254)) and self.y() > 50:
- dy -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if Qt.Key_K in keys_pressed and ((self.y() == 274 and (
- self.x() in range(int(coordinateX[3]) - 44, int(coordinateX[3]))) or self.x() in range(
- int(coordinateX[4]) - 44, int(coordinateX[4])))
- or (self.y() < 274 and self.x() in range(210, 254))):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if self.y() > 274:
- changeGlobalMinus4()
- if self.y() <= 50:
- changeGlobalPlus4()
- self.setPos(self.x() + dx, self.y() + dy)
- if (LEVEL4 == 5 and PLAYER4_LIVES > 0):
- if Qt.Key_J in keys_pressed and self.x() > 227 and self.y() == 50:
- dx -= PLAYER_SPEED
- self.setPixmap(QPixmap("purpleLeft.png"))
- if Qt.Key_L in keys_pressed and self.x() < 528 and self.y() == 50:
- dx += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleRight.png"))
- if Qt.Key_K in keys_pressed and (self.y() == 50 and self.x() in range(210, 254)):
- dy += PLAYER_SPEED
- self.setPixmap(QPixmap("purpleClimb.png"))
- if self.y() > 50:
- changeGlobalMinus4()
- self.setPos(self.x() + dx, self.y() + dy)
- class PlayerDonkey(QGraphicsPixmapItem):
- def __init__(self, q: mp.Queue, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("donkey.png"))
- self.queue = q
- def game_update(self, keys_pressed, marioPos, luigiPos, scena, bluePos, purplePos):
- dx = 0
- dy = 0
- num = self.queue.get()
- if (int(num) >= 980):
- changeDirection()
- if (int(num) <= 110):
- changeDirection()
- if ((PLAYER1_LIVES > 0) and (
- int(self.y()) == (int(marioPos.y()) - 39) and self.x() in range(int(marioPos.x()) - 20,
- int(marioPos.x()) + 20))):
- changePlayer1Lives()
- ResetPlayer1Level()
- ResetPlayer1Points()
- setLevelTo1()
- # time.sleep(0.5)
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
- scena.removeItem(scena.label.hide())
- scena.removeItem(scena.label2.hide())
- scena.removeItem(marioPos)
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- else:
- pic = QPixmap("luigiWins")
- # pic = QPixmap("gameOver.png")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (PLAYER1_LIVES == 0):
- scena.removeItem(marioPos)
- scena.removeItem(scena.label.hide())
- else:
- marioPos.setPos(SCREEN_WIDTH - 80,
- SCREEN_HEIGHT - 130)
- marioPos.setPixmap(QPixmap("marioLeft.png"))
- if ((PLAYER2_LIVES > 0) and (
- int(self.y()) == (int(luigiPos.y()) - 39) and self.x() in range(int(luigiPos.x()) - 20,
- int(luigiPos.x()) + 20))):
- changePlayer2Lives()
- ResetPlayer2Level()
- ResetPlayer2Points()
- setLevelTo2()
- # time.sleep(0.5)
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
- scena.removeItem(scena.label.hide())
- scena.removeItem(scena.label2.hide())
- scena.removeItem(luigiPos)
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- else:
- pic = QPixmap("luigiWins")
- # pic = QPixmap("gameOver.png")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (PLAYER2_LIVES == 0):
- scena.removeItem(luigiPos)
- scena.removeItem(scena.label2.hide())
- else:
- luigiPos.setPos(30, 848)
- luigiPos.setPixmap(QPixmap("luigiRight.png"))
- if ((PLAYER3_LIVES > 0) and (
- int(self.y()) == (int(bluePos.y()) - 39) and self.x() in range(int(bluePos.x()) - 20,
- int(bluePos.x()) + 20))):
- changePlayer3Lives()
- ResetPlayer3Level()
- ResetPlayer3Points()
- setLevelTo3()
- time.sleep(0.5)
- if (PLAYER3_LIVES == 0):
- scena.removeItem(bluePos)
- scena.removeItem(scena.label5.hide())
- else:
- bluePos.setPos(SCREEN_WIDTH - 150,
- SCREEN_HEIGHT - 130)
- bluePos.setPixmap(QPixmap("blueLeft.png"))
- if ((PLAYER4_LIVES > 0) and (
- int(self.y()) == (int(purplePos.y()) - 39) and self.x() in range(int(purplePos.x()) - 20,
- int(purplePos.x()) + 20))):
- changePlayer4Lives()
- ResetPlayer4Level()
- ResetPlayer4Points()
- setLevelTo4()
- time.sleep(0.5)
- if (PLAYER4_LIVES == 0):
- scena.removeItem(purplePos)
- scena.removeItem(scena.label6.hide())
- else:
- purplePos.setPos(70, 848)
- purplePos.setPixmap(QPixmap("purpleRight.png"))
- if (int(NUM_OF_PLAYERS) == 2):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- else:
- pic = QPixmap("luigiWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (int(NUM_OF_PLAYERS) == 3):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- elif (WINNER == 1):
- pic = QPixmap("luigiWins")
- else:
- pic = QPixmap("blueWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (int(NUM_OF_PLAYERS) == 4):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0 and PLAYER4_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- elif (WINNER == 1):
- pic = QPixmap("luigiWins")
- elif (WINNER == 2):
- pic = QPixmap("blueWins")
- else:
- pic = QPixmap("purpleWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- self.setPos(num, self.y() + dy)
- def donkeyRunner(queue: mp.Queue, zaSkidanje: mp.Queue, levodesno: mp.Queue):
- print("funkcija za queue: ", current_process().pid)
- while True:
- dx = 0
- ld = levodesno.get()
- koordinata = zaSkidanje.get()
- if (koordinata <= 980 and ld == 1):
- dx += MONKEY_SPEED
- if (ld == 0):
- dx -= MONKEY_SPEED
- queue.put(koordinata + dx)
- class PlayerPrincess(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("princessHandsDown.png"))
- def game_update(self, playerDX, playerX, playerY, marioPos, player2X, player2Y, luigiPos, scena, label,
- player3X, player3Y, bluePos, player4X, player4Y, purplePos):
- dx = 0
- dy = 0
- if (int(playerDX) in range(100, 200) or int(playerDX) in range(500, 600)):
- self.setPixmap(QPixmap("princessHandsUp.png"))
- else:
- self.setPixmap(QPixmap("princessHandsDown.png"))
- if (int(playerX) in range(440, 520) and playerY == 50):
- # time.sleep(0.5)
- changeFrameTimems()
- returnPlayerLives()
- ResetPlayer1Level()
- setLevelTo1()
- CurrentLVLUP()
- time.sleep(0.1)
- # label.setNum(CURRENT_LEVEL)
- scena.timer.start(FRAME_TIME_MS, scena)
- marioPos.setPos(SCREEN_WIDTH - 80,
- SCREEN_HEIGHT - 130)
- marioPos.setPixmap(QPixmap("marioLeft.png"))
- if (int(player2X) in range(440, 520) and player2Y == 50):
- # time.sleep(0.5)
- changeFrameTimems()
- returnPlayer2Lives()
- ResetPlayer2Level()
- setLevelTo2()
- CurrentLVLUP()
- time.sleep(0.1)
- # label.setNum(CURRENT_LEVEL)
- scena.timer.start(FRAME_TIME_MS, scena)
- luigiPos.setPos(30, 848)
- luigiPos.setPixmap(QPixmap("luigiRight.png"))
- if (player3X == 500 and player3Y == 50):
- # time.sleep(0.5)
- changeFrameTimems()
- returnPlayer3Lives()
- ResetPlayer3Level()
- setLevelTo3()
- CurrentLVLUP()
- # label.setNum(CURRENT_LEVEL)
- scena.timer.start(FRAME_TIME_MS, scena)
- bluePos.setPos(SCREEN_WIDTH - 150,
- SCREEN_HEIGHT - 130)
- bluePos.setPixmap(QPixmap("blueLeft.png"))
- if (player4X == 462 and player4Y == 50):
- # time.sleep(0.5)
- changeFrameTimems()
- returnPlayer4Lives()
- ResetPlayer4Level()
- setLevelTo4()
- CurrentLVLUP()
- # label.setNum(CURRENT_LEVEL)
- scena.timer.start(FRAME_TIME_MS, scena)
- purplePos.setPos(70, 848)
- purplePos.setPixmap(QPixmap("purpleRight.png"))
- class Player1Lives(QGraphicsPixmapItem):
- def __init__(self, q: mp.Queue, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPos(1160, 10)
- self.queue = q
- def listen(self):
- num = self.queue.get()
- self.game_update(num)
- def game_update(self, num):
- broj = num
- if (broj == 3):
- self.setPixmap(QPixmap("3heart.png"))
- self.setPos(1160, 10)
- elif (broj == 2):
- self.setPixmap(QPixmap("2heart.png"))
- self.setPos(1200, 10)
- elif (broj == 1):
- self.setPixmap(QPixmap("1heart.png"))
- self.setPos(1240, 10)
- else:
- ChangeWinner()
- self.hide()
- def runner2(queue: mp.Queue, zaSkidanje: mp.Queue):
- print("funkcija za queue: ", current_process().pid)
- while True:
- broj = zaSkidanje.get()
- queue.put(broj)
- class Player2Lives(QGraphicsPixmapItem):
- def __init__(self, q: mp.Queue, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.queue = q
- def listen(self):
- num = self.queue.get()
- self.game_update(num)
- def game_update(self, num):
- broj = num
- if (broj == 3):
- self.setPixmap(QPixmap("3heartGreen.png"))
- self.setPos(10, 10)
- elif (broj == 2):
- self.setPixmap(QPixmap("2heartGreen.png"))
- self.setPos(10, 10)
- elif (broj == 1):
- self.setPixmap(QPixmap("1heartGreen.png"))
- self.setPos(10, 10)
- else:
- self.hide()
- class Player3Lives(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- def game_update(self):
- if (PLAYER3_LIVES == 3):
- self.setPixmap(QPixmap("3heartGreenBlue.png"))
- self.setPos(1000, 10)
- elif (PLAYER3_LIVES == 2):
- self.setPixmap(QPixmap("2heartGreenBlue.png"))
- self.setPos(1040, 10)
- elif (PLAYER3_LIVES == 1):
- self.setPixmap(QPixmap("1heartBlue.png"))
- self.setPos(1080, 10)
- else:
- ChangeWinner(2)
- self.hide()
- class Player4Lives(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- def game_update(self):
- if (PLAYER4_LIVES == 3):
- self.setPixmap(QPixmap("3heartPurple.png"))
- self.setPos(150, 10)
- elif (PLAYER4_LIVES == 2):
- self.setPixmap(QPixmap("2heartPurple.png"))
- self.setPos(150, 10)
- elif (PLAYER4_LIVES == 1):
- self.setPixmap(QPixmap("1heartPurple.png"))
- self.setPos(150, 10)
- else:
- ChangeWinner(3)
- self.hide()
- def runner(queue: mp.Queue, zaSkidanje: mp.Queue):
- print("funkcija za queue: ", current_process().pid)
- while True:
- broj = zaSkidanje.get()
- queue.put(broj)
- class Bullet(QGraphicsPixmapItem):
- def __init__(self, offset_x, offset_y, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("barrel.png"))
- self.offset_x = offset_x
- self.offset_y = offset_y
- self.active = False
- self.frames = 0
- def game_update(self, timer, player, playerP, player2, scena, player3, player4):
- if not self.active:
- if timer.isActive():
- self.active = True
- self.setPos(player.x(), player.y() + 50)
- self.frames = BULLET_FRAMES
- else:
- self.setPos(self.x(), self.y() + BULLET_SPEED)
- self.frames -= 1
- if ((self.y() in range(int(playerP.y()), int(playerP.y()) + 80) and self.x() in range(int(playerP.x()) - 40,
- int(
- playerP.x()) + 80)) and PLAYER1_LIVES > 0):
- playerP.setPixmap(QPixmap("marioDown.png"))
- changePlayer1Lives()
- ResetPlayer1Level()
- ResetPlayer1Points()
- setLevelTo1()
- # time.sleep(1)
- if (PLAYER1_LIVES == 0):
- scena.removeItem(playerP)
- scena.removeItem(scena.label.hide())
- else:
- playerP.setPos(SCREEN_WIDTH - 80,
- SCREEN_HEIGHT - 130)
- playerP.setPixmap(QPixmap("marioLeft.png"))
- if ((PLAYER2_LIVES > 0) and (
- self.y() in range(int(player2.y()), int(player2.y()) + 80) and self.x() in range(
- int(player2.x()) - 40,
- int(player2.x()) + 80))):
- changePlayer2Lives()
- ResetPlayer2Level()
- ResetPlayer2Points()
- setLevelTo2()
- # time.sleep(1)
- if (PLAYER2_LIVES == 0):
- scena.removeItem(player2)
- scena.removeItem(scena.label2.hide())
- else:
- player2.setPos(30, 848)
- player2.setPixmap(QPixmap("luigiRight.png"))
- if ((PLAYER3_LIVES > 0) and (
- self.y() in range(int(player3.y()), int(player3.y()) + 80) and self.x() in range(
- int(player3.x()) - 40,
- int(player3.x()) + 80))):
- changePlayer3Lives()
- ResetPlayer3Level()
- ResetPlayer3Points()
- setLevelTo3()
- # time.sleep(1)
- if (PLAYER3_LIVES == 0):
- scena.removeItem(player3)
- scena.removeItem(scena.label5.hide())
- else:
- player3.setPos(SCREEN_WIDTH - 150,
- SCREEN_HEIGHT - 130)
- player3.setPixmap(QPixmap("blueLeft.png"))
- if ((PLAYER4_LIVES > 0) and (
- self.y() in range(int(player4.y()), int(player4.y()) + 80) and self.x() in range(
- int(player4.x()) - 40,
- int(player4.x()) + 80))):
- changePlayer4Lives()
- ResetPlayer4Level()
- ResetPlayer4Points()
- setLevelTo4()
- # time.sleep(1)
- if (PLAYER4_LIVES == 0):
- scena.removeItem(player4)
- scena.removeItem(scena.label6.hide())
- else:
- player4.setPos(70, 848)
- player4.setPixmap(QPixmap("purpleRight.png"))
- if (int(NUM_OF_PLAYERS) == 2):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- else:
- pic = QPixmap("luigiWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (int(NUM_OF_PLAYERS) == 3):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- elif (WINNER == 1):
- pic = QPixmap("luigiWins")
- else:
- pic = QPixmap("blueWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- elif (int(NUM_OF_PLAYERS) == 4):
- if (PLAYER1_LIVES == 0 and PLAYER2_LIVES == 0 and PLAYER3_LIVES == 0 and PLAYER4_LIVES == 0):
- if (WINNER == 0):
- pic = QPixmap("marioWins")
- elif (WINNER == 1):
- pic = QPixmap("luigiWins")
- elif (WINNER == 2):
- pic = QPixmap("blueWins")
- else:
- pic = QPixmap("purpleWins")
- scena.addItem(QGraphicsPixmapItem(pic))
- if self.frames <= 0:
- self.active = False
- self.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
- class Ladder(QGraphicsPixmapItem):
- def __init__(self, parent=None):
- QGraphicsPixmapItem.__init__(self, parent)
- self.setPixmap(QPixmap("ladder.png"))
- class Scene(QGraphicsScene):
- def __init__(self, q: mp.Queue, red: mp.Queue, q2: mp.Queue, red0: mp.Queue, monQ: mp.Queue, monQ1: mp.Queue,
- queueLevoDesno: mp.Queue, socSend: socket.socket, socRecv: socket.socket, parent=None):
- QGraphicsScene.__init__(self, parent)
- self.socSend = socSend
- self.socRecv = socRecv
- text = self.socSend.recv(1024)
- # self.socRecv.bind((HOST, PORTRECV))
- # self.socRecv.listen(1)
- # self.conn, addr = self.socRecv.accept()
- #
- # text = ''
- # while True:
- # bin = self.conn.recv(1024)
- # text += str(bin, 'utf-8')
- # if not bin or len(bin) < 1024:
- # break
- # print('Received', text)
- # hold the set of keys we're pressing
- self.keys_pressed = set()
- # use a timer to get 60Hz refresh (hopefully)
- self.timer = QBasicTimer()
- self.timer.start(FRAME_TIME_MS, self)
- bg = QGraphicsRectItem()
- bg.setRect(-1, -1, SCREEN_WIDTH + 2, SCREEN_HEIGHT + 2)
- bg.setBrush(QBrush(Qt.white))
- self.red1 = red
- self.red2 = red0
- self.queueLevoDesno = queueLevoDesno
- self.monkeyPosition = monQ1
- self.addItem(bg)
- pic = QPixmap("backgroundOriginal.png")
- self.addItem(QGraphicsPixmapItem(pic))
- self.ladders = []
- self.laddersCoordinates = eval(text)
- for i in range(5):
- self.ladders.append(Ladder())
- # rand1 = random.randint(73, 1025)
- self.ladders[0].setPos(self.laddersCoordinates[0], 745)
- self.addItem(self.ladders[0])
- # self.laddersCoordinates.append(rand1)
- # rand1 = random.randint(185, 600)
- self.ladders[1].setPos(self.laddersCoordinates[1], 560)
- self.addItem(self.ladders[1])
- # self.laddersCoordinates.append(rand1)
- # rand1 = random.randint(710, 1018)
- self.ladders[2].setPos(self.laddersCoordinates[2], 560)
- self.addItem(self.ladders[2])
- # self.laddersCoordinates.append(rand1)
- # rand1 = random.randint(157, 542)
- self.ladders[3].setPos(self.laddersCoordinates[3], 365)
- self.addItem(self.ladders[3])
- # self.laddersCoordinates.append(rand1)
- # rand1 = random.randint(620, 1032)
- self.ladders[4].setPos(self.laddersCoordinates[4], 365)
- self.addItem(self.ladders[4])
- # self.laddersCoordinates.append(rand1)
- global PLAYER_ID
- PLAYER_ID = self.laddersCoordinates[5]
- self.heart1 = Player1Lives(q2)
- self.heart2 = Player2Lives(q)
- self.heart3 = Player3Lives()
- self.heart4 = Player4Lives()
- if (int(NUM_OF_PLAYERS) == 2):
- self.addItem(self.heart1)
- self.addItem(self.heart2)
- elif (int(NUM_OF_PLAYERS) == 3):
- self.addItem(self.heart1)
- self.addItem(self.heart2)
- self.addItem(self.heart3)
- elif (int(NUM_OF_PLAYERS) == 4):
- self.addItem(self.heart1)
- self.addItem(self.heart2)
- self.addItem(self.heart3)
- self.addItem(self.heart4)
- self.playerD = PlayerDonkey(monQ)
- self.playerD.setPos(640, 235)
- self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y)]
- for b in self.bullets:
- b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
- self.addItem(b)
- self.addItem(self.playerD)
- self.playerP = PlayerPrincess()
- self.playerP.setPos(500, 60)
- self.bullets = [Bullet(PLAYER_BULLET_X_OFFSETS[0], PLAYER_BULLET_Y)]
- for b in self.bullets:
- b.setPos(SCREEN_WIDTH, SCREEN_HEIGHT)
- self.addItem(b)
- self.addItem(self.playerP)
- self.player = Player()
- self.player.setPos(SCREEN_WIDTH - 80,
- SCREEN_HEIGHT - 130)
- self.addItem(self.player)
- self.player2 = Player2()
- self.player2.setPos(30, 848)
- self.addItem(self.player2)
- self.player3 = Player3()
- self.player4 = Player4()
- if (int(NUM_OF_PLAYERS) == 2):
- self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
- self.addItem(self.player)
- self.player2.setPos(30, 848)
- self.addItem(self.player2)
- elif (int(NUM_OF_PLAYERS) == 3):
- self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
- self.addItem(self.player)
- self.player2.setPos(30, 848)
- self.addItem(self.player2)
- self.player3.setPos(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 130)
- self.addItem(self.player3)
- elif (int(NUM_OF_PLAYERS) == 4):
- self.player.setPos(SCREEN_WIDTH - 80, SCREEN_HEIGHT - 130)
- self.addItem(self.player)
- self.player2.setPos(30, 848)
- self.addItem(self.player2)
- self.player3.setPos(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 130)
- self.addItem(self.player3)
- self.player4.setPos(70, 848)
- self.addItem(self.player4)
- self.view = QGraphicsView(self)
- self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
- self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
- self.view.show()
- self.view.setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT)
- self.setSceneRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
- self.label = QLabel()
- self.label.setGeometry(1240, 50, 100, 100)
- self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label.setStyleSheet('color: white')
- self.label.setAutoFillBackground(True)
- widget = QWidget()
- paleta = widget.palette()
- paleta.setColor(widget.backgroundRole(), Qt.transparent)
- self.label.setPalette(paleta)
- self.label.setNum(POINTS1)
- self.addWidget(self.label)
- self.label2 = QLabel()
- self.label2.setGeometry(10, 50, 100, 100)
- self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label2.setStyleSheet('color: white')
- self.label2.setAutoFillBackground(True)
- widget2 = QWidget()
- paleta2 = widget2.palette()
- paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
- self.label2.setPalette(paleta2)
- self.label2.setNum(POINTS2)
- self.addWidget(self.label2)
- self.label3 = QLabel()
- self.label3.setGeometry(600, 0, 100, 40)
- self.label3.setFont(QFont("Times New Roman", 25, QFont.Bold))
- self.label3.setStyleSheet('color: white')
- self.label3.setAutoFillBackground(True)
- widget3 = QWidget()
- paleta3 = widget3.palette()
- paleta3.setColor(widget3.backgroundRole(), Qt.transparent)
- self.label3.setPalette(paleta3)
- self.label3.setText("Level")
- self.addWidget(self.label3)
- self.label4 = QLabel()
- self.label4.setGeometry(700, 0, 100, 40)
- self.label4.setFont(QFont("Times New Roman", 25, QFont.Bold))
- self.label4.setStyleSheet('color: white')
- self.label4.setAutoFillBackground(True)
- widget4 = QWidget()
- paleta4 = widget4.palette()
- paleta4.setColor(widget4.backgroundRole(), Qt.transparent)
- self.label4.setPalette(paleta4)
- self.label4.setNum(CURRENT_LEVEL)
- self.addWidget(self.label4)
- if (int(NUM_OF_PLAYERS) == 2):
- self.label = QLabel()
- self.label.setGeometry(1240, 50, 100, 100)
- self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label.setStyleSheet('color: white')
- self.label.setAutoFillBackground(True)
- widget = QWidget()
- paleta = widget.palette()
- paleta.setColor(widget.backgroundRole(), Qt.transparent)
- self.label.setPalette(paleta)
- self.label.setNum(POINTS1)
- self.addWidget(self.label)
- self.label2 = QLabel()
- self.label2.setGeometry(10, 50, 100, 100)
- self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label2.setStyleSheet('color: white')
- self.label2.setAutoFillBackground(True)
- widget2 = QWidget()
- paleta2 = widget2.palette()
- paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
- self.label2.setPalette(paleta2)
- self.label2.setNum(POINTS2)
- self.addWidget(self.label2)
- elif (int(NUM_OF_PLAYERS) == 3):
- self.label = QLabel()
- self.label.setGeometry(1240, 50, 100, 100)
- self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label.setStyleSheet('color: white')
- self.label.setAutoFillBackground(True)
- widget = QWidget()
- paleta = widget.palette()
- paleta.setColor(widget.backgroundRole(), Qt.transparent)
- self.label.setPalette(paleta)
- self.label.setNum(POINTS1)
- self.addWidget(self.label)
- self.label2 = QLabel()
- self.label2.setGeometry(10, 50, 100, 100)
- self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label2.setStyleSheet('color: white')
- self.label2.setAutoFillBackground(True)
- widget2 = QWidget()
- paleta2 = widget2.palette()
- paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
- self.label2.setPalette(paleta2)
- self.label2.setNum(POINTS2)
- self.addWidget(self.label2)
- self.label5 = QLabel()
- self.label5.setGeometry(1080, 50, 100, 100)
- self.label5.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label5.setStyleSheet('color: white')
- self.label5.setAutoFillBackground(True)
- widget5 = QWidget()
- paleta5 = widget5.palette()
- paleta5.setColor(widget5.backgroundRole(), Qt.transparent)
- self.label5.setPalette(paleta5)
- self.label5.setNum(POINTS3)
- self.addWidget(self.label5)
- elif (int(NUM_OF_PLAYERS) == 4):
- self.label = QLabel()
- self.label.setGeometry(1240, 50, 100, 100)
- self.label.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label.setStyleSheet('color: white')
- self.label.setAutoFillBackground(True)
- widget = QWidget()
- paleta = widget.palette()
- paleta.setColor(widget.backgroundRole(), Qt.transparent)
- self.label.setPalette(paleta)
- self.label.setNum(POINTS1)
- self.addWidget(self.label)
- self.label2 = QLabel()
- self.label2.setGeometry(10, 50, 100, 100)
- self.label2.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label2.setStyleSheet('color: white')
- self.label2.setAutoFillBackground(True)
- widget2 = QWidget()
- paleta2 = widget2.palette()
- paleta2.setColor(widget2.backgroundRole(), Qt.transparent)
- self.label2.setPalette(paleta2)
- self.label2.setNum(POINTS2)
- self.addWidget(self.label2)
- self.label5 = QLabel()
- self.label5.setGeometry(1080, 50, 100, 100)
- self.label5.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label5.setStyleSheet('color: white')
- self.label5.setAutoFillBackground(True)
- widget5 = QWidget()
- paleta5 = widget5.palette()
- paleta5.setColor(widget5.backgroundRole(), Qt.transparent)
- self.label5.setPalette(paleta5)
- self.label5.setNum(POINTS3)
- self.addWidget(self.label5)
- self.label6 = QLabel()
- self.label6.setGeometry(150, 50, 100, 100)
- self.label6.setFont(QFont("Times New Roman", 50, QFont.Bold))
- self.label6.setStyleSheet('color: white')
- self.label6.setAutoFillBackground(True)
- widget6 = QWidget()
- paleta6 = widget6.palette()
- paleta6.setColor(widget6.backgroundRole(), Qt.transparent)
- self.label6.setPalette(paleta6)
- self.label6.setNum(POINTS4)
- self.addWidget(self.label6)
- def keyPressEvent(self, event):
- self.keys_pressed.add(event.key())
- def keyReleaseEvent(self, event):
- self.keys_pressed.remove(event.key())
- def timerEvent(self, event):
- self.game_update()
- self.update()
- def game_update(self):
- global LEVEL
- global LEVEL2
- global LEVEL3
- global LEVEL4
- global POINTS1
- global POINTS2
- global POINTS3
- global POINTS4
- global PLAYER1_LIVES
- global PLAYER2_LIVES
- global PLAYER3_LIVES
- global PLAYER4_LIVES
- global PLAYER2_PIC
- global PLAYER1_PIC
- global PLAYER3_PIC
- global PLAYER4_PIC
- global CURRENT_LEVEL
- global FRAME_TIME_MS
- self.red2.put(PLAYER1_LIVES)
- self.red1.put(PLAYER2_LIVES)
- text2send = str(self.playerD.x())
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- self.monkeyPosition.put(float(text))
- self.queueLevoDesno.put(LEVO_DESNO)
- self.player.game_update(self.keys_pressed, self.laddersCoordinates, self.label)
- posX = str(self.player.x())
- posY = str(self.player.y())
- points1 = str(POINTS1)
- level1 = str(LEVEL)
- curLevel = str(CURRENT_LEVEL)
- koordinata = posX + ',' + posY + ',' + points1 + ',' + level1 + ',' + PLAYER1_PIC
- text2send = str(koordinata)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- x = text.split(',')
- self.player.setPos(float(x[0]), float(x[1]))
- POINTS1 = int(x[2])
- LEVEL = int(x[3])
- self.player.setPixmap(QPixmap(x[4]))
- # CURRENT_LEVEL = int(x[5])
- # self.label4.setNum(CURRENT_LEVEL)
- currLevel = str(CURRENT_LEVEL) # SLANJE NIVOA I PRIMANJE ISTOG
- time_frame_ms = str(FRAME_TIME_MS)
- text2send = currLevel + ',' + time_frame_ms
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- ret = text.split(',')
- CURRENT_LEVEL = int(ret[0])
- FRAME_TIME_MS = int(ret[1])
- self.label4.setNum(CURRENT_LEVEL)
- self.player2.game_update(self.keys_pressed, self.laddersCoordinates, self.label2)
- posX = str(self.player2.x())
- posY = str(self.player2.y())
- points2 = str(POINTS2)
- level2 = str(LEVEL2)
- curLevel = str(CURRENT_LEVEL)
- koordinata = posX + ',' + posY + ',' + points2 + ',' + level2 + ',' + PLAYER2_PIC
- text2send = str(koordinata)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- x = text.split(',')
- self.player2.setPos(float(x[0]), float(x[1]))
- POINTS2 = int(x[2])
- LEVEL2 = int(x[3])
- self.player2.setPixmap(QPixmap(x[4]))
- # CURRENT_LEVEL = int(x[5])
- # self.label4.setNum(CURRENT_LEVEL)
- if (int(NUM_OF_PLAYERS) == 3 or int(NUM_OF_PLAYERS) == 4):
- self.player3.game_update(self.keys_pressed, self.laddersCoordinates, self.label5) # PLAYER 3 GAME UPDATE
- posX = str(self.player3.x())
- posY = str(self.player3.y())
- points3 = str(POINTS3)
- level3 = str(LEVEL3)
- curLevel = str(CURRENT_LEVEL)
- koordinata = posX + ',' + posY + ',' + points3 + ',' + level3 + ',' + PLAYER3_PIC
- text2send = str(koordinata)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- x = text.split(',')
- self.player3.setPos(float(x[0]), float(x[1]))
- POINTS3 = int(x[2])
- LEVEL3 = int(x[3])
- self.player3.setPixmap(QPixmap(x[4]))
- if (int(NUM_OF_PLAYERS) == 4):
- self.player4.game_update(self.keys_pressed, self.laddersCoordinates, self.label6) # PLAYER 4 GAME UPDATE
- posX = str(self.player4.x())
- posY = str(self.player4.y())
- points4 = str(POINTS4)
- level4 = str(LEVEL4)
- curLevel = str(CURRENT_LEVEL)
- koordinata = posX + ',' + posY + ',' + points4 + ',' + level4 + ',' + PLAYER4_PIC
- text2send = str(koordinata)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- x = text.split(',')
- self.player4.setPos(float(x[0]), float(x[1]))
- POINTS4 = int(x[2])
- LEVEL4 = int(x[3])
- self.player4.setPixmap(QPixmap(x[4]))
- self.playerD.game_update(self.keys_pressed, self.player, self.player2, self, self.player3, self.player4)
- self.playerP.game_update(self.playerD.x(), self.player.x(), self.player.y(), self.player, self.player2.x(),
- self.player2.y(), self.player2, self, self.label4, self.player3.x(), self.player3.y(),
- self.player3, self.player4.x(), self.player4.y(), self.player4)
- self.heart1.listen()
- numOfLives1 = PLAYER1_LIVES
- text2send = str(numOfLives1)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- PLAYER1_LIVES = int(text)
- self.heart2.listen()
- numOfLives2 = PLAYER2_LIVES
- text2send = str(numOfLives2)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- PLAYER2_LIVES = int(text)
- if (NUM_OF_PLAYERS == 3 or NUM_OF_PLAYERS == 4):
- self.heart3.game_update() # PLAYER 3 LIVES
- numOfLives3 = PLAYER3_LIVES
- text2send = str(numOfLives3)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- PLAYER3_LIVES = int(text)
- if (NUM_OF_PLAYERS == 4):
- self.heart4.game_update() # PLAYER 4 LIVES
- numOfLives4 = PLAYER4_LIVES
- text2send = str(numOfLives4)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- PLAYER4_LIVES = int(text)
- for b in self.bullets:
- b.game_update(self.timer, self.playerD, self.player, self.player2, self, self.player3, self.player4)
- posX = str(b.x())
- posY = str(b.y())
- koordinata = posX + ',' + posY
- text2send = str(koordinata)
- self.socSend.sendall(text2send.encode('utf8'))
- text = ''
- while True:
- bin = self.socSend.recv(1024)
- text += str(bin, 'utf-8')
- if not bin or len(bin) < 1024:
- break
- x = text.split(',')
- b.setPos(float(x[0]), float(x[1]))
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- socketSend = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- socketSend.connect((HOST, PORTSEND))
- socketRecv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- queue = mp.Queue()
- queue1 = mp.Queue()
- queue2 = mp.Queue()
- queue3 = mp.Queue()
- queueMonkey = mp.Queue()
- queueMonkey1 = mp.Queue()
- queueLevoDesno = mp.Queue()
- proces = mp.Process(target=runner, args=[queue, queue1])
- proces.daemon = True
- proces.start()
- proces2 = mp.Process(target=runner2, args=[queue2, queue3])
- proces2.daemon = True
- proces2.start()
- procesMonkey = mp.Process(target=donkeyRunner, args=[queueMonkey, queueMonkey1, queueLevoDesno])
- procesMonkey.daemon = True
- procesMonkey.start()
- scene = Scene(queue, queue1, queue2, queue3, queueMonkey, queueMonkey1, queueLevoDesno, socketSend, socketRecv)
- print("main: ", current_process().pid)
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement