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 main(): """Début du programme """ pygame.init() pygame.font.init() config = Config() display = Display(config) level = config.loading_stage("level.txt") hero = Hero(level) guardian = Guardian(level) needle = Items("needle", level) ether = Items("ether", level) tube = Items("tube", level) keys = Event() display.draw_window(config) while config.run: display.draw_labyrinth(level, config) keys.actions(level, hero) hero.pick(needle) hero.pick(ether) hero.pick(tube) hero.craft() display.draw_items(hero, display.hero, config) display.draw_items(guardian, display.guardian, config) display.draw_items(ether, display.ether, config) display.draw_items(needle, display.needle, config) display.draw_items(tube, display.tube, config) display.draw_inventory(hero, config) guardian.is_there_anyone_here(hero, config) pygame.display.update() display.draw_final(config)
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 transition(self, fenetre) : self.niveau += 1 tempsTransition = Temps() tempsTransition.startChrono() while tempsTransition.tempsEcoule() < 3 : Event.observateurQuit(fenetre) self.dt = self.clock.tick(self.fps) / 1000 texteTransition = None if self.niveau == 1 : fenetre.afficherFond(1) texteTransition = Texte("Terre",(100,100,255),int(fenetre.getTailleFenetreL()/(7-pow(tempsTransition.tempsEcoule(),1.7))),[int(fenetre.getTailleFenetreL()/2),int(fenetre.getTailleFenetreH()/2)]) elif self.niveau == 2 : fenetre.afficherFond(2) texteTransition = Texte("Vénus",(255,255,100),int(fenetre.getTailleFenetreL()/(7-pow(tempsTransition.tempsEcoule(),1.7))),[int(fenetre.getTailleFenetreL()/2),int(fenetre.getTailleFenetreH()/2)]) self.character.actualiserPerso(fenetre, self.dt) self.generateur.regulerObjet(fenetre) self.generateur.actualiserObjet(fenetre, self.dt) if texteTransition != None : texteTransition.centrerProsition() texteTransition.afficherTexte(fenetre) fenetre.actualiser() if self.niveau == 1 : self.niveau1(fenetre) elif self.niveau == 2 : self.niveau2(fenetre)
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 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 __init__(self, hauteurPersonnage, vitessePerso, fenetre): self.charac = pygame.image.load("personnage.png").convert_alpha() self.hauteurPerso = self.charac.get_height() self.largeurPerso = self.charac.get_width() self.charac = pygame.transform.smoothscale( self.charac, (hauteurPersonnage, int(hauteurPersonnage * self.hauteurPerso / self.largeurPerso))) self.hauteurPerso = self.charac.get_height() self.largeurPerso = self.charac.get_width() self.posPersoX = int(fenetre.getTailleFenetreL() / 2 - self.largeurPerso / 2) self.posPersoY = int(fenetre.getTailleFenetreH() - self.hauteurPerso) self.vitesse = vitessePerso self.touchesPresse = pygame.key.get_pressed() self.compteurFlamme = 3 self.flammes = [] self.flammes.append( pygame.image.load("Flammes v2\\flammes000.png").convert_alpha()) hauteurFlammes = self.flammes[0].get_height() largeurFlammes = self.flammes[0].get_width() hauteurTransformee = int(hauteurPersonnage * 2) largeurTransformee = int(hauteurTransformee * hauteurFlammes / largeurFlammes) self.flammes[0] = pygame.transform.smoothscale( self.flammes[0], (hauteurTransformee, largeurTransformee)) for i in range(135): Event.observateurQuit(fenetre) i += 1 if i < 10: self.flammes.append( pygame.image.load("Flammes v2\\flammes00" + str(i) + ".png").convert_alpha()) elif i < 100: self.flammes.append( pygame.image.load("Flammes v2\\flammes0" + str(i) + ".png").convert_alpha()) else: self.flammes.append( pygame.image.load("Flammes v2\\flammes" + str(i) + ".png").convert_alpha()) self.flammes[i] = pygame.transform.smoothscale( self.flammes[i], (hauteurTransformee, largeurTransformee)) self.afficherPerso(fenetre)
def niveau1(self, fenetre) : self.clock.tick(self.fps) repeat = True while repeat == True : self.dt = self.clock.tick(self.fps) / 1000 fenetre.afficherFond(1) self.character.actualiserPerso(fenetre, self.dt) if self.score.score() < 73 : self.generateur.genererObjet(fenetre) self.generateur.regulerObjet(fenetre) self.generateur.actualiserObjet(fenetre, self.dt) #Affichage Hitbox #self.generateur.afficherHitboxObjet(fenetre) #self.character.afficherHitbox(fenetre) ### pour les collisions, il faut que je modifie la fonction collision pour gerer la collision x sur y et y sur x (en gros supprimer if/elif ci dessous) # + Voir pour transferer la gestion des collisions dans le generateur : je pense que c'est mieux et plus simple for objets in self.generateur.getListObjet() : if Collision.collision(self.character.hitbox(), objets.hitbox()) : repeat = False pass elif Collision.collision(objets.hitbox(), self.character.hitbox()) : repeat = False pass # fenetre.actualiser() #A etudier pour modification (mettre ca dans une classe) if Event.evenementPause(fenetre) : self.score.stopTempsJeu() self.generateur.stopGeneration() pause = Texte("Pause",(100,200,200), int(fenetre.getTailleFenetreL()/7),(int(fenetre.getTailleFenetreL()/3.2),int(fenetre.getTailleFenetreH()/3.2))) pause.afficherTexte(fenetre) fenetre.actualiser() while not Event.evenementUnPause(fenetre) : pass self.score.reprendreTempsJeu() self.generateur.reprendreGeneration() self.dt = self.clock.tick(self.fps) / 1000 # if self.score.score() >= 77 : self.transition(fenetre) repeat = False
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 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 finJeu(self, fenetre) : scoreT = Texte("Score Joueur : " + str(int(self.score.score())),(255,100,100), int(fenetre.getTailleFenetreL()/25),(int(fenetre.getTailleFenetreL()/3),int(fenetre.getTailleFenetreH()/3))) scoreT.afficherTexte(fenetre) messageGO = Texte("Game Over",(100,100,255), int(fenetre.getTailleFenetreL()/25),(int(fenetre.getTailleFenetreL()/3),int(fenetre.getTailleFenetreH()/2))) messageGO.afficherTexte(fenetre) retour = Texte("Retour", (100,255,100), int(fenetre.getTailleFenetreL()/30), (int(fenetre.getTailleFenetreL()/1.15), int(fenetre.getTailleFenetreH()/1.1))) retour.afficherTexte(fenetre) fenetre.actualiser() repeat = True while repeat : hiboxSouris = Event.obsevateurEvenement(fenetre) if hiboxSouris[0] == True : if Collision.collision((hiboxSouris[1],hiboxSouris[2],hiboxSouris[3],hiboxSouris[4]), retour.hitbox()) : repeat = False if hiboxSouris[0] == False : if Collision.collision((hiboxSouris[1],hiboxSouris[2],hiboxSouris[3],hiboxSouris[4]), retour.hitbox()) : retour = Texte("Retour", (50,200,50), int(fenetre.getTailleFenetreL()/30), (int(fenetre.getTailleFenetreL()/1.15), int(fenetre.getTailleFenetreH()/1.1))) else : retour = Texte("Retour", (100,255,100), int(fenetre.getTailleFenetreL()/30), (int(fenetre.getTailleFenetreL()/1.15), int(fenetre.getTailleFenetreH()/1.1))) retour.afficherTexte(fenetre) fenetre.actualiser()
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 resume(self): print("unpausing selector") Event.Dispatcher().register(self, 'E_Mouse_1', self.select)
def pause(self): Event.Dispatcher().unregister(self, 'E_Mouse_1')
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 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 __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 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')
from game import Game, Event from events.system import * from events.act1 import * # instantiate game inst game = Game() # register events game.handle(Event("exit,quit", "global", event_exit, "strict")) game.handle(Event("help", "global", event_help, "strict")) game.handle(Event("save", "global", event_save)) game.handle(Event("load", "global", event_load)) game.handle(Event("delete", "global", event_delete)) game.handle(Event("stat", "global", event_stats, "strict")) game.handle(Event("play", "title", event_play, "strict")) game.handle(Event("lamp,light,switch", "start", event_start, "contains")) game.handle(Event("record", "dream-0-choice-0", event_wardrobe_choice_0, "contains")) game.handle(Event("lock", "dream-0-choice-0", event_wardrobe_choice_1, "contains")) game.handle(Event("dresser", "dream-0-choice-0", event_wardrobe_choice_2, "contains")) game.handle(Event("1,2,3,4", "wardrobe-shirts", event_wardrobe_choice_3, "strict")) printTitleScreen(game) # print starting title game.start()