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, 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, parent, size=1): LOG.debug("[SelectionIndicator] Initializing") self.aaLevel = int(GameSettings().antiAlias) self.size = size self._np = loader.loadModelCopy("data/models/ribbon.egg") self._np.setScale(10) self._np.setHpr(self._currHpr) self._np.setTwoSided(True) if self.aaLevel > 0: self._np.setAntialias(AntialiasAttrib.MLine, self.aaLevel) self._np.reparentTo(parent) taskMgr.add(self.rotate, 'Selection Rotation Task')
def __init__(self, parent, pos=Vec3(0, 0, 0), size=1, color=Vec4(0, 0, 0, 1)): print(" Creating circle at " + str(pos)) self.aaLevel = int(GameSettings().getSetting('ANTIALIAS')) self.pos = pos self.size = size self.color = color self._np = self.draw() self._np.setTwoSided(True) self._np.setTransparency(1) self._np.setAttrib(DepthTestAttrib.make(RenderAttrib.MNone)) self._np.setEffect(BillboardEffect.makePointEye()) if self.aaLevel > 0: self._np.setAntialias(AntialiasAttrib.MPolygon, self.aaLevel) self._np.reparentTo(parent)
class GameClient(DirectObject): """ GameClient GameClient creates the Dispatcher, ClientConnection, GSM and GUI. Then it sits back and chills. The GUI handles setting organizing the rest of the setup, the dispatcher handles all communication and the GSM handles the game. """ 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 startGame(self, event): """ TODO - Document """ mapMD5 = event.data LOG.debug("[GameClient] Starting game with map ID %s" % mapMD5) if not NOSERVER: self.gui.clear() del (self.menu) del (self.gui) # Create GSM self.gsm = GSMgr.GSMgr(self.clientconnection) # Setup controls self.keyboardcontroller = Controller.KeyboardController() self.mousecontroller = Controller.MouseController() # Create GXEng self.gxm = GXMgr.GXMgr() self.gxm.makeGameEngine() self.gsm.registerGXEng(self.gxm) LOG.debug("[GameClient] Loading map id %s" % mapMD5) map = self._mapStore.loadMap(self._mapStore.getMap(mapMD5)["filename"]) self.gsm.startGame(map) def exitGame(self, event): """ Clean up open/running game. Show mainmenu.""" LOG.debug("[GameClient] Exiting game") self.gui = Gui(Keys(), theme=RTheme()) self.menu = MainScreen(self) def exitProgram(self, event): """ TODO - Document """ LOG.debug("[GameClient] Exiting process") # do any necessary cleanup if self.clientconnection.isConnected(): self.clientconnection.disconnect(None) sys.exit(0)
class GameClient(DirectObject): ''' GameClient GameClient creates the Dispatcher, ClientConnection, GSM and GUI. Then it sits back and chills. The GUI handles setting organizing the rest of the setup, the dispatcher handles all communication and the GSM handles the game. ''' 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 startGame(self, event): ''' TODO - Document ''' mapMD5 = event.data LOG.debug("[GameClient] Starting game with map ID %s" % mapMD5) if not NOSERVER: self.gui.clear() del (self.menu) del (self.gui) # Create GSM self.gsm = GSMgr.GSMgr(self.clientconnection) # Setup controls self.keyboardcontroller = Controller.KeyboardController() self.mousecontroller = Controller.MouseController() # Create GXEng self.gxm = GXMgr.GXMgr() self.gxm.makeGameEngine() self.gsm.registerGXEng(self.gxm) LOG.debug("[GameClient] Loading map id %s" % mapMD5) map = self._mapStore.loadMap(self._mapStore.getMap(mapMD5)['filename']) self.gsm.startGame(map) def exitGame(self, event): ''' Clean up open/running game. Show mainmenu.''' LOG.debug("[GameClient] Exiting game") self.gui = Gui(Keys(), theme=RTheme()) self.menu = MainScreen(self) def exitProgram(self, event): ''' TODO - Document ''' LOG.debug("[GameClient] Exiting process") # do any necessary cleanup if self.clientconnection.isConnected(): self.clientconnection.disconnect(None) sys.exit(0)