def initialiseComponent(self): # listen to shutdown events ogl_display = OpenGLDisplay.getDisplayService()[0] self.link( (ogl_display, "signal"), (self, "control") ) # create board self.boardvis = CheckersBoard(position=(0,0,-15)).activate() self.interactor_comms = {} self.board = {} for i in range(8): self.board[i] = {} for j in range(8): self.board[i][j] = None # create black pieces self.blackPieces = [] self.blackInteractors = [] for i in range(8): for j in range(3): if (i+j) %2 == 0: x = float(i)-3.5 y = float(j)-3.5 piece = CheckersPiece(position=(x, y, -15), colour=(0.6,0,0)).activate() self.blackPieces.append(piece) interactor = CheckersInteractor(target=piece, colour='B').activate() self.blackInteractors.append(interactor) intcomms = self.addOutbox("interactor_comms") self.interactor_comms[id(interactor)] = intcomms self.link( (self, intcomms), (interactor, "inbox")) self.link( (interactor, "outbox"), (self, "inbox")) self.board[i][j] = 'B' # create white pieces self.whitePieces = [] self.whiteInteractors = [] for i in range(8): for j in range(5,8): if (i+j) %2 == 0: x = float(i)-3.5 y = float(j)-3.5 piece = CheckersPiece(position=(x, y, -15), colour=(0,0,0.6)).activate() self.whitePieces.append(piece) interactor = CheckersInteractor(target=piece, colour='B').activate() self.whiteInteractors.append(interactor) intcomms = self.addOutbox("interactor_comms") self.interactor_comms[id(interactor)] = intcomms self.link( (self, intcomms), (interactor, "inbox")) self.link( (interactor, "outbox"), (self, "inbox")) self.board[i][j] = 'W' return 1
def initUIComponents(self): # listen to shutdown events ogl_display = OpenGLDisplay().getDisplayService()[0] self.link((ogl_display, "signal"), (self, "control")) # init mover self.mover = WheelMover(radius=15, center=(0, 0, -25), steps=500, slots=40).activate() self.link((self, "mover_signal"), (self.mover, "notify")) self.link((self, "mover_switch"), (self.mover, "switch")) self.background = SkyGrassBackground(size=(5000, 5000, 0), position=(0, 0, -90)).activate() # create & link nav buttons self.up_button = ArrowButton(size=(1, 1, 0.3), position=(7, 5, -15), msg="UP").activate() self.down_button = ArrowButton(size=(1, 1, 0.3), position=(7, -5, -15), rotation=(0, 0, 180), msg="DOWN").activate() self.link((self.up_button, "outbox"), (self, "nav")) self.link((self.down_button, "outbox"), (self, "nav")) # init info display self.infoticker = Ticker(text_height=21, render_right=250, render_bottom=500, background_colour=(250, 250, 200), text_colour=(0, 0, 0), outline_colour=(255, 255, 255)).activate() self.tickerwrapper = PygameWrapper(wrap=self.infoticker, size=(2.4, 4.0, 0.3)).activate() self.hideinfo_button = Button(caption="Hide", fontsize=30).activate() infocontents = { self.tickerwrapper: { "position": (0, 0, 0) }, self.hideinfo_button: { "position": (0, -2.4, 0) }, } self.infocontainer = Container(contents=infocontents, position=(-10, 10, -16)).activate() infopath = LinearPath([(-10, 10, -16), (-3, 0, -8)], 100) self.infomover = PathMover(infopath, False).activate() self.link((self.infomover, "outbox"), (self.infocontainer, "position")) self.link((self, "infomover_commands"), (self.infomover, "inbox")) self.link((self, "torrent_info"), (self.infoticker, "inbox")) self.link((self.hideinfo_button, "outbox"), (self, "hide_info")) self.send("Stop", "infomover_commands")
self.send(infostring, "torrent_info") def hideInfo(self): self.send("Backward", "infomover_commands") self.send("Play", "infomover_commands") if __name__ == "__main__": from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.Util.Console import ConsoleReader from Kamaelia.UI.PygameDisplay import PygameDisplay from Kamaelia.Community.THF.Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay from Kamaelia.Community.RJL.Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient from Kamaelia.Community.RJL.Kamaelia.Protocol.Torrent.TorrentPatron import TorrentPatron ogl_display = OpenGLDisplay(limit_fps=100).activate() OpenGLDisplay.setDisplayService(ogl_display) # override pygame display service PygameDisplay.setDisplayService(ogl_display) Graphline(reader=ConsoleReader(prompt="Enter torrent location:", eol=""), httpclient=SimpleHTTPClient(), gui=TorrentOpenGLGUI(), backend=TorrentPatron(), linkages={ ("gui", "outbox"): ("backend", "inbox"), ("reader", "outbox"): ("gui", "torrent_url"), ("gui", "fetcher"): ("httpclient", "inbox"), ("httpclient", "outbox"): ("gui", "torrent_file"), ("backend", "outbox"): ("gui", "inbox") }).run()
if msg.get("PLACEMENT", None): objectid = msg.get("objectid") fr = msg.get("from") to = msg.get("to") colour = msg.get("colour") if (to[0]<0 or to[0]>7 or to[1]<0 or to[1]>7 or to[0] + to[1]) % 2 != 0 or self.board[to[0]][to[1]] is not None: self.send("INVALID", self.interactor_comms[objectid]) else: self.board[fr[0]][fr[1]] = None self.board[to[0]][to[1]] = colour self.send("ACK", self.interactor_comms[objectid]) while self.dataReady("control"): cmsg = self.recv("control") if isinstance(cmsg, Axon.Ipc.shutdownMicroprocess): # dirty way to terminate program sys.exit(0) return 1 if __name__=='__main__': # initialise display, change point of view ogl_display = OpenGLDisplay(viewerposition=(0,-10,0), lookat=(0,0,-15), limit_fps=100) ogl_display.activate() OpenGLDisplay.setDisplayService(ogl_display) Checkers().activate() Axon.Scheduler.scheduler.run.runThreads() # Licensed to the BBC under a Contributor Agreement: THF
def initialiseComponent(self): # listen to shutdown events ogl_display = OpenGLDisplay.getDisplayService()[0] self.link((ogl_display, "signal"), (self, "control")) # create board self.boardvis = CheckersBoard(position=(0, 0, -15)).activate() self.interactor_comms = {} self.board = {} for i in range(8): self.board[i] = {} for j in range(8): self.board[i][j] = None # create black pieces self.blackPieces = [] self.blackInteractors = [] for i in range(8): for j in range(3): if (i + j) % 2 == 0: x = float(i) - 3.5 y = float(j) - 3.5 piece = CheckersPiece(position=(x, y, -15), colour=(0.6, 0, 0)).activate() self.blackPieces.append(piece) interactor = CheckersInteractor(target=piece, colour='B').activate() self.blackInteractors.append(interactor) intcomms = self.addOutbox("interactor_comms") self.interactor_comms[id(interactor)] = intcomms self.link((self, intcomms), (interactor, "inbox")) self.link((interactor, "outbox"), (self, "inbox")) self.board[i][j] = 'B' # create white pieces self.whitePieces = [] self.whiteInteractors = [] for i in range(8): for j in range(5, 8): if (i + j) % 2 == 0: x = float(i) - 3.5 y = float(j) - 3.5 piece = CheckersPiece(position=(x, y, -15), colour=(0, 0, 0.6)).activate() self.whitePieces.append(piece) interactor = CheckersInteractor(target=piece, colour='B').activate() self.whiteInteractors.append(interactor) intcomms = self.addOutbox("interactor_comms") self.interactor_comms[id(interactor)] = intcomms self.link((self, intcomms), (interactor, "inbox")) self.link((interactor, "outbox"), (self, "inbox")) self.board[i][j] = 'W' return 1
if (to[0] < 0 or to[0] > 7 or to[1] < 0 or to[1] > 7 or to[0] + to[1]) % 2 != 0 or self.board[to[0]][ to[1]] is not None: self.send("INVALID", self.interactor_comms[objectid]) else: self.board[fr[0]][fr[1]] = None self.board[to[0]][to[1]] = colour self.send("ACK", self.interactor_comms[objectid]) while self.dataReady("control"): cmsg = self.recv("control") if isinstance(cmsg, Axon.Ipc.shutdownMicroprocess): # dirty way to terminate program sys.exit(0) return 1 if __name__ == '__main__': # initialise display, change point of view ogl_display = OpenGLDisplay(viewerposition=(0, -10, 0), lookat=(0, 0, -15), limit_fps=100) ogl_display.activate() OpenGLDisplay.setDisplayService(ogl_display) Checkers().activate() Axon.Scheduler.scheduler.run.runThreads() # Licensed to the BBC under a Contributor Agreement: THF
def hideInfo(self): self.send("Backward", "infomover_commands") self.send("Play", "infomover_commands") if __name__ == "__main__": from Kamaelia.Chassis.Graphline import Graphline from Kamaelia.Util.Console import ConsoleReader from Kamaelia.UI.PygameDisplay import PygameDisplay from Kamaelia.Community.THF.Kamaelia.UI.OpenGL.OpenGLDisplay import OpenGLDisplay from Kamaelia.Community.RJL.Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient from Kamaelia.Community.RJL.Kamaelia.Protocol.Torrent.TorrentPatron import TorrentPatron ogl_display = OpenGLDisplay(limit_fps=100).activate() OpenGLDisplay.setDisplayService(ogl_display) # override pygame display service PygameDisplay.setDisplayService(ogl_display) Graphline( reader = ConsoleReader(prompt="Enter torrent location:", eol=""), httpclient = SimpleHTTPClient(), gui = TorrentOpenGLGUI(), backend = TorrentPatron(), linkages = { ("gui", "outbox") : ("backend", "inbox"), ("reader", "outbox") : ("gui", "torrent_url"), ("gui", "fetcher") : ("httpclient", "inbox"), ("httpclient", "outbox") : ("gui", "torrent_file"), ("backend", "outbox"): ("gui", "inbox") }