-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilitarios.py
44 lines (34 loc) · 1.21 KB
/
utilitarios.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
from csv import reader
from configuracoes import tile_size
from os import walk
import pygame
def import_folder(path):
surface_list = []
for _, __, image_files in walk(path):
for image in image_files:
full_path = path + '/' + image
image_surf = pygame.image.load(full_path).convert_alpha()
surface_list.append(image_surf)
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_graphics(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