From c0f59d72c948c25e60368317c0d0387c0624d60c Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Fri, 10 Aug 2012 21:54:21 +0200 Subject: [PATCH 1/3] Level 3 easier but still missing necessary clues to the player. --- robotgame/level3.py | 30 ++++++++++++++++++------------ robotgame/logic/colourboxes.py | 27 ++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/robotgame/level3.py b/robotgame/level3.py index b09a799..8c59e76 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -57,16 +57,17 @@ class Level3(level.Level): # tile.Tile(self, i*64, j*48, self.imgs['ground1'])) task_start = (2, 2) - task_size = (5, 5) # Abstract "boxes", actually colour fields - boxes = [box + [(0, 0, 0)] * 2 for box in logic.colourboxes.generate_colour_boxes(2, 3)] - boxes += [[(0, 0, 0)] * 2 + box for box in logic.colourboxes.generate_colour_boxes(2, 3)] - boxes += [logic.colourboxes.generate_random_box(4) for _ in range(9)] - boxes += [[(0, 0, 0)] * 4 for _ in range(9)] + boxes = [] + for i in range(4): + boxes.extend([(0, 0, 0)] * i + box + [(0, 0, 0)] * (3 - i) + for box in logic.colourboxes.generate_colour_boxes(1, 3)) + boxes.extend(logic.colourboxes.generate_random_box(4, 2) for _ in range(20)) + boxes.extend([(0, 0, 0)] * 4 for _ in range(10)) random.shuffle(boxes) pos_colour = {} - for box, (x, y) in zip(boxes, itertools.product(range(6), range(4))): + for box, (x, y) in zip(boxes, itertools.product(range(7), range(6))): self.tiles.append(tile.Tile(self, 64 * (x + task_start[0] + 1), 48 * (y + task_start[1] + 1), self.imgs['ground1'])) @@ -74,15 +75,20 @@ class Level3(level.Level): 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)] + action_blocks = list(itertools.chain(* + [(block.ActionBlock(self, 64 * task_start[0], + 48 * (i + 1 + task_start[1]), + movable=True), + block.ActionBlock(self, 64 * (task_start[0] + 8), + 48 * (i + 1 + 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), + block.ColorWell(self, (task_start[0] + 8) * 64, task_start[1] * 48), + block.ColorWell(self, task_start[0] * 64, (task_start[1] + 7) * 48), + block.ColorWell(self, (task_start[0] + 8) * 64, (task_start[1] + 7) * 48), ] self.objects.extend(wells) diff --git a/robotgame/logic/colourboxes.py b/robotgame/logic/colourboxes.py index bf8c3fb..9ec886b 100644 --- a/robotgame/logic/colourboxes.py +++ b/robotgame/logic/colourboxes.py @@ -91,14 +91,35 @@ def _get_oxs(x): else (x - 1, x + 1) if x % 3 == 1 \ else (x - 2, x - 1) -def generate_random_box(nwells): - """Generate a box with random colors except white (111).""" +def generate_random_box(nwells, min_nonblacks=0): + """ + Generate a box that triggers nwells wells, with random colors except white + (111). + + Arguments: + min_nonblacks -- minimum number of well colours in a box required not to be + black. + """ def gen_wc(): wc = [random.choice((0, 1)) for i in range(3)] if all(b == 1 for b in wc): wc[random.randrange(3)] = 0 return wc - return [tuple(gen_wc()) for _ in range(nwells)] + def gen_wc_nonblack(): + wc = gen_wc() + if all(b == 0 for b in wc): + wc[random.randrange(3)] = 1 + return wc + colours = [tuple(gen_wc()) for _ in range(nwells)] + nonblack = lambda t: any(n == 1 for n in t) + missing_nonblacks = min_nonblacks - len(list(filter(nonblack, colours))) + i = 0 + while missing_nonblacks > 0: + if not nonblack(colours[i]): + colours[i] = gen_wc_nonblack() + missing_nonblacks -= 1 + i += 1 + return colours def get_colours(boxes): colours = [] From 6790174a76ff5f114f53b35134aacce6327d2329 Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Fri, 10 Aug 2012 22:10:27 +0200 Subject: [PATCH 2/3] Erased useless load functions. --- robotgame/level2.py | 39 --------------------------------------- robotgame/level3.py | 39 --------------------------------------- robotgame/level_bonus.py | 40 ---------------------------------------- 3 files changed, 118 deletions(-) diff --git a/robotgame/level2.py b/robotgame/level2.py index c3e7e88..c429d9e 100644 --- a/robotgame/level2.py +++ b/robotgame/level2.py @@ -45,45 +45,6 @@ class Level2(level.Level): anim='lever_updown')) - def load(self): - """Load all resources used in the level.""" - tile_list = ['ground1', 'ground2'] - - for tile in tile_list: - self.imgs[tile] = pygame.image.load(os.path.join( - self.graphics_dir, 'tiles', '%s.png' % tile)) - - block_list = ['block1'] - 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/level3.py b/robotgame/level3.py index 8c59e76..dfbfca8 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -111,45 +111,6 @@ class Level3(level.Level): b.action = update_wells - def load(self): - """Load all resources used in the level.""" - tile_list = ['ground1', 'ground2'] - - for tile in tile_list: - self.imgs[tile] = pygame.image.load(os.path.join( - self.graphics_dir, 'tiles', '%s.png' % tile)) - - 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 020ae2a..b7c82b8 100644 --- a/robotgame/level_bonus.py +++ b/robotgame/level_bonus.py @@ -73,46 +73,6 @@ class Level(level.Level): toggling=False, anim='lever_updown')) - - def load(self): - """Load all resources used in the level.""" - tile_list = ['ground1', 'ground2'] - - for tile in tile_list: - self.imgs[tile] = pygame.image.load(os.path.join( - self.graphics_dir, 'tiles', '%s.png' % tile)) - - 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 enter(self, root_level): self.__dict__.update(locals()) self.game.objs.remove(root_level) From ba7edfffd49b6a310acf14cc0e211f882e6fae53 Mon Sep 17 00:00:00 2001 From: Niels Serup Date: Fri, 10 Aug 2012 22:20:31 +0200 Subject: [PATCH 3/3] Replaced ground tile with indoor tiles in some places. --- robotgame/level2.py | 2 +- robotgame/level3.py | 2 +- robotgame/level_bonus.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/robotgame/level2.py b/robotgame/level2.py index c429d9e..208c963 100644 --- a/robotgame/level2.py +++ b/robotgame/level2.py @@ -23,7 +23,7 @@ class Level2(level.Level): for i in range(self.dimensions[0]): for j in range(self.dimensions[1]): self.tiles.append( - tile.Tile(self, i*64, j*48, self.imgs['ground1'])) + tile.Tile(self, i*64, (j + 1)*48, self.imgs['indoor%d' % random.randint(1, 6)])) self.draw_background() diff --git a/robotgame/level3.py b/robotgame/level3.py index dfbfca8..fc3c136 100644 --- a/robotgame/level3.py +++ b/robotgame/level3.py @@ -70,7 +70,7 @@ class Level3(level.Level): for box, (x, y) in zip(boxes, itertools.product(range(7), range(6))): self.tiles.append(tile.Tile(self, 64 * (x + task_start[0] + 1), 48 * (y + task_start[1] + 1), - self.imgs['ground1'])) + self.imgs['indoor%d' % random.randint(1, 6)])) pos_colour[(x, y)] = box self.draw_background() diff --git a/robotgame/level_bonus.py b/robotgame/level_bonus.py index b7c82b8..31a06e8 100644 --- a/robotgame/level_bonus.py +++ b/robotgame/level_bonus.py @@ -49,7 +49,7 @@ class Level(level.Level): for i in range(self.dimensions[0]): for j in range(self.dimensions[1]): self.tiles.append( - tile.Tile(self, i*64, j*48, self.imgs['ground1'])) + tile.Tile(self, (i+1)*64, j*48, self.imgs['indoor%d' % random.randint(1, 6)])) self.draw_background()