-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile_handler.py
More file actions
60 lines (52 loc) · 1.95 KB
/
tile_handler.py
File metadata and controls
60 lines (52 loc) · 1.95 KB
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
'''
Tile loader from the PYR_PG Project
Copyright (C) 2024-2025 Spyro24
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import pygame as p
def load_tiles(folder, config, *font, mode="new"):
'''
To use the font you have to make a Text obj from the pyr_pg libary
The modes are "new" for tile tables and "legacy" if you have
'''
tmp = config["size"].split("x")
tmx = int(tmp[0])
tmy = int(tmp[1])
draw_font = False
tile_maps = []
tiles = []
if len(font) > 0:
draw_font = True
try:
n = 0
if mode == "new":
while True:
if draw_font:
pass # ("Loading Tilemap str(n))
p.display.flip()
tile_maps.append(p.image.load(folder + "/" + str(n) + ".png"))
n += 1
elif mode == "single":
tile_maps.append(p.image.load(folder))
except:
pass
max_tile_maps = len(tile_maps)
for tmap in range(max_tile_maps):
cur_tmap = tile_maps[tmap]
tw, th = cur_tmap.get_size()
sx, sy = tw / tmx, th / tmy
for h in range(tmy):
for w in range(tmx):
tmp = p.Surface((sy, sy), flags=p.SRCALPHA)
tmp.blit(cur_tmap,(0,0),(sx * w, sy * h, sx, sy))
tiles.append(tmp)
return tiles