-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.py
40 lines (32 loc) · 1.17 KB
/
support.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
from os import walk
import pygame
from csv import reader
from settings import tile_size
def import_folder(path):
surface_list = []
for _, __, img_files in walk(path):
for image in img_files:
full_path = path + "/" + image
image_surface = pygame.image.load(full_path).convert_alpha()
surface_list.append(image_surface)
return surface_list
def import_csv_layout(path):
terrain_map = []
with open(path) as map:
level = reader(map, delimiter=",")
for row in level:
terrain_map.append(list(row))
return terrain_map
def import_cut_graphic(path):
surface = pygame.image.load(path).convert_alpha()
tile_num_x = int(surface.get_size()[0] / tile_size)
tile_num_y = int(surface.get_size()[1] / tile_size)
cut_tiles = []
for row in range(tile_num_y):
for col in range(tile_num_x):
x = col * tile_size
y = row * tile_size
new_surf = pygame.Surface((tile_size, tile_size), flags=pygame.SRCALPHA)
new_surf.blit(surface, (0, 0), pygame.Rect(x, y, tile_size, tile_size))
cut_tiles.append(new_surf)
return cut_tiles