Tasks now in correct order.

This commit is contained in:
Sakse Dalum 2012-08-12 20:01:58 +02:00
parent fbd699356c
commit 5fe049f585
2 changed files with 162 additions and 166 deletions

View File

@ -51,7 +51,6 @@ class Level1(level.Level):
self.solution = range(1, 6) self.solution = range(1, 6)
random.shuffle(self.solution) random.shuffle(self.solution)
self.solution = self.solution[:3] self.solution = self.solution[:3]
print self.solution
self.task_completions = [0, 0, 0] self.task_completions = [0, 0, 0]
@ -81,59 +80,69 @@ class Level1(level.Level):
self.objects.append(block.InvisBlock(self, self.dimensions[0] * 64, self.objects.append(block.InvisBlock(self, self.dimensions[0] * 64,
i * 48)) i * 48))
### Task 1: Wheels of fortune
task1_pos = (64 * 15, 48 * 13)
ws = []
for i in range(5): ### Task 1: Teleporters
w1 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1] - 48 * 2)
w2 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1], task5_size = 5, 8 # y, x -- Note, inverted.
immitate=w1) task5_pos = (64 * 12, 48 * 19)
self.objects.extend([w1, w2])
self.objects.append(lever.Lever(self, task5_nturns = random.randint(2, 4) * 2 - 1
task1_pos[0] + 64 * i,
task1_pos[1] + 48 * 1, playfield, nsteps, directions = (
[w2.activate], logic.rollingstone.generate_simple_unsolved_solvable_extra(
anim='lever_updown')) task5_size[0], task5_size[1], task5_nturns,
ws.append(w2) task5_size[0]*task5_size[1]))
self.add_tile(task1_pos[0] + 64 * i,
task1_pos[1] - 48 * 3, for x in range(task5_size[1]):
for y in range(task5_size[0]):
self.add_tile(task5_pos[0] - 64 * (x - 1),
task5_pos[1] - 48 * y,
'indoor%d' % random.randint(1, 6), blocking=False)
for i, j in playfield:
self.objects.append(
trigger.Trigger(self,
task5_pos[0] - 64 * (j - 1),
task5_pos[1] - 48 * i,
[lambda x: self.player.set_pos(
task5_pos[0] + 2 * 64,
(task5_pos[1]
- random.randint(0, task5_size[0] - 1) * 48))],
self.imgs['hole'],
[self.player],
visible=False))
for i in range(task5_size[1] + 1):
self.add_tile(task5_pos[0] - 64 * i,
task5_pos[1] + 48,
'moat_horizontal') 'moat_horizontal')
self.add_tile(task5_pos[0] - 64 * i,
task5_pos[1] - task5_size[0] * 48,
'moat_horizontal')
self.add_tile(task5_pos[0] + 64,
task5_pos[1] + 48,
'moat_end_horizontal_flip')
# self.add_tile(task5_pos[0] + 64,
# task5_pos[1] - task5_size[0] * 48,
# 'moat_end_horizontal_flip')
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1),
task5_pos[1] + 48,
'moat_corner_south')
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1),
task5_pos[1] - task5_size[0] * 48,
'moat_corner_north')
for i in range(task5_size[0]):
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1),
task5_pos[1] - 48 * i,
'moat_vertical')
self.objects.append( self.objects.append(
lever.Lever(self, lever.Lever(self,
task1_pos[0] + 64 * 5, task5_pos[0] - 64 * (task5_size[1]),
task1_pos[1] + 48 * 2, task5_pos[1] - (task5_size[0] / 2) * 48,
[lambda *xs: self.complete_task(1) [lambda *x: self.complete_task(1)]))
if len(ws) == len([w for w in ws if w.on])
else lambda: None]))
self.add_tile(task1_pos[0] - 64,
task1_pos[1] - 48 * 3,
'moat_corner_north')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] - 48 * 3,
'moat_corner_north_flip')
for i in range(3):
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48,
'moat_corner_south_flip')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48,
'moat_corner_south')
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] + 48,
'moat_horizontal')
self.add_tile(task1_pos[0] + 64 * 6,
task1_pos[1] + 48,
'moat_end_horizontal_flip')
### Task 2: Rolling stone ### Task 2: Rolling stone
@ -272,68 +281,11 @@ class Level1(level.Level):
task2_pos[1] + 48 * (task2_size[1] - 1), task2_pos[1] + 48 * (task2_size[1] - 1),
[self.complete_task, b.fall], [self.complete_task, b.fall],
self.imgs['hole'], [b], self.imgs['hole'], [b],
signal=[0, 2])) signal=[0, 2],
toggling=True))
### Task 3: Colour blocks ### Task 3: Inverted bits
task3_pos = (64 * 15, 48 * 20)
# Abstract "boxes", actually colour fields
boxes = logic.colourboxes.generate_colour_boxes(1, 3)
boxes += boxes
boxes += [logic.colourboxes.generate_random_box(1) for _ in range(3)]
random.shuffle(boxes)
pos_colour = {}
for box, (x, y) in zip(boxes, itertools.product(range(3), range(3))):
# self.tiles.append(tile.Tile(self, x * 64 + task3_pos[0],
# y * 48 + task3_pos[1],
# self.imgs['ground1']))
pos_colour[(x, y)] = box
self.add_tile(task3_pos[0] + 64 * x, task3_pos[1] + 48 * (y + 1),
'indoor%d' % random.randint(1, 6), blocking=False)
action_blocks = [block.ActionBlock(self, 64 * i + task3_pos[0],
task3_pos[1], movable=True)
for i in range(3)]
self.objects.extend(action_blocks)
wells = [block.ColorWell(self, task3_pos[0] + 64,
task3_pos[1] + 48 * 5)]
self.objects.extend(wells)
def update_wells(block):
cur_boxes = []
for block in action_blocks:
box = pos_colour.get(((block.x - task3_pos[0]) / 64,
(block.y - task3_pos[1] - 48) / 48))
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 i in range(len(wells)):
wells[i].set_colour(*well_colours[i])
for b in action_blocks:
b.action = update_wells
self.objects.append(
lever.Lever(self,
task3_pos[0] + 64,
task3_pos[1] + 48 * 4,
[lambda *x: (self.complete_task(3)
if (len([w for w in wells
if (w.well_colour
== (255, 255, 255))
])
== len(wells))
else lambda: None)]))
### Task 4: Inverted bits
task4_pos = (64 * 26, 48 * 18) task4_pos = (64 * 26, 48 * 18)
@ -389,7 +341,7 @@ class Level1(level.Level):
task4_pos[1] - 48 * 3, task4_pos[1] - 48 * 3,
[self.complete_task, b.fall], [self.complete_task, b.fall],
self.imgs['hole'], [b], self.imgs['hole'], [b],
signal=[0, 4])) signal=[0, 3]))
# Moat # Moat
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4, self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4,
@ -413,67 +365,117 @@ class Level1(level.Level):
'moat_end_horizontal') 'moat_end_horizontal')
### Task 5: Teleporters ### Task 4: Colour blocks
task5_size = 5, 8 # y, x -- Note, inverted. task3_pos = (64 * 15, 48 * 20)
task5_pos = (64 * 12, 48 * 19)
task5_nturns = random.randint(2, 4) * 2 - 1 # Abstract "boxes", actually colour fields
boxes = logic.colourboxes.generate_colour_boxes(1, 3)
boxes += boxes
boxes += [logic.colourboxes.generate_random_box(1) for _ in range(3)]
random.shuffle(boxes)
playfield, nsteps, directions = ( pos_colour = {}
logic.rollingstone.generate_simple_unsolved_solvable_extra( for box, (x, y) in zip(boxes, itertools.product(range(3), range(3))):
task5_size[0], task5_size[1], task5_nturns, # self.tiles.append(tile.Tile(self, x * 64 + task3_pos[0],
task5_size[0]*task5_size[1])) # y * 48 + task3_pos[1],
# self.imgs['ground1']))
for x in range(task5_size[1]): pos_colour[(x, y)] = box
for y in range(task5_size[0]): self.add_tile(task3_pos[0] + 64 * x, task3_pos[1] + 48 * (y + 1),
self.add_tile(task5_pos[0] - 64 * (x - 1),
task5_pos[1] - 48 * y,
'indoor%d' % random.randint(1, 6), blocking=False) 'indoor%d' % random.randint(1, 6), blocking=False)
action_blocks = [block.ActionBlock(self, 64 * i + task3_pos[0],
task3_pos[1], movable=True)
for i in range(3)]
self.objects.extend(action_blocks)
for i, j in playfield: wells = [block.ColorWell(self, task3_pos[0] + 64,
self.objects.append( task3_pos[1] + 48 * 5)]
trigger.Trigger(self, self.objects.extend(wells)
task5_pos[0] - 64 * (j - 1),
task5_pos[1] - 48 * i,
[lambda x: self.player.set_pos(
task5_pos[0] + 2 * 64,
(task5_pos[1]
- random.randint(0, task5_size[0] - 1) * 48))],
self.imgs['hole'],
[self.player],
visible=False))
for i in range(task5_size[1] + 1): def update_wells(block):
self.add_tile(task5_pos[0] - 64 * i, cur_boxes = []
task5_pos[1] + 48, for block in action_blocks:
'moat_horizontal') box = pos_colour.get(((block.x - task3_pos[0]) / 64,
self.add_tile(task5_pos[0] - 64 * i, (block.y - task3_pos[1] - 48) / 48))
task5_pos[1] - task5_size[0] * 48, if box:
'moat_horizontal') cur_boxes.append(box)
self.add_tile(task5_pos[0] + 64,
task5_pos[1] + 48, if not cur_boxes:
'moat_end_horizontal_flip') well_colours = [(0, 0, 0)] * len(wells)
# self.add_tile(task5_pos[0] + 64, else:
# task5_pos[1] - task5_size[0] * 48, well_colours = logic.colourboxes.get_colours(cur_boxes)
# 'moat_end_horizontal_flip') for i in range(len(wells)):
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1), wells[i].set_colour(*well_colours[i])
task5_pos[1] + 48,
'moat_corner_south') for b in action_blocks:
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1), b.action = update_wells
task5_pos[1] - task5_size[0] * 48,
'moat_corner_north')
for i in range(task5_size[0]):
self.add_tile(task5_pos[0] - 64 * (task5_size[1] + 1),
task5_pos[1] - 48 * i,
'moat_vertical')
self.objects.append( self.objects.append(
lever.Lever(self, lever.Lever(self,
task5_pos[0] - 64 * (task5_size[1]), task3_pos[0] + 64,
task5_pos[1] - (task5_size[0] / 2) * 48, task3_pos[1] + 48 * 4,
[lambda *x: self.complete_task(5)])) [lambda *x: (self.complete_task(4)
if (len([w for w in wells
if (w.well_colour
== (255, 255, 255))
])
== len(wells))
else lambda: None)]))
### Task 5: Rising columns
task1_pos = (64 * 15, 48 * 13)
ws = []
for i in range(5):
w1 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1] - 48 * 2)
w2 = Wheel(self, task1_pos[0] + 64 * i, task1_pos[1],
immitate=w1)
self.objects.extend([w1, w2])
self.objects.append(lever.Lever(self,
task1_pos[0] + 64 * i,
task1_pos[1] + 48 * 1,
[w2.activate],
anim='lever_updown'))
ws.append(w2)
self.add_tile(task1_pos[0] + 64 * i,
task1_pos[1] - 48 * 3,
'moat_horizontal')
self.objects.append(
lever.Lever(self,
task1_pos[0] + 64 * 5,
task1_pos[1] + 48 * 2,
[lambda *xs: self.complete_task(5)
if len(ws) == len([w for w in ws if w.on])
else lambda: None]))
self.add_tile(task1_pos[0] - 64,
task1_pos[1] - 48 * 3,
'moat_corner_north')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] - 48 * 3,
'moat_corner_north_flip')
for i in range(3):
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48 * (i - 2),
'moat_vertical')
self.add_tile(task1_pos[0] - 64,
task1_pos[1] + 48,
'moat_corner_south_flip')
self.add_tile(task1_pos[0] + 64 * 5,
task1_pos[1] + 48,
'moat_corner_south')
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] + 48,
'moat_horizontal')
self.add_tile(task1_pos[0] + 64 * 6,
task1_pos[1] + 48,
'moat_end_horizontal_flip')
### Final: The door ### Final: The door
@ -523,7 +525,6 @@ class Level1(level.Level):
self.task_completions.append(task) self.task_completions.append(task)
if len(self.task_completions) > 3: if len(self.task_completions) > 3:
self.task_completions = self.task_completions[-3:] self.task_completions = self.task_completions[-3:]
print(self.task_completions)
def restart(self): def restart(self):
for obj in self.objects: for obj in self.objects:

View File

@ -123,11 +123,6 @@ class Player(worldobject.WorldObject):
if event.key == pygame.K_SPACE: if event.key == pygame.K_SPACE:
self.touch(*self.direction) self.touch(*self.direction)
for i in range(1, 6):
if event.key == getattr(pygame, 'K_%d' % i):
self.level.complete_task(i)
else: else:
self.working = not (self.frame == len( self.working = not (self.frame == len(
self.imgs[self.anim_root + '_' + self.anim]) - 1) self.imgs[self.anim_root + '_' + self.anim]) - 1)