Added task 1.

This commit is contained in:
Sakse Dalum 2012-08-10 22:31:15 +02:00
parent d6ec520e21
commit bb17cbb430
2 changed files with 129 additions and 4 deletions

View File

@ -37,6 +37,7 @@ import block
import boulder
import lever
import trigger
import worldobject
import logic.rollingstone
import logic.colourboxes
@ -72,6 +73,69 @@ class Level1(level.Level):
self.objects.append(block.InvisBlock(self, self.dimensions[0] * 64,
i * 48))
### Task 1: Wheels of fortune
task1_pos = (64 * 10, 48 * 10)
ws = []
for i in range(5):
w1 = Wheel(self, task1_pos[0] - 64, task1_pos[1] + 48 * i * 2)
w2 = Wheel(self, task1_pos[0], task1_pos[1] + 48 * i * 2,
immitate=w1)
self.objects.extend([w1, w2])
self.objects.append(lever.Lever(self,
task1_pos[0] + 64 * 1,
task1_pos[1] + 48 * i * 2,
[w2.activate]))
if i > 0:
self.objects.append(lever.Lever(self,
task1_pos[0],
task1_pos[1] + 48 * (i * 2 - 1),
[w2.set_direction],
toggling=True))
else:
self.objects.append(lever.Lever(self,
task1_pos[0] + 64 * 2,
task1_pos[1] - 48,
[w2.set_direction],
toggling=True,
anim='lever_updown'))
ws.append(w2)
self.objects.append(
lever.Lever(self,
task1_pos[0] + 64 * 2,
task1_pos[1] + 48 * 9,
[lambda *xs: self.complete_task(1)
if len(ws) == len([w for w in ws if w.on])
else lambda: None],
anim='lever_updown'))
for i in range(9):
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] + 48 * i,
'moat_vertical')
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] - 48,
'moat_corner_north')
self.add_tile(task1_pos[0] - 64 * 2,
task1_pos[1] + 48 * 9,
'moat_corner_south')
for i in range(2):
self.add_tile(task1_pos[0] + 64 * (i - 1),
task1_pos[1] - 48,
'moat_horizontal')
self.add_tile(task1_pos[0] + 64 * (i - 1),
task1_pos[1] + 48 * 9,
'moat_horizontal')
self.add_tile(task1_pos[0] + 64,
task1_pos[1] - 48,
'moat_end_horizontal_flip')
self.add_tile(task1_pos[0] + 64,
task1_pos[1] + 48 * 9,
'moat_end_horizontal_flip')
### Task 2: Rolling stone
task2_size = 15, 10
@ -88,7 +152,13 @@ class Level1(level.Level):
task2_pos[0] + 64 * i,
task2_pos[1] + 48 * j,
self.imgs['block1'],
movable=True))
movable=True)
if (random.randint(0, 2) or (i, j) == 4) else
block.Block(self,
task2_pos[0] + 64 * i,
task2_pos[1] + 48 * j,
self.imgs['block3'],
movable=False))
arrow_blocks = []
n = 0
@ -349,3 +419,55 @@ class Level1(level.Level):
def restart(self):
for obj in self.objects:
obj.reset_pos()
class Wheel(block.Block):
def __init__(self, level, x, y, immitate=None):
self.__dict__.update(locals())
worldobject.WorldObject.__init__(self, level, x, y)
self.frame = 0
self.anim_speed = 15
self.nsettings = 5
self.setting = random.randint(0, self.nsettings - 1)
if self.immitate:
self.on = self.setting == self.immitate.setting
self.init_setting = self.setting
self.anim = 'stairs'
self.anim_direction = 1
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 set_direction(self, setting):
self.anim_direction = -1 if setting else 1
def activate(self, setting):
self.setting = (self.setting + 1 * self.anim_direction) % self.nsettings
self.on = self.setting == self.immitate.setting
def update(self, e, t, dt):
# Update the animation
l = len(self.level.imgs[self.anim])
if not (int(self.frame) == self.setting * l / self.nsettings):
self.frame = ((self.frame + self.anim_speed * dt) % l
if (self.setting > 0 and self.anim_direction > 0)
or (self.setting == self.nsettings - 1
and self.anim_direction < 0) else
(self.frame - self.anim_speed * dt) % l)
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 - self.level.camera_x,
self.y - self.img.get_size()[1] + 24
- self.level.camera_y))

View File

@ -44,7 +44,7 @@ class Loader(object):
self.imgs['indoor%d' % o] = pygame.image.load(os.path.join(
self.directory, 'tiles', 'indoor', 'ground%02d.png' % o))
l = ['block1', 'block1_lifted']
l = ['block1', 'block1_lifted', 'block3']
for o in l:
self.imgs[o] = pygame.image.load(os.path.join(
self.directory, 'blocks', '%s.png' % o))
@ -83,7 +83,9 @@ class Loader(object):
('arrow_up', os.path.join('matt', 'up')),
('arrow_right', os.path.join('matt', 'right')),
('arrow_down', os.path.join('matt', 'down')),
('arrow_left', os.path.join('matt', 'right')),]
('arrow_left', os.path.join('matt', 'right')),
('stairs', 'stairs')]
):
self.imgs[anim] = []
@ -176,7 +178,8 @@ class Loader(object):
if anim in ['idle_left', 'carry_left',
'lever_down_right', 'lever_left_down',
'lever_up_left', 'lever_right_up']:
'lever_up_left', 'lever_right_up',
'lever_left_right']:
img = pygame.transform.flip(img, 1, 0)
if anim in ['lever_right_left', 'lever_left_right',