Added darkness!
This commit is contained in:
parent
28b89bc191
commit
dda8512700
|
@ -54,3 +54,17 @@ class Fadeout(object):
|
||||||
|
|
||||||
def draw(self, window):
|
def draw(self, window):
|
||||||
window.blit(self.img, (0, 0))
|
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
|
||||||
|
|
|
@ -27,6 +27,7 @@ A generic level.
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
import player
|
import player
|
||||||
|
import fadeout
|
||||||
|
|
||||||
class Level(object):
|
class Level(object):
|
||||||
def __init__(self, game, graphics_dir, size=(0, 0), paused=False):
|
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.player = player.Player(self, 0, 0)
|
||||||
self.objects.append(self.player)
|
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):
|
def draw_background(self):
|
||||||
self.background = pygame.Surface(self.size)
|
self.background = pygame.Surface(self.size)
|
||||||
for tile in self.tiles:
|
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)):
|
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
|
||||||
obj.draw(window)
|
obj.draw(window)
|
||||||
|
|
||||||
|
self.darkness.draw(window)
|
||||||
|
|
|
@ -49,6 +49,8 @@ class Level1(level.Level):
|
||||||
|
|
||||||
self.dimensions = 50, 50
|
self.dimensions = 50, 50
|
||||||
|
|
||||||
|
self.set_darkness(0.5)
|
||||||
|
|
||||||
for i in range(self.dimensions[0]):
|
for i in range(self.dimensions[0]):
|
||||||
for j in range(self.dimensions[1]):
|
for j in range(self.dimensions[1]):
|
||||||
self.tiles.append(
|
self.tiles.append(
|
||||||
|
|
Loading…
Reference in New Issue