-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_display.py
60 lines (43 loc) · 1.85 KB
/
tile_display.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Contains the display functions for tiles"""
import pygame
from global_vars import *
def display_tiles(tile_map: dict[int,tuple[tuple[int,int],int,pygame.Color]]):
if tile_map != {}:
for tile in tile_map.values():
display_tile(tile,create_tile_image(tile))
def create_tile_image(tile: tuple[tuple[int, int], int, pygame.Color]) -> pygame.Surface:
tile_type = tile[1]
image = images[tile_type]
# Scaling
image = pygame.transform.scale_by(image,scale)
return image
def display_tile(tile: tuple[tuple[int, int], int, pygame.Color], image: pygame.Surface):
rect = image.get_rect(topleft = tile[0])
screen.blit(image,rect)
def display_tile_with_given_color(tile: tuple[tuple[int, int], int, pygame.Color], color: pygame.Color):
# Image
image = create_tile_image(tile)
# Coloring
color_tile_given_color(image,color)
# Display
display_tile(tile,image)
def color_tile_given_color(image: pygame.Surface, color: pygame.Color):
# Coloring
surf = pygame.Surface(image.get_rect().size, pygame.SRCALPHA)
surf.fill(color)
image.blit(surf, (0, 0), None, pygame.BLEND_SUB)
# BLEND_ADD will move it towards that color, BLEND_SUB will move towards removing the image altogether
# From brief testing, BLEND_ADD is for lightening and BLEND_SUB is for darkening
def display_tiles_with_color(tile_map: dict[int,tuple[tuple[int,int],int,pygame.Color]]):
if tile_map != {}:
for tile in tile_map.values():
display_tile_with_color(tile)
def display_tile_with_color(tile: tuple[tuple[int, int], int, pygame.Color]):
# Image
image = create_tile_image(tile)
# Coloring
color_tile(tile,image)
# Display
display_tile(tile,image)
def color_tile(tile: tuple[tuple[int, int], int, pygame.Color], image: pygame.Surface):
color_tile_given_color(image, tile[2])