コード例 #1
0
 def draw(self):
     #TODO Check who I belong to
     #check who player is
     #check if close to sentry
     #draw
     flag = False
     network = PEG_mainLoop.mainLoop().entityDict['Network']
     #OR nearby a sentry
     #if network.server or pedo_lookup.teamMap[network.color] == self.team:
     if True:
         flag = True
     if flag:
         if self.sides > 1:
             pygame.draw.polygon(
                                 PEG_mainLoop.mainLoop().screen,
                                 self.color,
                                 PEG_draw.getNgon(
                                                  self.sides, 
                                                  BUILDING_DRAW_RADIUS, 
                                                  PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition())),
                                 1
                                 )
         else:
             pygame.draw.circle(
                            PEG_mainLoop.mainLoop().screen,
                            self.color,
                            PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                            5,
                            1
                            )
コード例 #2
0
 def draw(self):
     PEG_speech.Speech().setSize(30, pedo_lookup.fontList[0])
     PEG_speech.Speech().writeCentered(
                                       PEG_mainLoop.mainLoop().screen,
                                       Vector2d(250,150),
                                       "TEAM A",
                                       pedo_lookup.colorMap["A"],
                                       )
     PEG_speech.Speech().setSize(30, pedo_lookup.fontList[0])
     PEG_speech.Speech().writeCentered(
                                       PEG_mainLoop.mainLoop().screen,
                                       Vector2d(525,150),
                                       "TEAM B",
                                       pedo_lookup.colorMap["B"],
                                       )
     PEG_speech.Speech().setSize(45, pedo_lookup.fontList[0])
     PEG_speech.Speech().writeCentered(
                                       PEG_mainLoop.mainLoop().screen,
                                       Vector2d(387,80),
                                       "SELECT YOUR COLOR",
                                       FL_SELECT_YOUR_COLOR_COLOR,
                                       )
     for b in self.buttonList:
         b.drawAbs()
     pass
コード例 #3
0
 def draw(self):
     if self.dir == "left":
         self.activeSurface = self.flipSurface
     else:
         self.activeSurface = self.mainSurface
                 
     frameNum = (PEG_helpers.truncateToMultiple(pygame.time.get_ticks(),self.frames[self.state][1])/self.frames[self.state][1])%len(self.frames[self.state][0])
     PEG_mainLoop.mainLoop().cam.drawOnScreen(self.activeSurface, self.pos-self.drawOffset, pygame.Rect(self.frames[self.state][0][frameNum].x, self.frames[self.state][0][frameNum].y,40,80))
コード例 #4
0
 def drawSelfLines(self):
     
     pygame.draw.lines(
                       PEG_mainLoop.mainLoop().screen,
                       self.color,
                       False,
                       convertToTupleList(map(PEG_mainLoop.mainLoop().cam.convertCrds,self.lastPos))                   
                      )
コード例 #5
0
ファイル: PEG_entity.py プロジェクト: chippermonky/mwgame3
 def editMode(self):
     self.setMouse()
     for e in PEG_mainLoop.mainLoop().eventList:
         if e.type == pygame.KEYDOWN:
             if e.key == pygame.K_SPACE:
                 self.toggleMode()
         if e.type == pygame.MOUSEBUTTONUP:
             for e in PEG_mainLoop.mainLoop().entityList:
                 if self.cursor == e.pos.getPosition():
                     self.activeObject = e
                     PEG_mainLoop.mainLoop().deleteEntity(e)
                     self.toggleMode()
コード例 #6
0
 def attackedBy(self,shape = None):
     if self.sides == 3:
         self.state = "destroy"
         #TODO some sort of explosion effect here maybe?
         PEG_mainLoop.mainLoop().entityDict['Network']
         network.mgr.send([data,])
         args = [3, self.pos.getPosition(), pedo_lookup.colorMap[self.team], ACTION_RADIUS]
         #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
         data = PEG_effects.quickData(*args)
         network.mgr.send([data,])
     else:
         self.sides -= 1
