def __init__(self, parent, entity, foot=1): self.entity = entity self._moveRadCircleNP = NodePath("Movement Radius Node") self._moveLine = LineSegs() self._moveLineNP = NodePath("Movement Direction Line Node") self._moveZLine = LineSegs() self._moveZLineNP = NodePath("Movement Z Line Node") self._moveZFootNP = NodePath("Movement Z Foot Node") self._moveFootCircle = LineSegs() self._moveFootCircleNP = NodePath("Movement Foot Circle Node") self._attackRadCircle = LineSegs() self._attackRadCircleNP = NodePath("Attack Radius Node") self._np = NodePath("Movement Node") self.attackables = [] Event.Dispatcher().register(self, 'E_Key_ZUp', self.onZChange) Event.Dispatcher().register(self, 'E_Key_ZDown', self.onZChange) Event.Dispatcher().register(self, 'E_Key_ZUp-up', self.onZChange) Event.Dispatcher().register(self, 'E_Key_ZDown-up', self.onZChange) self.aaLevel = int(GameSettings().getSetting('ANTIALIAS')) self.parent = parent self.start = Vec3(0, 0, 0) self.moveRad = entity.moveRad self.footRad = foot self.attackRad = entity.attackRad self.plane = Plane(Vec3(0, 0, 1), Point3(0, 0, 0)) self.draw() self._np.reparentTo(self.parent) if self.aaLevel > 0: self._np.setAntialias(AntialiasAttrib.MLine, self.aaLevel) taskMgr.add(self.updateMovePos, 'Movement Indicator Update Task')
def __init__(self): import __builtin__ __builtin__.LOG = LogConsole() print("Starting PSG Client ...") # Initialize event dispatcher self._dispatcher = Event.Dispatcher() self._dispatcher.register(self, 'E_StartGame', self.startGame) self._dispatcher.register(self, 'E_ExitGame', self.exitGame) self._dispatcher.register(self, 'E_ExitProgram', self.exitProgram) # Create server connection object self.clientconnection = ClientConnection() # Load settings self.gst = GameSettings() self.gst.loadSettings() self._mapStore = MapStore() # If AUTOSERVER is set automatically connect and start a game with the # local server #if (AUTOSERVER): # def connResp(status): # if status: # # Authenticate # self.clientconnection.authenticate('autoserver','password1', authResp) # else: # LOG.error("[GameClient] Could not autoconnect <%s>"%status) # def authResp(status): # if (status == 3): # self.clientconnection.newGame("debug game", mapDict['id'], "3", newResp) # else: # LOG.error("[GameClient] Could not autoauthenticate <%s>"%status) # def newResp(status): # if status > 0: # self.clientconnection.joinGame(status, joinResp) # else: # LOG.error("[GameClient] Could not automatically create a game <%s>"%status) # def joinResp(status, mapMD5): # if status == 2: # Event.Dispatcher().broadcast(Event.Event('E_StartGame', src=self, data=mapMD5)) # else: # LOG.error("[GameClient] Could not autojoin <%s>"%status) # # Use the debug map # mapDict = self._mapStore.getMap(name="Debugger Map") # # Connect # self.clientconnection.connect('localhost', 9091, 3000, connResp) if NOSERVER: mapDict = self._mapStore.getMap(name="Debugger Map") print(mapDict) Event.Dispatcher().broadcast( Event.Event('E_StartGame', src=self, data=mapDict['id'])) # Otherwise start menu GUI normally else: self.gui = Gui(Keys(), theme=RTheme()) self.menu = MainScreen(self)
def __init__(self): # Register events self.accept("mouse1", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_1', self)]) self.accept("mouse2", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_2', self)]) self.accept("mouse3", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_3', self)]) self.accept("mouse1-up", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_1_Up', self)]) self.accept("mouse2-up", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_2_Up', self)]) self.accept("mouse3-up", Event.Dispatcher().broadcast, [Event.Event('E_Mouse_3_Up', self)]) self.accept("wheel_up", Event.Dispatcher().broadcast, [Event.Event('E_MouseWheel_Up', self)]) self.accept("wheel_down", Event.Dispatcher().broadcast, [Event.Event('E_MouseWheel_Down', self)])
def onEntitySelect(self, event): LOG.debug("[GSMgr] Entity select") if self.s_WaitingForSelection: LOG.debug("[GSMgr] tag=%s"%event.data) self.selected = self._entmgr.getFromTag(event.data) LOG.debug("[GSMgr] Selected = %s"%self.selected) if self.selected.moved is not True: # Enter moving state LOG.debug("[GSMgr] State Transition <s_WaitingForSelection=>s_MoveCursor>") Event.Dispatcher().broadcast(Event.Event('E_UpdateGUI', src=self, data=self.selected)) self.s_WaitingForSelection = False self.selected.rep.selectMove() self.s_MoveCursor = True self.selector.pause() if self.s_AttackCursor: if self.selected.attacked is not True: # Exit attacking state (execute attack) LOG.debug("[GSMgr] State Transition <s_AttackCursor=>s_WaitingForSelection>") shipToAttack = self._entmgr.getFromTag(event.data) self.selected.rep.fireRockets(shipToAttack.pos) self.selected.rep.unselectAttack() # TODO - damage calc self.selected.attacked = True self.s_AttackCursor = False self.selected = None # Enter waitingforselection state self.s_WaitingForSelection = True
def __init__(self, clientconnection): ''' TODO - Document ''' LOG.debug("[GSMgr] Initializing") super(GSMgr, self).__init__() self._clientconnection = clientconnection self._entmgr = Entity.EntityManager() Event.Dispatcher().register(self, 'E_Key_Move', self.onMoveKey) Event.Dispatcher().register(self, 'E_Key_Exit', self.onExitKey) Event.Dispatcher().register(self, 'E_EntitySelect', self.onEntitySelect) #Event.Dispatcher().register(self, 'E_EntityUnSelect', self.onEntityUnSelect) Event.Dispatcher().register(self, 'E_Mouse_1', self.onMouse1) self.selector = Controller.Selector()
def onExitKey(self, event): # TODO - Handle this better. if self.s_MoveCursor: # Exit moving state self.selected.rep.unselectMove() self.selected = None self.s_MoveCursor = False self.s_WaitingForSelection = True self.selector.unpause() if self.s_AttackCursor: # Exit attacking state (do not execute) self.selected.rep.unselectAttack() else: Event.Dispatcher().broadcast(Event.Event('E_ExitProgram', src=self))
def select(self, event): LOG.debug("[Selector] Selecting ") if base.mouseWatcherNode.hasMouse(): mpos = base.mouseWatcherNode.getMouse() self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY()) self.cTrav.traverse(render) # TODO - change this to a lower node if self.cHandler.getNumEntries() > 0: #LOG.debug("[Selector] Entries=%d"%self.cHandler.getNumEntries()) self.cHandler.sortEntries() selectionNP = self.cHandler.getEntry(0).getIntoNodePath() selection = selectionNP.findNetTag('SelectorTag').getTag( 'SelectorTag') if selection is not '': LOG.debug("[Selector] Collision with %s" % selection) Event.Dispatcher().broadcast( Event.Event('E_EntitySelect', src=self, data=selection)) else: LOG.debug("[Selector] No collision")
def startCamera(self): LOG.debug("Starting CameraManager") # Register with Dispatcher Event.Dispatcher().register(self, 'E_Mouse_3', self.startDrag) Event.Dispatcher().register(self, 'E_Mouse_3_Up', self.stopDrag) Event.Dispatcher().register(self, 'E_MouseWheel_Up', self.adjustCamDist) Event.Dispatcher().register(self, 'E_MouseWheel_Down', self.adjustCamDist) Event.Dispatcher().register(self, 'E_Key_CameraUp', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraUp-up', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraDown', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraDown-up', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraLeft', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraLeft-up', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraRight', self.keyMove) Event.Dispatcher().register(self, 'E_Key_CameraRight-up', self.keyMove) # Turn off default camera movement base.disableMouse() # Set camera properties base.camLens.setFov(self.fov) base.camera.setPos(self.pos) # The lookAt camera method doesn't work right at the moment. # This should be moved into a seperate method of Camera Manager anyway # so we can set this to the players start pos. #base.camera.lookAt(self.lookAt) self.turnCameraAroundPoint(0, 0, self.target, self.camDist) taskMgr.add(self.dragTask, 'dragTask')
def start(self): ''' The logger needs the Dispatcher but is usually created before the Dispatcher so we need to break the register part of creation out.''' self.log("Starting log console") Event.Dispatcher().register(self, 'E_All', self.printEvents)
def startGame(self, mapMD5): ''' Clean up all the menus and then tell dispatcher to start the game''' self.background.destroy() Event.Dispatcher().broadcast( Event.Event('E_StartGame', src=self, data=mapMD5))
def exit(self): Event.Dispatcher().broadcast(Event.Event('E_ExitProgram', src=self))
def __init__(self): # Register events self.accept("escape", Event.Dispatcher().broadcast, [Event.Event('E_Key_Exit', self)]) self.accept("m", Event.Dispatcher().broadcast, [Event.Event('E_Key_Move', self)]) self.accept("arrow_up", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraUp', self)]) self.accept("arrow_down", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraDown', self)]) self.accept("arrow_left", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraLeft', self)]) self.accept("arrow_right", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraRight', self)]) self.accept("arrow_up-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraUp-up', self)]) self.accept("arrow_down-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraDown-up', self)]) self.accept("arrow_left-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraLeft-up', self)]) self.accept("arrow_right-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_CameraRight-up', self)]) self.accept("page_up", Event.Dispatcher().broadcast, [Event.Event('E_Key_ZUp', self)]) self.accept("page_down", Event.Dispatcher().broadcast, [Event.Event('E_Key_ZDown', self)]) self.accept("page_up-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_ZUp-up', self)]) self.accept("page_down-up", Event.Dispatcher().broadcast, [Event.Event('E_Key_ZDown-up', self)])
def resume(self): print("unpausing selector") Event.Dispatcher().register(self, 'E_Mouse_1', self.select)
def pause(self): Event.Dispatcher().unregister(self, 'E_Mouse_1')