/
light.py
38 lines (27 loc) · 998 Bytes
/
light.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from typing import Union
import pygame
from pygame.surface import Surface, SurfaceType
from mandaw import *
class Light:
light_mask: Union[Surface, SurfaceType]
light_filter: Surface
def __init__(self, window: Mandaw, mask_img):
self.window = window
self.mask = mask_img
def light_init(self, pos):
self.pos = pos
self.light_mask = pygame.image.load(self.mask)
self.light_filter = pygame.surface.Surface((self.window.width, self.window.height))
self.light_filter.fill(pygame.color.Color("Gray"))
self.light_filter.blit(self.light_mask, pos)
def draw(self):
self.window.window.blit(self.light_filter, (0, 0), special_flags=pygame.BLEND_RGBA_SUB)
if __name__ == '__main__':
from mandaw import *
mandaw = Mandaw(bg_color="red")
light = Light(mandaw, "assets/circle.png")
light.light_init((100, 100))
@mandaw.draw
def draw():
light.draw()
mandaw.loop()