Added loader object. Game now loads on startup.

This commit is contained in:
Sakse Dalum
2012-08-10 18:54:48 +02:00
parent 91a228af72
commit d6ec520e21
5 changed files with 192 additions and 159 deletions

View File

@@ -338,79 +338,6 @@ class Level1(level.Level):
if blocking:
self.objects.append(block.InvisBlock(self, x, y))
def load(self):
"""Load all resources used in the level."""
l = ['ground1', 'ground2']
for o in l:
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', 'well']
for o in l:
self.imgs[o] = pygame.image.load(os.path.join(
self.graphics_dir, '%s.png' % o))
l = ['moat_corner_north',
'moat_corner_south',
'moat_corner_north_flip',
'moat_corner_south_flip',
'moat_end_horizontal',
'moat_horizontal',
'moat_vertical']
for o in l:
self.imgs[o] = pygame.image.load(os.path.join(
self.graphics_dir, 'moat', '%s.png' % o))
# Special treatment
self.imgs['moat_end_horizontal_flip'] = pygame.transform.flip(
self.imgs['moat_end_horizontal'], 1, 0)
# Load animations
for anim, directory in (
[('boulder_up', os.path.join('boulder', 'up')),
('boulder_down', os.path.join('boulder', 'down')),
('boulder_right', os.path.join('boulder', 'right')),
('boulder_left', os.path.join('boulder', 'right')),
('boulder_falling', os.path.join('boulder_fall')),
('lever_updown', os.path.join('lever', 'down-up')),
('lever_leftright', os.path.join('lever', 'left-right')),
('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')),]
):
self.imgs[anim] = []
# Find all image files for the given animation
anim_files = []
for root, dirs, files in os.walk(os.path.join(
self.graphics_dir, directory)):
for f in files:
if re.match(r"^.*\.(png)$", '/'.join([root, f])):
anim_files.append('/'.join([root, f]))
# Sort and load the files
for f in sorted(anim_files):
img = pygame.image.load(f)
# Special treatment:
if anim == 'arrow_left':
img = pygame.transform.flip(img, 1, 0)
self.imgs[anim].append(img)
def complete_task(self, task):
if task == 0:
return