Blocks, depth, holding and releasing objects, etc.

This commit is contained in:
Sakse Dalum
2012-08-07 23:21:44 +02:00
parent 90a11e9ed3
commit 2ba27dff1f
6 changed files with 135 additions and 17 deletions

View File

@@ -26,27 +26,40 @@ The first level.
import os
import pygame
import random
import level
import player
import tile
import block
class Level1(level.Level):
def __init__(self, graphics_dir):
self.__dict__.update(locals())
self.player = player.Player(200, 200)
self.player = player.Player(self, 5*64, 5*48)
self.dimensions = 20, 20
self.tiles = []
self.objects = []
self.imgs = {}
self.load()
for i in range(0, 10):
for j in range(0, 10):
for i in range(self.dimensions[0]):
for j in range(self.dimensions[1]):
self.tiles.append(
tile.Tile(i*64, j*48,
self.imgs['ground%d' % (((i + j) % 2) + 1)]))
tile.Tile(self, i*64, j*48, self.imgs['ground%d'
% (((i + j) % 2) + 1)]))
self.objects.append(self.player)
for i in range(100):
self.objects.append(block.Block(self, random.randint(0, 20)*64,
random.randint(0, 20)*48,
self.imgs['block1'],
movable=True))
def load(self):
"""Load all resources used in the level."""
@@ -56,11 +69,18 @@ class Level1(level.Level):
self.imgs[tile] = pygame.image.load(os.path.join(
self.graphics_dir, 'tiles', '%s.png' % tile))
block_list = ['block1']
for block in block_list:
self.imgs[block] = pygame.image.load(os.path.join(
self.graphics_dir, 'blocks', '%s.png' % block))
def update(self, e, t, dt):
self.player.update(e, t, dt)
for obj in self.objects:
obj.update(e, t, dt)
def draw(self, window):
for tile in self.tiles:
tile.draw(window)
self.player.draw(window)
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
obj.draw(window)