Ejemplo n.º 1
0
    def registerPlayerEvent(self):
        ball = self.ball
        for object in self.objectList:
            if 'Player' in object.name:
                player = object

        #ball + player
        sounds.playSound("BallPlayer", ball.geom.getPosition())
        lastTouchedObject = self.events['lastTouchedObject']

        if lastTouchedObject == None:  #picked from middle line
            self.scoreBoard.resetJoinedCombo()  #clear combo
            self.scoreBoard.incrementCombo(player, self.hitMsgList)  #(+1)
        else:  #picked from ground or player
            if lastTouchedObject.name == 'Ground':  #picked from ground inside
                self.scoreBoard.resetJoinedCombo()
                playerName = player.name
                self.scoreBoard.incrementCombo(player, self.hitMsgList)
                if (self.events['lastFieldOwner'] == player)\
                  and (self.events['lastTouchedPlayer'] == player)\
                  and vectormath.isPointInSquare(ball.geom.getPosition()
                                                 , self.players[playerName].min
                                                 , self.players[playerName].max): #critical event. double-touched -> fault

                    if playerName == "Player":
                        pl = self.players[[
                            "Player_Red", "Player_Green", "Player_Yellow"
                        ][randint(0, 2)]]
                        #pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
                        #while pl2==pl:
                        #  pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]

                        sounds.playTauntMsg(pl, "AreYouCrazy",
                                            pl.body.getPosition())
                        self.addTaunt(pl, "Are you crazy?")

                        #sounds.playTauntMsg(pl2, "No", pl.body.getPosition())
                        #self.addTaunt(pl2, "No!")

                    resetCoords = self.getBallCoords(playerName)
                    self.scoreBoard.addSelfPoints(playerName)
                    self.faultMsgList.append(
                        [playerName + ' touched twice!', '1', 0])
                    if self.scoreBoard[playerName][0] >= self.matchPoints:
                        self.setGameOver()
                        return
                    self.initEvents()
                    self.resetBall(resetCoords)
                    self.resetPlayers()
                    return
            else:  #picked from player
                if self.events[
                        'lastTouchedPlayer'] != player:  #reset own combo, when picked from other
                    self.scoreBoard.resetOwnCombo(player.name)
                self.scoreBoard.incrementCombo(player, self.hitMsgList)

        self.events['lastTouchedObject'] = player
        self.events['lastTouchedPlayer'] = player
Ejemplo n.º 2
0
  def registerPlayerEvent(self):
    ball = self.ball
    for object in self.objectList:
      if 'Player' in object.name:
        player = object
    
    #ball + player
    sounds.playSound("BallPlayer", ball.geom.getPosition())
    lastTouchedObject = self.events['lastTouchedObject']
    
    if lastTouchedObject == None: #picked from middle line
      self.scoreBoard.resetJoinedCombo() #clear combo
      self.scoreBoard.incrementCombo(player, self.hitMsgList) #(+1)
    else:#picked from ground or player
      if lastTouchedObject.name == 'Ground': #picked from ground inside
        self.scoreBoard.resetJoinedCombo()
        playerName = player.name
        self.scoreBoard.incrementCombo(player, self.hitMsgList)
        if (self.events['lastFieldOwner'] == player)\
          and (self.events['lastTouchedPlayer'] == player)\
          and vectormath.isPointInSquare(ball.geom.getPosition()
                                         , self.players[playerName].min
                                         , self.players[playerName].max): #critical event. double-touched -> fault

          if playerName=="Player":
            pl = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
            #pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
            #while pl2==pl:
            #  pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]

            sounds.playTauntMsg(pl, "AreYouCrazy", pl.body.getPosition())
            self.addTaunt(pl, "Are you crazy?")

            #sounds.playTauntMsg(pl2, "No", pl.body.getPosition())
            #self.addTaunt(pl2, "No!")

          resetCoords = self.getBallCoords(playerName)
          self.scoreBoard.addSelfPoints(playerName)
          self.faultMsgList.append([playerName + ' touched twice!', '1', 0])
          if self.scoreBoard[playerName][0] >= self.matchPoints:
            self.setGameOver()
            return
          self.initEvents()
          self.resetBall(resetCoords)
          self.resetPlayers()
          return 
      else: #picked from player
        if self.events['lastTouchedPlayer'] != player: #reset own combo, when picked from other
          self.scoreBoard.resetOwnCombo(player.name)
        self.scoreBoard.incrementCombo(player, self.hitMsgList)
        
    self.events['lastTouchedObject'] = player
    self.events['lastTouchedPlayer'] = player
