Holy smokes, level 1 almost finished!

This commit is contained in:
Sakse Dalum 2012-08-12 19:05:54 +02:00
parent da2bcecfa5
commit 4babce9f3c
4 changed files with 89 additions and 3 deletions

View File

@ -39,7 +39,7 @@ class Block(worldobject.WorldObject):
for i in range(width):
for j in range(height):
if not i or not j :
if width != 1 or height != 1:
self.level.objects.append(
InvisBlock(self.level,
self.x + 64 * i,
@ -236,3 +236,52 @@ class ColorWell(Block):
self.y - self.img.get_size()[1] + 52
- self.level.camera_y))
Block.draw(self, window)
class Door(Block):
def __init__(self, level, x, y, movable=False, setting=False):
self.__dict__.update(locals())
worldobject.WorldObject.__init__(self, level, x, y, movable=movable)
self.frame = 0
self.anim_speed = 15
self.init_setting = self.setting
self.anim = 'door'
self.level.objects.append(InvisBlock(self.level, self.x + 64, self.y))
self.level.objects.append(InvisBlock(self.level, self.x - 64, self.y))
def set_init_pos(self):
worldobject.WorldObject.set_init_pos(self)
self.init_setting = self.setting
def reset_pos(self):
worldobject.WorldObject.reset_pos(self)
self.setting = self.init_setting
def activate(self, setting):
self.setting = setting
def update(self, e, t, dt):
# Update the animation
if self.setting:
self.frame = min(self.frame + self.anim_speed * dt,
len(self.level.imgs[self.anim]) - 1)
else:
self.frame = max(self.frame - self.anim_speed * dt,
0)
if self.frame == len(self.level.imgs[self.anim]) - 1:
self.blocking = False
else:
self.blocking = True
worldobject.WorldObject.update(self, e, t, dt)
def draw(self, window):
self.img = self.level.imgs[self.anim][int(self.frame)]
if self.visible:
window.blit(self.img, (self.x - (32 + 64) - self.level.camera_x,
self.y - self.img.get_size()[1] + 24
- self.level.camera_y))

View File

@ -48,6 +48,11 @@ class Level1(level.Level):
48 * 100),
paused=paused)
self.solution = range(1, 6)
random.shuffle(self.solution)
self.solution = self.solution[:3]
print self.solution
self.task_completions = []
self.dimensions = 50, 50
@ -469,6 +474,35 @@ class Level1(level.Level):
task5_pos[0] - 64 * (task5_size[1]),
task5_pos[1] - (task5_size[0] / 2) * 48,
[lambda *x: self.complete_task(5)]))
### Final: The door
door_x = 22
for i in range(12):
self.add_tile(door_x * 64,
48 * (5 + i),
'indoor%d' % random.randint(1, 6), blocking=False)
for i in range(7):
self.add_tile((door_x - i - 1) * 64,
48 * (5 + 11),
'indoor%d' % random.randint(1, 6), blocking=False)
door = block.Door(self, 64 * door_x, 48 * 4)
self.objects.append(door)
self.objects.append(
lever.Lever(self, 64 * (door_x + 3), 48 * 4,
[lambda x: door.activate(x)
if self.task_completions == self.solution
else lambda *v: None],
anim='lever_updown', toggling=False))
self.objects.append(
trigger.Trigger(self, 64 * door_x, 48 * 4,
[self.game.goto_level],
self.imgs['indoor1'],
[self.player]))
# DRAW THE BACKGROUND
self.draw_background()

View File

@ -88,7 +88,9 @@ class Loader(object):
('stairs', 'stairs'),
('elevating_column', 'elevating_column'),
('mirror', 'mirror')]
('mirror', 'mirror'),
('door', 'door')]
):
self.imgs[anim] = []

View File

@ -52,7 +52,8 @@ class Trigger(worldobject.WorldObject):
if self.x == obj.x and self.y == obj.y:
self.trigger(True, obj)
break
self.trigger(False, None)
if self.toggling:
self.trigger(False, obj)
worldobject.WorldObject.update(self, e, t, dt)