コード例 #7
0
    def update(self):
        #grab input
        mousePos = pygame.mouse.get_pos()
        for e in PEG_mainLoop.mainLoop().eventList:
            if e.type == pygame.MOUSEBUTTONUP:
                if PEG_helpers.livesIn(mousePos,Rect2d(self.pos.x+20,80,120,120)):
                    network = PEG_mainLoop.mainLoop().entityDict['Network']
#===============================================================================
#                    #TODO figure out why I have this here???
#                    for s in network.enDict.keys():
#                        network.destroyList.append(s)
#                    self.scan = not self.scan
#                    print "scan mode: ", self.scan
#===============================================================================
#===============================================================================
#                    PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(3, Vector2d(300,200), COLOR_CHARTREUSE, 150))
#                    PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(2, Vector2d(300,200), (255,255,255), 300))
#                    PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(6, Vector2d(300,200), (255,255,255), 300))
#                    PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(4))
#===============================================================================
#===============================================================================
#                if PEG_helpers.livesIn(mousePos,Rect2d(self.pos.x+20,200,120,120)):
#                    print "box2"
#                if PEG_helpers.livesIn(mousePos,Rect2d(self.pos.x+20,340,120,120)):
#                    print "box3"
#===============================================================================

        if PEG_mainLoop.mainLoop().entityDict['Network'].server:
            mousePos = pygame.mouse.get_pos()
            for e in PEG_mainLoop.mainLoop().eventList:
                if e.type == pygame.MOUSEBUTTONUP:
                    data = dict()
                    data['type'] = "position"
                    data['entity'] = "PowerSourceEn"
                    data['x'] = mousePos[0]
                    data['y'] = mousePos[1]
                    data['name'] = "ThePSource" 
                    data['team'] = "neutral"
                    data['sides'] = "123"
                    network = PEG_mainLoop.mainLoop().entityDict['Network']
                    network.processNetMessage(data)
                    if network.state == "waiting":
                        network.changeState("starting")
                    
                    
            self.selectMode = False
            
        if self.selectMode:
            self.select.update()
            if self.select.destroy:
                self.selectMode = False
                del self.select
コード例 #8
0
ファイル: PEG_entity.py プロジェクト: chippermonky/mwgame3
 def addMode(self):
     self.setMouse()
     for e in PEG_mainLoop.mainLoop().eventList:
         if e.type == pygame.KEYDOWN:
             if e.key == pygame.K_PAGEUP:
                 self.setActive(1)
             if e.key == pygame.K_PAGEDOWN:
                 self.setActive(-1)
             if e.key == pygame.K_SPACE:
                 self.toggleMode()
         if e.type == pygame.MOUSEBUTTONUP:
             PEG_mainLoop.mainLoop().entityList.append(self.activeObject)
             self.activeObject = pedo_lookup.enTables(self.entityList[self.currentItem].cloneNode(True))
コード例 #9
0
 def processNetMessage(self, data):
     if data['type'] == "position":
         self.parseEnData(data)          #has server specific routine inside
     if data['type'] == "time":
         self.gameTime = data['time'][1:len(data['time'])]   #time data is buffered with a character so we can start it with a 0
     if not self.server and data['type'] == "effect":        #client specific
         #should have position, id, etc 
         PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(
                                                                                            int(data['id']), 
                                                                                            Vector2d(int(data['x']),int(data['y'])),
                                                                                            (int(data['r']),int(data['g']),int(data['b'])), 
                                                                                            int(data['radius']),
                                                                                            int(data['sides'])
                                                                                            ))
     if not self.server and data['type'] == "state":        #client specific
         menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
         if data['state'] == "gameover":
             menu.gameover = True
             menu.winner = data['winner']
             menu.Ascore = data['Ateam']
             menu.Bscore = data['Bteam']
         elif data['state'] == "starting":
             menu.gameover = False
             
     if self.server and 'relay' in data:                     #server specific
             del data['relay']
             self.mgr.send(self.makeDefaultMessage(data))
             #print "relayed", data
     
     if self.server and data['type'] == "event":             #server specific
         if data['event'] == "arduino":
             if 'ThePSource' in self.enDict:
                 self.processArduinoEvent(data)
         
     #FIXK THIS
     if self.server and data['type'] == "init":              #server specific
         try: 
             m[1].name = data['name']
             print data['name'], " client is set"
         except: pass
         
         #now we check if all clients have been identified
         #this is kind of bad because we don't wait for extra clients to join, too bad
         #add maybe a 10 second grace period
         flag = True
         self.mgr.clntListlock.acquire()
         for e in self.mgr.clntList:
             if e.name == None:
                 flag = False
                 break
         self.mgr.clntListlock.release()