Ejemplo n.º 3
0
  def registerGroundEvent(self):
    #our objects of interest:
    ball, ground = self.ball, None

    #asign objects of interest
    for object in self.objectList:
      if object.name == 'Ground':
        ground = object

    #handle events
    ballCoords = ball.geom.getPosition()
    #ball + ground

    if ball.body.getLinearVel()[1] < -0.3:
      sounds.playSound("BallGround", ballCoords)

    if not vectormath.isPointInSquare(ballCoords, (-10, -10), (10, 10)): #critical event
      #BALL HAS HIT THE FIELD OUTSIDE
      #and we handle score here

      out = False

      if self.events['lastTouchedObject'] != None: #if last touched was not middle line
        lastTouchedObject = self.events['lastTouchedObject'].name
        if 'Player' in lastTouchedObject:
          #player has kicked the ball out
          pts = self.scoreBoard.addSelfPoints(lastTouchedObject)
          resetCoords = self.getBallCoords(lastTouchedObject)
          self.faultMsgList.append(['Out from ' + lastTouchedObject + '!', str(pts), 0])

          out = lastTouchedObject
          
          getsPoints = lastTouchedObject
        elif self.events['lastFieldOwner']: #if ground was touched in one of the players field last add points to owner
          owner = self.events['lastFieldOwner'].name
          if self.events['lastTouchedPlayer']:
            #case when noone touched the ball after throwing minus
            lastPlayer = self.events['lastTouchedPlayer'].name
            if owner == lastPlayer:
              pts = self.scoreBoard.addSelfPoints(owner)
            else:
              pts = self.scoreBoard.addTotalPoints(owner)
          else:
            pts = self.scoreBoard.addPoint(owner)

          out = owner

          self.faultMsgList.append(['Out from ' + owner + '`s field!', str(pts), 0])
          resetCoords = self.getBallCoords(owner)
          getsPoints = owner
        if self.scoreBoard[getsPoints][0] >= self.matchPoints:
          self.setGameOver()
          return
      else:
        self.faultMsgList.append(['Ball out from middle line!', '', 0])
        resetCoords = (0, 10, 0)

      if out=="Player":
        pl = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
        #pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
        #while pl2==pl:
        #  pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]

        sounds.playTauntMsg(pl, "GreatShot", pl.body.getPosition())
        self.addTaunt(pl, "Great shot!")

        #    sounds.playTauntMsg(pl2, "Yes", pl.body.getPosition())
        #    self.addTaunt(pl2, "Yes!")

##      print self.scoreBoard

      #finishing handling critical branch
      self.scoreBoard.resetJoinedCombo()
      self.initEvents()
      self.resetBall(resetCoords)
      self.resetPlayers()
      if out!=False and out!="Player":
        pl = self.players[out]
        sounds.playTauntMsg(pl, "MoveIn", pl.body.getPosition())
        self.addTaunt(pl, "Move in!")


    else:
      #BALL HAS HIT THE FIELD INSIDE
      #save the touched field
      for p in self.players.values():
        if self.checkIsBallInSquare(ballCoords, p.min, p.max):
          self.events['lastFieldOwner'] = p.geom
          self.events['lastTouchedObject'] = ground
          break
        self.events['lastTouchedObject'] = None #if has hit the middle line
Ejemplo n.º 4
0
    def registerGroundEvent(self):
        #our objects of interest:
        ball, ground = self.ball, None

        #asign objects of interest
        for object in self.objectList:
            if object.name == 'Ground':
                ground = object

        #handle events
        ballCoords = ball.geom.getPosition()
        #ball + ground

        if ball.body.getLinearVel()[1] < -0.3:
            sounds.playSound("BallGround", ballCoords)

        if not vectormath.isPointInSquare(ballCoords, (-10, -10),
                                          (10, 10)):  #critical event
            #BALL HAS HIT THE FIELD OUTSIDE
            #and we handle score here

            out = False

            if self.events[
                    'lastTouchedObject'] != None:  #if last touched was not middle line
                lastTouchedObject = self.events['lastTouchedObject'].name
                if 'Player' in lastTouchedObject:
                    #player has kicked the ball out
                    pts = self.scoreBoard.addSelfPoints(lastTouchedObject)
                    resetCoords = self.getBallCoords(lastTouchedObject)
                    self.faultMsgList.append(
                        ['Out from ' + lastTouchedObject + '!',
                         str(pts), 0])

                    out = lastTouchedObject

                    getsPoints = lastTouchedObject
                elif self.events[
                        'lastFieldOwner']:  #if ground was touched in one of the players field last add points to owner
                    owner = self.events['lastFieldOwner'].name
                    if self.events['lastTouchedPlayer']:
                        #case when noone touched the ball after throwing minus
                        lastPlayer = self.events['lastTouchedPlayer'].name
                        if owner == lastPlayer:
                            pts = self.scoreBoard.addSelfPoints(owner)
                        else:
                            pts = self.scoreBoard.addTotalPoints(owner)
                    else:
                        pts = self.scoreBoard.addPoint(owner)

                    out = owner

                    self.faultMsgList.append(
                        ['Out from ' + owner + '`s field!',
                         str(pts), 0])
                    resetCoords = self.getBallCoords(owner)
                    getsPoints = owner
                if self.scoreBoard[getsPoints][0] >= self.matchPoints:
                    self.setGameOver()
                    return
            else:
                self.faultMsgList.append(['Ball out from middle line!', '', 0])
                resetCoords = (0, 10, 0)

            if out == "Player":
                pl = self.players[[
                    "Player_Red", "Player_Green", "Player_Yellow"
                ][randint(0, 2)]]
                #pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]
                #while pl2==pl:
                #  pl2 = self.players[["Player_Red", "Player_Green", "Player_Yellow"][randint(0,2)]]

                sounds.playTauntMsg(pl, "GreatShot", pl.body.getPosition())
                self.addTaunt(pl, "Great shot!")

                #    sounds.playTauntMsg(pl2, "Yes", pl.body.getPosition())
                #    self.addTaunt(pl2, "Yes!")


##      print self.scoreBoard

#finishing handling critical branch
            self.scoreBoard.resetJoinedCombo()
            self.initEvents()
            self.resetBall(resetCoords)
            self.resetPlayers()
            if out != False and out != "Player":
                pl = self.players[out]
                sounds.playTauntMsg(pl, "MoveIn", pl.body.getPosition())
                self.addTaunt(pl, "Move in!")

        else:
            #BALL HAS HIT THE FIELD INSIDE
            #save the touched field
            for p in self.players.values():
                if self.checkIsBallInSquare(ballCoords, p.min, p.max):
                    self.events['lastFieldOwner'] = p.geom
                    self.events['lastTouchedObject'] = ground
                    break
                self.events[
                    'lastTouchedObject'] = None  #if has hit the middle line