From 6416df3e5f1284f85c7ed938729c91b40a49c168 Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Fri, 10 Aug 2012 13:47:26 +0200 Subject: [PATCH 1/2] Added pretty difficult level 3. --- robotgame/level3.py | 74 +++++++++++++++++++++++++++++++++++++++- robotgame/level_bonus.py | 2 +- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/robotgame/level3.py b/robotgame/level3.py index bc17a74..49024b2 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -56,8 +56,54 @@ class Level3(level.Level): # self.tiles.append( # tile.Tile(self, i*64, j*48, self.imgs['ground1'])) + task_start = (2, 2) + task_size = (5, 5) + + # Abstract "boxes", actually colour fields + boxes = logic.colourboxes.generate_colour_boxes(4, 6) + boxes += boxes + boxes += [logic.colourboxes.generate_random_box(4) for _ in range(12)] + random.shuffle(boxes) + + pos_colour = {} + for box, (x, y) in zip(boxes, itertools.product(range(6), range(4))): + self.tiles.append(tile.Tile(self, 64 * (x + task_start[0] + 1), + 48 * (y + task_start[1] + 1), + self.imgs['ground1'])) + pos_colour[(x, y)] = box + self.draw_background() + action_blocks = [block.ActionBlock(self, 64 * (i + 1 + task_start[0]), + 48 * task_start[1], movable=True) + for i in range(6)] + self.objects.extend(action_blocks) + + wells = [block.ColorWell(self, task_start[0] * 64, task_start[1] * 48), + block.ColorWell(self, (task_start[0] + 7) * 64, task_start[1] * 48), + block.ColorWell(self, task_start[0] * 64, (task_start[1] + 5) * 48), + block.ColorWell(self, (task_start[0] + 7) * 64, (task_start[1] + 5) * 48), + ] + self.objects.extend(wells) + + def update_wells(block): + cur_boxes = [] + for block in action_blocks: + box = pos_colour.get((block.x / 64 - task_start[0], + block.y / 48 - task_start[1] - 1)) + if box: + cur_boxes.append(box) + + if not cur_boxes: + well_colours = [(0, 0, 0)] * len(wells) + else: + well_colours = logic.colourboxes.get_colours(cur_boxes) + for well, color in zip(wells, well_colours): + well.set_colour(*color) + + for b in action_blocks: + b.action = update_wells + def load(self): """Load all resources used in the level.""" @@ -67,11 +113,37 @@ class Level3(level.Level): self.imgs[tile] = pygame.image.load(os.path.join( self.graphics_dir, 'tiles', '%s.png' % tile)) - block_list = ['block1'] + block_list = ['block1', 'block1_lifted'] for block in block_list: self.imgs[block] = pygame.image.load(os.path.join( self.graphics_dir, 'blocks', '%s.png' % block)) + # Load animations + for anim, directory in ( + [('lever_updown', os.path.join('lever', 'down-up')), + ] + ): + + self.imgs[anim] = [] + + # Find all image files for the given animation + anim_files = [] + for root, dirs, files in os.walk(os.path.join( + self.graphics_dir, directory)): + for f in files: + if re.match(r"^.*\.(png)$", '/'.join([root, f])): + anim_files.append('/'.join([root, f])) + + # Sort and load the files + for f in sorted(anim_files): + img = pygame.image.load(f) + + # Special treatment: + if anim == 'arrow_left': + img = pygame.transform.flip(img, 1, 0) + + self.imgs[anim].append(img) + def restart(self): for obj in self.objects: obj.reset_pos() diff --git a/robotgame/level_bonus.py b/robotgame/level_bonus.py index 69b1f0a..020ae2a 100644 --- a/robotgame/level_bonus.py +++ b/robotgame/level_bonus.py @@ -82,7 +82,7 @@ class Level(level.Level): self.imgs[tile] = pygame.image.load(os.path.join( self.graphics_dir, 'tiles', '%s.png' % tile)) - block_list = ['block1'] + block_list = ['block1', 'block1_lifted'] for block in block_list: self.imgs[block] = pygame.image.load(os.path.join( self.graphics_dir, 'blocks', '%s.png' % block)) From 924d56c00e3036634eab8065b68ee9ff0cadce01 Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Fri, 10 Aug 2012 13:51:22 +0200 Subject: [PATCH 2/2] Minor bug fix. --- robotgame/level3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robotgame/level3.py b/robotgame/level3.py index 49024b2..c7e8968 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -89,7 +89,7 @@ class Level3(level.Level): def update_wells(block): cur_boxes = [] for block in action_blocks: - box = pos_colour.get((block.x / 64 - task_start[0], + box = pos_colour.get((block.x / 64 - task_start[0] - 1, block.y / 48 - task_start[1] - 1)) if box: cur_boxes.append(box)