def start(self): global inoutput inoutput = False global invariables invariables = False global inlists inlists = False global inloops inloops = False global moved moved = False global otherdirs otherdirs = [] end_pos = shared.dim + Vec2d(200, 200) shared.gui.help_page.set_text(helps['move']) # use our own output function userspace.space['output'] = output # make the background grid objects.create(image.Image, grid_path, (0, 0)) # make the player player = objects.create(_Player, grid_step * Vec2d(5.5, 5.5)) userspace.space['player'] = player.proxy
def start(self): shared.gui.help_page.set_text(helps['breakout']) # make the background grid objects.create(image.Image, grid_path, (0, 0)) # Paddle and Ball self.paddle = objects.create(_Paddle, (shared.dim.x / 2, shared.dim.y - grid_step * 2.5)) ballvel = Vec2d(1, 1) ballvel.length = ball_speed self.ball = objects.create(_Ball, (shared.dim.x / 2, shared.dim.y / 2), ballvel) # reset hits global hits hits = 0
def start(self): random.seed() self.paddle = objects.create(_Paddle, Vec2d(int(shared.dim.x/2), int(shared.dim.y - 20))) self.ball = objects.create(_Ball, Vec2d(shared.dim) / 2) bricks = {} self._bricks = {} for row in xrange(0, 10): for col in xrange(0, int(shared.dim.x/40)): brick = objects.create(_Brick, pygame.Rect(40*col + 5, 20*row + 5, 38, 18)) bricks[(row, col)] = brick.proxy self._bricks[(row, col)] = brick userspace.space['bricks'] = bricks userspace.space['ball'] = self.ball.proxy userspace.space['paddle'] = self.paddle.proxy
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 start(self): shared.gui.help_page.set_text(helps['breakout']) # make the background grid objects.create(image.Image, grid_path, (0, 0)) userspace.space['left_wall'] = grid_step + ball_width/2 userspace.space['right_wall'] = shared.dim.x - (grid_step + ball_width/2) userspace.space['top_wall'] = grid_step + ball_height/2 userspace.space['paddle_speed'] = paddle_speed # Paddle and Ball self.paddle = objects.create(_Paddle, (shared.dim.x / 2, shared.dim.y - grid_step * 2.5)) ballvel = Vec2d(1, 1) ballvel.length = ball_speed self.ball = objects.create(_Ball, (shared.dim.x / 2, shared.dim.y / 2), ballvel) # reset hits global hits hits = 0