コード例 #10
0
    def detectCircling(self):
        #outer radius
        for e in self.enDict.itervalues():
            for f in self.enDict.itervalues():
                if e != f:
                    if f.name not in e.playerAngleDict:
                        e.playerAngleDict[f.name] = []
                        for i in range(PLAYER_ANGLE_QUEUE_LEN):
                            e.playerAngleDict[f.name].append(0)
                    if e.pos.getPosition().distance(f.pos) < OUTER_RADIUS:                   
                        angle = getAngle3pt(e.lastPos[len(e.lastPos)-2], f.lastPos[len(f.lastPos)-2], e.lastPos[len(e.lastPos)-1])
                        e.playerAngleDict[f.name].append(angle)
                        e.playerAngleDict[f.name].pop(0)
                        pygame.draw.lines(PEG_mainLoop.mainLoop().screen,(0,0,0),False,(e.pos.getPosition().getIntTuple(), f.pos.getPosition().getIntTuple()))
                    else:
                        #we gain no angles when outside OUTER RADIUS so pop last and push a 0
                        e.playerAngleDict[f.name].append(0)
                        e.playerAngleDict[f.name].pop(0)
                        pass
                    try: 
                        #we try as f may not have e set up in his playerAngleDict yet
                        if math.fabs(reduce(add, e.playerAngleDict[f.name])) - math.fabs(reduce(add, f.playerAngleDict[e.name])) > ENCIRCLE_RADIANS:
                            print e.name, " has lapped", f.name
                            f.state = "destroy"
                            f.data["state"] = "destroy"
#===============================================================================
#                            PEG_helpers.quickFcnCaller().callOnce(
#                                                                  23042729749234,
#                                                                  PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect,
#                                                                  [PEG_effects.quickEffect(3, f.pos.getPosition(), (255,255,255), 300),]
#                                                                  )
#===============================================================================
                    except: pass
