Optimisation!

This commit is contained in:
Sakse Dalum
2012-08-08 19:53:48 +02:00
parent a4df741866
commit 5c1af793df
4 changed files with 33 additions and 33 deletions

View File

@@ -24,10 +24,12 @@
A generic level.
"""
import pygame
import player
class Level(object):
def __init__(self, game, graphics_dir, paused=False):
def __init__(self, game, graphics_dir, size=(0, 0), paused=False):
self.__dict__.update(locals())
self.tiles = []
@@ -42,6 +44,11 @@ class Level(object):
self.player = player.Player(self, 0, 0)
self.objects.append(self.player)
def draw_background(self):
self.background = pygame.Surface(self.size)
for tile in self.tiles:
tile.draw(self.background)
def restart(self):
pass
@@ -58,8 +65,7 @@ class Level(object):
self.camera_y = (self.player.y - screen_size[1] / 2 - 24)
def draw(self, window):
for tile in self.tiles:
tile.draw(window)
window.blit(self.background, (0 - self.camera_x, -48 - self.camera_y))
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
obj.draw(window)