Added well and compactified level1.

This commit is contained in:
Sakse Dalum 2012-08-10 18:37:17 +02:00
parent eee3dc7920
commit a49c3135c4
2 changed files with 51 additions and 40 deletions

View File

@ -208,18 +208,22 @@ class ActionBlock(Block):
worldobject.WorldObject.update(self, e, t, dt)
class ColorWell(Block):
def __init__(self, level, x, y):
def __init__(self, level, x, y, img_str='well'):
self.__dict__.update(locals())
worldobject.WorldObject.__init__(
self, level, x, y, movable=False)
self.img = pygame.Surface((64, 64))
Block.load(self)
self.col_img = pygame.Surface((32, 32))
def set_colour(self, r, g, b):
self.well_colour = r * 255, g * 255, b * 255
self.img.fill(self.well_colour)
self.col_img.fill(self.well_colour)
def draw(self, window):
if self.visible:
window.blit(self.img, (self.x - self.level.camera_x,
self.y - self.img.get_size()[1]
window.blit(self.col_img, (self.x - self.level.camera_x + 16,
self.y - self.img.get_size()[1] + 52
- self.level.camera_y))
Block.draw(self, window)

View File

@ -120,69 +120,69 @@ class Level1(level.Level):
anim='lever_updown'))
# Moat sides
for i in range(-1, task2_size[1]):
self.add_moat(task2_pos[0] - 64,
self.add_tile(task2_pos[0] - 64,
task2_pos[1] + 48 * i,
'moat_vertical')
for i in range(task2_size[1] - 2):
self.add_moat(task2_pos[0] + 64 * task2_size[0],
self.add_tile(task2_pos[0] + 64 * task2_size[0],
task2_pos[1] + 48 * i,
'moat_vertical')
for i in range(6, task2_size[0]):
self.add_moat(task2_pos[0] + 64 * i,
self.add_tile(task2_pos[0] + 64 * i,
task2_pos[1] - 48,
'moat_horizontal')
for i in range(task2_size[0] - 2):
self.add_moat(task2_pos[0] + 64 * i,
self.add_tile(task2_pos[0] + 64 * i,
task2_pos[1] + 48 * task2_size[1],
'moat_horizontal')
# Corners
self.add_moat(task2_pos[0] + 64 * task2_size[0],
self.add_tile(task2_pos[0] + 64 * task2_size[0],
task2_pos[1] - 48,
'moat_corner_north_flip')
self.add_moat(task2_pos[0] - 64,
self.add_tile(task2_pos[0] - 64,
task2_pos[1] + 48 * task2_size[1],
'moat_corner_south')
# Start
self.add_moat(task2_pos[0] + 64 * 2,
self.add_tile(task2_pos[0] + 64 * 2,
task2_pos[1] - 48,
'moat_horizontal')
self.add_moat(task2_pos[0] + 64 * 3,
self.add_tile(task2_pos[0] + 64 * 3,
task2_pos[1] - 48,
'moat_end_horizontal_flip')
self.add_moat(task2_pos[0] + 64 * 5,
self.add_tile(task2_pos[0] + 64 * 5,
task2_pos[1] - 48,
'moat_end_horizontal')
self.add_moat(task2_pos[0] - 64,
self.add_tile(task2_pos[0] - 64,
task2_pos[1] - 48 * 2,
'moat_corner_north')
self.add_moat(task2_pos[0],
self.add_tile(task2_pos[0],
task2_pos[1] - 48 * 2,
'moat_horizontal')
self.add_moat(task2_pos[0] + 64,
self.add_tile(task2_pos[0] + 64,
task2_pos[1] - 48 * 2,
'moat_corner_north_flip')
self.add_moat(task2_pos[0] + 64,
self.add_tile(task2_pos[0] + 64,
task2_pos[1] - 48,
'moat_corner_south')
# End
self.add_moat(task2_pos[0] + 64 * task2_size[0],
self.add_tile(task2_pos[0] + 64 * task2_size[0],
task2_pos[1] + 48 * (task2_size[1] - 2),
'moat_corner_south')
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
task2_pos[1] + 48 * (task2_size[1] - 2),
'moat_corner_north_flip')
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
task2_pos[1] + 48 * (task2_size[1] - 1),
'moat_vertical')
self.add_moat(task2_pos[0] + 64 * (task2_size[0] + 1),
self.add_tile(task2_pos[0] + 64 * (task2_size[0] + 1),
task2_pos[1] + 48 * (task2_size[1]),
'moat_corner_south_flip')
self.add_moat(task2_pos[0] + 64 * (task2_size[0]),
self.add_tile(task2_pos[0] + 64 * (task2_size[0]),
task2_pos[1] + 48 * (task2_size[1]),
'moat_end_horizontal')
self.add_moat(task2_pos[0] + 64 * (task2_size[0] - 2),
self.add_tile(task2_pos[0] + 64 * (task2_size[0] - 2),
task2_pos[1] + 48 * (task2_size[1]),
'moat_end_horizontal_flip')
@ -196,7 +196,7 @@ class Level1(level.Level):
### Task 3: Colour blocks
task3_pos = (64 * 3, 48 * 16)
task3_pos = (64 * 15, 48 * 18)
# Abstract "boxes", actually colour fields
boxes = logic.colourboxes.generate_colour_boxes(1, 3)
@ -210,6 +210,8 @@ class Level1(level.Level):
# 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,
'indoor%d' % random.randint(1, 6), blocking=False)
action_blocks = [block.ActionBlock(self, 64 * i + task3_pos[0],
task3_pos[1], movable=True)
@ -240,8 +242,8 @@ class Level1(level.Level):
self.objects.append(
lever.Lever(self,
task3_pos[0] - 64 * 3,
task3_pos[1] - 48 * 3,
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
@ -252,7 +254,7 @@ class Level1(level.Level):
### Task 4: Inverted bits
task4_pos = (64 * 13, 48 * 13)
task4_pos = (64 * 26, 48 * 18)
b = boulder.Boulder(self, task4_pos[0] - 64, task4_pos[1] - 48 * 3,
direction=(1, 0))
@ -309,31 +311,32 @@ class Level1(level.Level):
signal=[0, 4]))
# Moat
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4,
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 4,
'moat_corner_north')
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 3,
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 3,
'moat_vertical')
self.add_moat(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 2,
self.add_tile(task4_pos[0] - 64 * 2, task4_pos[1] - 48 * 2,
'moat_corner_south')
self.add_moat(task4_pos[0] - 64, task4_pos[1] - 48 * 2,
self.add_tile(task4_pos[0] - 64, task4_pos[1] - 48 * 2,
'moat_end_horizontal_flip')
for i in range(10):
self.add_moat(task4_pos[0] + 64 * (i - 1), task4_pos[1] - 48 * 4,
self.add_tile(task4_pos[0] + 64 * (i - 1), task4_pos[1] - 48 * 4,
'moat_horizontal')
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 4,
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 4,
'moat_corner_north_flip')
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 3,
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 3,
'moat_vertical')
self.add_moat(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 2,
self.add_tile(task4_pos[0] + 64 * 9, task4_pos[1] - 48 * 2,
'moat_corner_south_flip')
self.add_moat(task4_pos[0] + 64 * 8, task4_pos[1] - 48 * 2,
self.add_tile(task4_pos[0] + 64 * 8, task4_pos[1] - 48 * 2,
'moat_end_horizontal')
self.draw_background()
def add_moat(self, x, y, img):
def add_tile(self, x, y, img, blocking=True):
self.tiles.append(tile.Tile(self, x, y, self.imgs[img]))
self.objects.append(block.InvisBlock(self, x, y))
if blocking:
self.objects.append(block.InvisBlock(self, x, y))
def load(self):
"""Load all resources used in the level."""
@ -342,12 +345,16 @@ class Level1(level.Level):
self.imgs[o] = pygame.image.load(os.path.join(
self.graphics_dir, 'tiles', '%s.png' % o))
for o in range(1, 7):
self.imgs['indoor%d' % o] = pygame.image.load(os.path.join(
self.graphics_dir, 'tiles', 'indoor', 'ground%02d.png' % o))
l = ['block1', 'block1_lifted']
for o in l:
self.imgs[o] = pygame.image.load(os.path.join(
self.graphics_dir, 'blocks', '%s.png' % o))
l = ['hole']
l = ['hole', 'well']
for o in l:
self.imgs[o] = pygame.image.load(os.path.join(
self.graphics_dir, '%s.png' % o))