コード例 #11
0
ファイル: PEG_entity.py プロジェクト: chippermonky/mwgame3
 def setMouse(self):
     self.screenCrds = Vector2d(pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
     self.cursor = PEG_mainLoop.mainLoop().cam.convertCrds(self.screenCrds)
     self.cursor.x = PEG_helpers.truncateToMultiple(self.cursor.x, TILING_SIZE.x)
     self.cursor.y = PEG_helpers.truncateToMultiple(self.cursor.y, TILING_SIZE.y)
     if self.activeObject:
         self.activeObject.teleport(self.cursor)
コード例 #12
0
 def changeState(self,state):
     self.state = state
     self.stateStartTime = pygame.time.get_ticks()
     
     data = dict()
     if state == "starting":
         data['type'] = "state"
         data['state'] = "starting"
     elif state == "end":
         #determine the winner
         #adding sides
         def isTeamA(en): return en.getTeam == "A"
         def isTeamB(en): return en.getTeam == "B"
         sumA = sumB = 0
         for e in self.enDict.values():
             if e.team == "A":
                 sumA += e.sides
             elif e.team == "B":
                 sumB += e.sides           
         winner = "A"
         if sumB > sumA: winner = "B"
         if sumB == sumA: winner = "TIE"
         data['type'] = "state"
         data['state'] = "gameover"
         data['winner'] = winner
         data['Ateam'] = sumA
         data['Bteam'] = sumB
     if len(data) > 0:
         network = PEG_mainLoop.mainLoop().entityDict['Network']
         network.mgr.send( network.makeDefaultMessage(data))
         
     print "game state changed to: ", state
コード例 #13
0
 def destroySelf(self):
     self.state = "dead"
     self.sides = 0
     self.resources = 0
     args = [3, self.pos.getPosition(), COLOR_CHARTREUSE, 150]
     #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
     network = PEG_mainLoop.mainLoop().entityDict['Network']
     network.mgr.send([PEG_effects.quickData(*args),])
コード例 #14
0
 def updatePos(self):
     try:
         self.pos = Rect2d(int(self.data['x']),int(self.data['y']),0,0)
     except: pass #keep position unchanged
     
     if 'sides' in self.data: self.sides = self.data['sides']
     if not PEG_mainLoop.mainLoop().entityDict['Network'].server:
         if 'resources' in self.data: 
             self.resources = self.data['resources']
コード例 #15
0
 def update(self):
     mousePos = pygame.mouse.get_pos()
     for e in PEG_mainLoop.mainLoop().eventList:
         if e.type == pygame.MOUSEBUTTONUP:
             for b in self.buttonList:
                 if b.isPointInside(mousePos):
                     PEG_mainLoop.mainLoop().entityDict['Network'].color = b.text
                     print "you have chosen to be ", b.text
                     #send message to server
                     data = dict()
                     data['type'] = 'init'
                     data['name'] = b.text
                     network = PEG_mainLoop.mainLoop().entityDict['Network']
                     network.mgr.send( [data,])
                     data['type'] = 'position'
                     data['entity'] = 'ShapeEn'
                     data['x'] = 500
                     data['y'] = 200
                     network.mgr.send( [data,] )
                     self.destroy = True
コード例 #16
0
 def processInput(self):
     #determines which object has been selected. Not really important for server
     mousePos = pygame.mouse.get_pos()
     for e in PEG_mainLoop.mainLoop().eventList:
         if e.type == pygame.MOUSEBUTTONUP:
             for e in self.enDict.values():
                 if e.visible and e.pos.getPosition().distance(Vector2d(mousePos[0],mousePos[1])) < PLAYER_DRAW_RADIUS:
                     self.selection = e
                     print "you have selected: ", e.name
                     break
                 else: self.selection = None
コード例 #17
0
ファイル: PEG_entity.py プロジェクト: chippermonky/mwgame3
    def update(self):
#===============================================================================
#        for e in PEG_mainLoop.mainLoop().eventList:
#            if e.type == pygame.KEYDOWN:
#                if e.key == pygame.K_LEFT:
#                    PEG_mainLoop.mainLoop().cam.moveToRel(Vector2d(-50,0))
#                if e.key == pygame.K_RIGHT:
#                    PEG_mainLoop.mainLoop().cam.moveToRel(Vector2d(50,0))
#                if e.key == pygame.K_UP:
#                    PEG_mainLoop.mainLoop().cam.moveToRel(Vector2d(0,-50))
#                if e.key == pygame.K_DOWN:
#                    PEG_mainLoop.mainLoop().cam.moveToRel(Vector2d(0,50))
#===============================================================================
        if self.mode == "place":
            self.addMode()
        else:
            self.editMode()
            
        #not very efficienty to be looping through this again but who cares
        for e in PEG_mainLoop.mainLoop().eventList:
            if e.type == pygame.KEYDOWN and e.key == pygame.K_RETURN:
                PEG_mainLoop.mainLoop().saveState(99)
コード例 #18
0
    def processNetMessage(self, data):
        if data["type"] == "position":
            # We only update entities after one has been idnetififed
            if self.server or self.color:
                self.parseEnData(data)  # has server specific routine inside
        if data["type"] == "time":
            self.gameTime = data["time"]
        if not self.server and data["type"] == "effect":  # client specific
            # should have position, id, etc
            print "got effect from serva", data
            PEG_mainLoop.mainLoop().entityDict["EffectMenu"].addEffect(
                PEG_effects.quickEffect(
                    int(data["id"]),
                    Vector2d(int(data["x"]), int(data["y"])),
                    (int(data["r"]), int(data["g"]), int(data["b"])),
                    int(data["radius"]),
                    int(data["sides"]),
                )
            )
        if not self.server and data["type"] == "state":  # client specific
            menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
            if data["state"] == "gameover":
                menu.gameover = True
                menu.winner = data["winner"]
                menu.Ascore = data["Ateam"]
                menu.Bscore = data["Bteam"]
            elif data["state"] == "starting":
                menu.gameover = False

        if self.server and "relay" in data:  # server specific
            del data["relay"]
            self.send(self.makeDefaultMessage(data))
            # print "relayed", data

        if self.server and data["type"] == "event":  # server specific
            if data["event"] == "arduino":
                if "ThePSource" in self.enDict:
                    self.processArduinoEvent(data)
コード例 #19
0
def quickEffect(id, pos = Vector2d(0,0),color = (255,255,255), radius = 300, sides = 3):
    if id == 1:
        return EffectNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,2000,radius,color,pointFunctionSquigglyPoly)
    if id == 2:
        return EffectThickExpandingGonNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,1000,radius,color,7,pointFunctionSquigglyPoly)
    if id == 3:
        return EffectAsteroidExplosion(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,3000,radius,color,3,pointFunctionSquigglyPoly)
    if id == 4:
        return EffectGameOver(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], expiration = 5000)
    if id == 5:
        return EffectImplodingNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,2000,radius,color,pointFunctionExpandingGonNova)
    if id == 6:
        return EffectImplodingNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,500,radius,color,pointFunctionSquigglyPoly)
    if id == 7:
        return EffectAsteroidExplosion(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,3000,radius,color,1,pointFunctionSquigglyPoly)
    if id == 8:
        return EffectImplodingNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,2000,radius,color,pointFunctionExpandingGonNovaX(3))
    if id == 9:     #X sides imploding polygon for leveling up players
        return EffectImplodingNova(PEG_mainLoop.mainLoop().entityDict['EffectMenu'], pos,2000,radius,color,pointFunctionExpandingGonNovaX(sides))
