def applyInputs(self, entryIndex): W, H = glfwGetWindowSize() mx, my = glfwGetMousePos() my = -my if (mx, my + H) != self.cursorPos: if mx <= 0: mx = 0 if mx >= W: mx = W if my >= 0: my = 0 if my <= -H: my = -H self.cursorPos = (mx, my + H) glfwSetMousePos(mx, -my) #if mousebutton1 is pressed, enter selected menu W, H = glfwGetWindowSize() menuY = H / 2 + 50 * self.entryFontScale for i in range(len(self)): pos = i + 1 string = self[i][0] #vertical positioning will work fine only with one height for all entries x0 = W / 2 - self.font_aa.getSize(string)[0] * self.entryFontScale / 2 y0 = menuY - pos * self.font_aa.getSize(string)[1] * self.entryFontScale #+ self.entryLineSpacing x1 = x0 + self.font_aa.getSize(string)[0] * self.entryFontScale y1 = y0 + self.entryLineSpacing - self.font_aa.getSize(string)[1] * self.entryFontScale if vectormath.isPointInSquare((self.cursorPos[0], 0, self.cursorPos[1]), (x0, y1), (x1, y0)): self[i][1] = True if glfwGetMouseButton(GLFW_MOUSE_BUTTON_1) == GLFW_PRESS\ and glfwGetMouseButton(GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE: sounds.playSound("Menu", (0,0,0)) selection = self[i][0] gameglobals.gameState = self[i][2] self.setSelectionIndex(selection, entryIndex)
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
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
def applyInputs(self, entryIndex): W, H = glfwGetWindowSize() mx, my = glfwGetMousePos() my = -my if (mx, my + H) != self.cursorPos: if mx <= 0: mx = 0 if mx >= W: mx = W if my >= 0: my = 0 if my <= -H: my = -H self.cursorPos = (mx, my + H) glfwSetMousePos(mx, -my) #if mousebutton1 is pressed, enter selected menu W, H = glfwGetWindowSize() menuY = H / 2 + 50 * self.entryFontScale for i in range(len(self)): pos = i + 1 string = self[i][0] #vertical positioning will work fine only with one height for all entries x0 = W / 2 - self.font_aa.getSize( string)[0] * self.entryFontScale / 2 y0 = menuY - pos * self.font_aa.getSize( string)[1] * self.entryFontScale #+ self.entryLineSpacing x1 = x0 + self.font_aa.getSize(string)[0] * self.entryFontScale y1 = y0 + self.entryLineSpacing - self.font_aa.getSize( string)[1] * self.entryFontScale if vectormath.isPointInSquare( (self.cursorPos[0], 0, self.cursorPos[1]), (x0, y1), (x1, y0)): self[i][1] = True if glfwGetMouseButton(GLFW_MOUSE_BUTTON_1) == GLFW_PRESS\ and glfwGetMouseButton(GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE: sounds.playSound("Menu", (0, 0, 0)) selection = self[i][0] gameglobals.gameState = self[i][2] self.setSelectionIndex(selection, entryIndex)
def near_callback(args, geom1, geom2): """Callback function for the collide() method. This function checks if the given geoms do collide and creates contact joints if they do. """ # Check if the objects do collide friction = 100.0 bounce = 0.7 contacts = ode.collide(geom1, geom2) geoms = [geom1, geom2] geomNames = [g.name for g in geoms] if len(contacts) > 0: world, contactgroup = args #coach must track ball and register events if 'Ball' in geomNames: ball = [g for g in geoms if g.name == 'Ball'][0] for g in geoms: if g.name != 'Ball' and g.name != 'Bound': world.coach.objectList.append(g) elif g.name == 'Bound': sounds.playSound("BallGround", ball.getPosition()) friction = 600.0 if 'Player' in geom1.name and 'Player' in geom2.name: sounds.playSound("Player", geom1.getPosition()) # Create contact joints if 'Trigger' not in geomNames: for c in contacts: c.setBounce(bounce) c.setMu(friction) j = ode.ContactJoint(world, contactgroup, c) j.attach(geom1.getBody(), geom2.getBody()) break
def setGameOver(self): sounds.playSound("GameOver", (0,0,0)) self.gameOver = True
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
def setGameOver(self): sounds.playSound("GameOver", (0, 0, 0)) self.gameOver = True
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