def set_motion(self, arg): vels = { 'left': Vec2d(-paddle_speed, 0), 'right': Vec2d(paddle_speed, 0), 'stop': Vec2d(0, 0) } vel = vels.get(arg) if vel is not None: objects.proxy_map[self].vel = vel else: userspace.output("Error: '%s' is not a valid motion!" % (arg))
def run(self): try: code = compile(self.text, self.filename, "exec") userspace.run(code) except Exception as e: userspace.output("Error: " + e.__str__()) gtk.threads_enter() shared.gui.set_status("Error! Check output console.") gtk.threads_leave() except SystemExit: gtk.threads_enter() shared.gui.set_status("Cancelled.") gtk.threads_leave() else: gtk.threads_enter() shared.gui.set_status("Finished running!") gtk.threads_leave() shared.gui.runner = None
def move(self, dirstr): global moved global otherdirs global inloops player = objects.proxy_map[self] dirs = { 'left': Vec2d(-grid_step, 0), 'right': Vec2d(grid_step, 0), 'up': Vec2d(0, -grid_step), 'down': Vec2d(0, grid_step) } vec = dirs.get(dirstr) if vec: if not moved: otherdirs = list(dirs.iterkeys()) otherdirs.remove(dirstr) shared.gui.help_page.append_text( helps['otherdirs'] % tuple(otherdirs)) moved = True elif dirstr in otherdirs: shared.gui.help_page.append_text(helps['output']) global inoutput inoutput = True otherdirs = [] elif inloops: shared.gui.help_page.set_text(helps['end']) global end_pos end_pos = shared.dim - grid_step * Vec2d(6, 6) objects.create(image.Image, endblock_path, end_pos) inloops = False player.move(vec) # check if we won pos = player.pos if (pos.x > end_pos.x and pos.x < end_pos.x + grid_step and pos.y > end_pos.y and pos.y < end_pos.y + grid_step): shared.levelmgr.get_current_level().data.completed = True shared.levelmgr.get_current_level().won = True shared.levelmgr.request_next_level() shared.gui.help_page.set_text("# Well done! You completed 'Basics 1'") else: userspace.output("Error: '%s' is not a valid direction!" % (dirstr))
def output(s): global inoutput global invariables global oldsize global inlists global inloops userspace.output(s) if inoutput: inoutput = False shared.gui.help_page.append_text(helps['variables']) oldsize = len(userspace.space) invariables = True elif invariables and len(userspace.space) > oldsize: invariables = False shared.gui.help_page.append_text(helps['lists']) inlists = True elif inlists and type(s) == list: inlists = False shared.gui.help_page.set_text(helps['loops']) inloops = True