コード例 #20
0
 def updatePos(self):
     if not self.controlled:
         try:
             #TODO we should get rid of this list of data. slows things down a lot ya.
             self.pos = Rect2d(int(self.data['x']),int(self.data['y']),0,0)
             self.lastPos.pop(0)
             self.lastPos.append(Vector2d(int(self.data['x']),int(self.data['y'])))
         except: pass #keep position unchanged
     
     #server dictates sides and resources
     if not PEG_mainLoop.mainLoop().entityDict['Network'].server:
         if 'sides' in self.data: self.sides = self.data['sides']
         if 'resources' in self.data: self.resources = self.data['resources']
         if 'state' in self.data: self.state = self.data['state']
コード例 #21
0
ファイル: pedo_player.py プロジェクト: chippermonky/mwgame3
 def update(self):
     #handle the input
     for e in PEG_mainLoop.mainLoop().eventList:
         if e.type == pygame.KEYDOWN or e.type == pygame.KEYUP:
             self.handleInput(e)
     
     if self.grounded:
         self.vel.y = 0
     #gravity
     self.vel -= GRAVITY
     
     #move the character
     self.pos.x += self.vel.x
     self.pos.y += self.vel.y
コード例 #22
0
 def drawAnglePie(self,target):
     """draws pie chart representing angle gain as calculated by Network
     
     target: ShapeEn"""
     try: angle = -(math.fabs(reduce(add, self.playerAngleDict[target.name])) - math.fabs(reduce(add, target.playerAngleDict[self.name])))
     except: return #exception happens when player trys to graph him or herself
     
     radius = 100
     location = pygame.Rect(0,0,radius,radius)
     sfc = pygame.Surface((radius+5,radius+5),pygame.SRCALPHA)
     sfc.fill((0,0,0))
     
     pygame.draw.circle(sfc,(255,255,255),location.center,radius,1)
     pygame.draw.line(sfc,COLOR_CHARTREUSE,location.center, 
                      (getVector2dFromTuple(location.center)+getVector2dFromPolar(radius - 4,-ENCIRCLE_RADIANS+math.pi/2)).getIntTuple()
                      )
     pygame.draw.line(sfc,COLOR_RED,location.center, 
                      (getVector2dFromTuple(location.center)+getVector2dFromPolar(radius - 4,ENCIRCLE_RADIANS+math.pi/2)).getIntTuple()
                      )
     
     #TODO: maybe flash the arc as it gets closer
     if angle < 0: 
         clr = COLOR_CHARTREUSE
         pygame.draw.arc(sfc,clr,location,angle+math.pi/2,0+math.pi/2,1)
     else:
         clr = COLOR_RED
         pygame.draw.arc(sfc,clr,location,0+math.pi/2,angle+math.pi/2,1)
         
     pygame.draw.line(sfc,clr,location.center, 
                      (getVector2dFromTuple(location.center)+getVector2dFromPolar( -radius + 4,0+math.pi/2)).getIntTuple()
                      )
     pygame.draw.line(sfc,clr,location.center, 
                      (getVector2dFromTuple(location.center)+getVector2dFromPolar( -radius + 4,-angle+math.pi/2)).getIntTuple()
                      )
     #TODO blit with transparency
     PEG_mainLoop.mainLoop().screen.blit(sfc,(650,200))
