Added task 5.

This commit is contained in:
Sakse Dalum 2012-08-12 17:36:59 +02:00
parent d6e8fc2c44
commit 2c3b75fc44
2 changed files with 72 additions and 9 deletions

View File

@ -405,7 +405,68 @@ class Level1(level.Level):
'moat_end_horizontal') 'moat_end_horizontal')
### Task 5: The bridge. ### Task 5: Teleporters
task5_size = 5, 8 # y, x -- Note, inverted.
task5_pos = (64 * 10, 48 * 10)
task5_nturns = random.randint(2, 4) * 2 - 1
playfield, nsteps, directions = (
logic.rollingstone.generate_simple_unsolved_solvable_extra(
task5_size[0], task5_size[1], task5_nturns,
task5_size[0]*task5_size[1]))
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')
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(
lever.Lever(self,
task5_pos[0] - 64 * (task5_size[1]),
task5_pos[1] - (task5_size[0] / 2) * 48,
[lambda *x: self.complete_task(5)]))
# DRAW THE BACKGROUND
self.draw_background() self.draw_background()

View File

@ -31,15 +31,16 @@ import worldobject
class Trigger(worldobject.WorldObject): class Trigger(worldobject.WorldObject):
def __init__(self, level, x, y, links, img, trigger_objs, def __init__(self, level, x, y, links, img, trigger_objs,
toggling=False, signal=[0, 1], toggling=False, signal=[0, 1],
setting=False): setting=False, blocking=False,
visible=True):
self.__dict__.update(locals()) self.__dict__.update(locals())
worldobject.WorldObject.__init__(self, level, x, y, z=-48, worldobject.WorldObject.__init__(self, level, x, y, z=-48,
blocking=False) blocking=blocking, visible=visible)
self.frame = 0 self.frame = 0
self.anim_speed = 15 self.anim_speed = 15
def trigger(self, setting): def trigger(self, setting, obj):
if self.setting != setting: if self.setting != setting:
self.setting = setting self.setting = setting
@ -49,13 +50,14 @@ class Trigger(worldobject.WorldObject):
def update(self, e, t, dt): def update(self, e, t, dt):
for obj in self.trigger_objs: for obj in self.trigger_objs:
if self.x == obj.x and self.y == obj.y: if self.x == obj.x and self.y == obj.y:
self.trigger(True) self.trigger(True, obj)
break break
self.trigger(False) self.trigger(False, None)
worldobject.WorldObject.update(self, e, t, dt) worldobject.WorldObject.update(self, e, t, dt)
def draw(self, window): def draw(self, window):
window.blit(self.img, (self.x - 32 - self.level.camera_x, if self.visible:
self.y - self.img.get_size()[1] + 24 window.blit(self.img, (self.x - 32 - self.level.camera_x,
- self.level.camera_y)) self.y - self.img.get_size()[1] + 24
- self.level.camera_y))