Added a rolling boulder.

This commit is contained in:
Sakse Dalum
2012-08-08 16:46:26 +02:00
parent 868df222bf
commit 12b849c668
2 changed files with 92 additions and 0 deletions

View File

@@ -27,11 +27,13 @@ The first level.
import os
import pygame
import random
import re
import level
import player
import tile
import block
import boulder
class Level1(level.Level):
def __init__(self, game, graphics_dir, paused=False):
@@ -50,6 +52,8 @@ class Level1(level.Level):
self.imgs['block1'],
movable=True))
self.objects.append(boulder.Boulder(self, 64, 48))
def load(self):
"""Load all resources used in the level."""
tile_list = ['ground1', 'ground2']
@@ -63,5 +67,29 @@ class Level1(level.Level):
self.imgs[block] = pygame.image.load(os.path.join(
self.graphics_dir, 'blocks', '%s.png' % block))
# 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'))]
):
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)
self.imgs[anim].append(img)
def restart(self):
self.player.reset_pos()