コード例 #23
0
 def processNetMessage(self, data):
     if data['type'] == "position":
         #We only update entities after one has been idnetififed
         if self.server or self.color:
             self.parseEnData(data)          #has server specific routine inside
     if data['type'] == "time":
         self.gameTime = data['time']
     if not self.server and data['type'] == "effect":        #client specific
         #should have position, id, etc 
         print "got effect from serva", data
         PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(
                                                                                            int(data['id']), 
                                                                                            Vector2d(int(data['x']),int(data['y'])),
                                                                                            (int(data['r']),int(data['g']),int(data['b'])), 
                                                                                            int(data['radius']),
                                                                                            int(data['sides'])
                                                                                            ))
     if not self.server and data['type'] == "state":        #client specific
         menu = PEG_mainLoop.mainLoop().entityDict["MenuEn"]
         if data['state'] == "gameover":
             menu.gameover = True
             menu.winner = data['winner']
             menu.Ascore = data['Ateam']
             menu.Bscore = data['Bteam']
         elif data['state'] == "starting":
             menu.gameover = False
             
     if self.server and 'relay' in data:                     #server specific
             del data['relay']
             self.send(self.makeDefaultMessage(data))
             #print "relayed", data
     
     if self.server and data['type'] == "event":             #server specific
         if data['event'] == "arduino":
             if 'ThePSource' in self.enDict:
                 self.processArduinoEvent(data)
コード例 #24
0
 def drawConnectingLines(self,target):
     """draws lines representing angle gain between self and target
     
     target: ShapeEn"""
     skip = 5
     for i in range(PLAYER_ANGLE_QUEUE_LEN/skip - skip):
         at = i*skip
         pygame.draw.lines(
                       PEG_mainLoop.mainLoop().screen,
                       self.color,
                       False,
                       (self.lastPos[at].getIntTuple(), 
                        target.lastPos[at].getIntTuple(),
                        target.lastPos[at+skip].getIntTuple(),
                        self.lastPos[at+skip].getIntTuple())                   
                      )
コード例 #25
0
 def sendData(self):
     #for each players
     #calculate game time based on ticks
     #send game time
     #we send gametime to everybody
     data = dict()
     data['type'] = 'time'
     data['time'] = 'a' + str(self.gameTime)     #we buffer the time with a character so we can start it with a 0
     network = PEG_mainLoop.mainLoop().entityDict['Network']
     network.mgr.send( network.makeDefaultMessage(data) )
     
     #send the object to everybody
     #TODO selective sending with player knowledge dict... for future version
     for e in self.enDict.values():
         if hasattr(e, 'updateData'):
             e.updateData()
         network.mgr.send( network.makeDefaultMessage(e.data) )
コード例 #26
0
 def update(self):   
     #for manual input version of game
     if self.controlled:
         #grab input
         mousePos = getVector2dFromTuple(pygame.mouse.get_pos())
         #advance current position
         newPos = self.pos.getPosition()
         if (newPos-mousePos).magnitude() > 6: 
             newPos += (mousePos - newPos).getNormal()*5 
         
         #update our own position because there is too much network lag :(
         self.pos.x = newPos.x
         self.pos.y = newPos.y
         
         data = dict()
         data['x'] = int(newPos.x)
         data['y'] = int(newPos.y)
         data['name'] = self.name
         data['type'] = 'position'
         data['entity'] = 'ShapeEn'
         network = PEG_mainLoop.mainLoop().entityDict['Network']
         network.mgr.send( [data,])
