Optimisation!
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user