Added darkness!

This commit is contained in:
Sakse Dalum 2012-08-09 17:18:44 +02:00
parent 28b89bc191
commit dda8512700
3 changed files with 24 additions and 0 deletions

View File

@ -54,3 +54,17 @@ class Fadeout(object):
def draw(self, window):
window.blit(self.img, (0, 0))
class Darkness(Fadeout):
def __init__(self, game, darkness):
self.__dict__.update(locals())
self.set_darkness(darkness)
def set_darkness(self, darkness):
self.darkness = darkness
self.img = pygame.Surface(self.game.window.get_size())
self.img.set_alpha(int(darkness * 255))
self.img.fill((0, 0, 0))
def update(self, *xs):
pass

View File

@ -27,6 +27,7 @@ A generic level.
import pygame
import player
import fadeout
class Level(object):
def __init__(self, game, graphics_dir, size=(0, 0), paused=False):
@ -44,6 +45,11 @@ class Level(object):
self.player = player.Player(self, 0, 0)
self.objects.append(self.player)
self.darkness = fadeout.Darkness(self.game, 0)
def set_darkness(self, darkness):
self.darkness.set_darkness(darkness)
def draw_background(self):
self.background = pygame.Surface(self.size)
for tile in self.tiles:
@ -69,3 +75,5 @@ class Level(object):
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
obj.draw(window)
self.darkness.draw(window)

View File

@ -49,6 +49,8 @@ class Level1(level.Level):
self.dimensions = 50, 50
self.set_darkness(0.5)
for i in range(self.dimensions[0]):
for j in range(self.dimensions[1]):
self.tiles.append(