コード例 #27
0
 def serialRoutineOLD(self):
     serial = PEG_mainLoop.mainLoop().entityDict["SerialEntity"]
     action = serial.getActionString()
     if action == "starting sweep":
         print "sweep started"
         self.currentAction = action
         self.actionStart = pygame.time.get_ticks()
     elif action == "triggered sweep":
         print "sweep triggered"
         self.currentAction = ''
         network = PEG_mainLoop.mainLoop().entityDict['Network']
         data = dict()
         data['type'] = 'event'
         data['event'] = 'arduino'
         data['name'] = self.color
         data['arduino'] = action
         network.mgr.send([data,])
         args = [5, self.pos.getPosition(), self.color, ACTION_RADIUS]
         #PEG_mainLoop.mainLoop().entityDict['EffectMenu'].addEffect(PEG_effects.quickEffect(*args))
         data = PEG_effects.quickData(*args)
         data['relay'] = 'True'
         network.mgr.send([data,])
         
         
     if self.currentAction == "starting sweep":
         timeSinceLastAction = pygame.time.get_ticks() - self.actionStart
         pygame.draw.circle(
                            PEG_mainLoop.mainLoop().screen,
                            COLOR_GRAY,
                            PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                            ACTION_RADIUS*timeSinceLastAction/ACTION_TIME + 1,
                            1
                            )
         pygame.draw.circle(
                            PEG_mainLoop.mainLoop().screen,
                            self.color,
                            PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                            ACTION_RADIUS,
                            1
                            )
コード例 #28
0
 def serialRoutine(self):
     serial = PEG_mainLoop.mainLoop().entityDict["SerialEntity"]
     action = serial.getAction()
     if( action != ''):
         if self.currentAction != action:
             self.actionStart = pygame.time.get_ticks()
             self.currentAction = action
             
         self.timeSinceLastAction = pygame.time.get_ticks() - self.actionStart
         if self.timeSinceLastAction < ACTION_TIME:
             pygame.draw.circle(
                                PEG_mainLoop.mainLoop().screen,
                                COLOR_GRAY,
                                PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                                ACTION_RADIUS*float(self.timeSinceLastAction)/float(ACTION_TIME) + 1,
                                1
                                )
             pygame.draw.circle(
                                PEG_mainLoop.mainLoop().screen,
                                self.color,
                                PEG_mainLoop.mainLoop().cam.convertCrds(self.pos.getPosition()).getIntTuple(),
                                ACTION_RADIUS,
                                1
                                )
         else:
             self.currentAction = ''
             #TODO
             #send net message
             network = PEG_mainLoop.mainLoop().entityDict['Network']
             data = dict()
             data['type'] = 'event'
             data['event'] = 'arduino'
             data['name'] = self.name
             data['arduino'] = action
             network.mgr.send([data,])
     else:
         #or for the type of action where radius is determined by time, check for this and send a message
         self.currentAction = ''
コード例 #29
0
ファイル: PEG_camera.py プロジェクト: chippermonky/mwgame3
 def drawOnScreen(self, sfc, pos, area = None):
     """draws onto self.screen at camera coordinates pos
     
     sfc: pygame.Surface
     pos: PEG_datatypes.Vector2d"""
     PEG_mainLoop.mainLoop().screen.blit(sfc, (pos+self.pos).getSDLRect(), area)
コード例 #30
0
 def drawAbs(self):
     pygame.draw.rect(PEG_mainLoop.mainLoop().screen,self.borderColor,self.pos.getSDLRect(), 2)
     PEG_speech.Speech().setSize(30, pedo_lookup.fontList[0])
     PEG_speech.Speech().writeCentered(PEG_mainLoop.mainLoop().screen, self.pos.getCenter(),self.text, self.color)
     
     pass