class Game: def __init__(self): self.running = False self.event_dispatcher = EventDispatcher() self.graphics = gamegraphics.Graphics(self, self.event_dispatcher) self.map = gamemap.Map() self.player = player.Player(self, self.event_dispatcher) self.ai = ai.AI(self, self.event_dispatcher) def sigint_handler(sig, frame): self.event_dispatcher.add_event("quit", "Ctrl-C") signal.signal(signal.SIGINT, sigint_handler) self.event_dispatcher.register("quit", self.quit) def quit(self, cause=None): logger.info("Stopping game, cause: {}".format(cause)) self.running = False def get_move(self): move = input(">> ") self.event_dispatcher.add_event("movePlayer", move) def run(self): self.running = True self.graphics.setup_sprites() utility.repeat(self.event_dispatcher, "ai_update", 0.1, self.ai.update) while self.running: self.graphics.update() self.event_dispatcher.dispatch()
def __init__(self, parent, width, height): self.tag = 'draws' self.stats_tag = 'stats' self.path_tag = 'tool_path' self.grid_tag = 'grid' super().__init__( parent) #, width = self.canvas_width, height = self.canvas_height) self.parent = parent self.width = width self.height = height self.bot_width = width self.bot_height = height self.x_scale = 1.0 self.y_scale = 1.0 self._last_tool_p = Point(0.0, 0.0) self._enable_tool = False self.configure(width=self.width, height=self.height, background="white", borderwidth=0) # self.bind('<Button-1>', self.on_click) print(dispatcher) print(type(dispatcher)) dispatcher.add_event('on_click')
def __init__(self, id, spr, microsteps): #, on_step_func): # stepper self._steps_per_revolution = spr self._microsteps = microsteps self._effective_steps = spr * microsteps self._rads_per_step = (2 * pi) / self._effective_steps # callback self._id = id #self._on_step = on_step_func # internal self._steps_to_move = 0 self._dir_to_move = 0 dispatcher.add_event('step')
def __init__(self, parent, **kwargs): super().__init__( parent) #, width = self.canvas_width, height = self.canvas_height) self.parent = parent self._actions = {} self.tick_interval = kwargs.get('tick_interval', ControlPanel.TICK_INTERVAL) # self.width = width # self.height = height #self.configure(width = self.width, height = self.height) #self.pack() #ipadx = 10, ipady = 10) # self.script_running = False self.cmd_running = False self.program_line = 0 self.program_text_iter = None # create controls self.lb_x = TK.Label(self, text='GO TO X') self.lb_x.grid(row=0, column=0) self.ed_x = TK.Entry(self, width=5) self.ed_x.grid(row=0, column=1) self.lb_y = TK.Label(self, text='Y') self.lb_y.grid(row=0, column=2) self.ed_y = TK.Entry(self, width=5) self.ed_y.grid(row=0, column=3) # text fields self.txt_prog = TK.Text(self, width=20) self.txt_prog.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # button - run self.btn_run = TK.Button(self, text='RUN') self.btn_run.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # button clear self.btn_clear = TK.Button(self, text='CLEAR') self.btn_clear.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # bindings self.ed_y.bind('<Key>', self.edXY_on_key_enter) self.ed_x.bind('<Key>', self.edXY_on_key_enter) self.btn_run.bind('<Button-1>', self.btnRun_on_click) self.btn_clear.bind('<Button-1>', self.btnClear_on_click) # events dispatcher.add_event('go_coordinates') dispatcher.on_click += self.on_mouse1_click # start ticking self.after(self.tick_interval, self.tick)