· 8 years ago · Jan 23, 2018, 06:02 AM
1"""
2As much as Tile's "Object Layers" are useful, they sometimes just don't work well enough.
3
4For simple doors, npc spawner locations, etc, they don't snap well and the interface is
5a little jenky. not to mention, there is no spreadsheet-like view that would make
6wide changes easy to do.
7
8to get around this limitation, the script will generate a tileset that is suitable to be
9used in place of object layers.
10
11uses pygame
12
13--bitcraft
14leif.theden at gmail.com
15"""
16
17import pygame
18
19
20# tile size
21tile = (16, 16)
22
23# size in tiles
24size = (16, 16)
25
26image_fg = (0,0,0)
27image_bg = (240,240,240)
28
29# for each colorset, there will be a set of numbered tiles
30colorsets = []
31
32# white on blue
33colorsets.append(("NPC", (255,255,255), (20,0,180)))
34
35# white on red
36colorsets.append(("DOOR", (255,255,255), (180,10,20)))
37
38# white on green
39colorsets.append(("ITEM", (255,255,255), (0,120,10)))
40
41# black on light-pink
42colorsets.append(("", (0,0,0), (255,200,200)))
43
44# black on light-blue
45colorsets.append(("", (0,0,0), (200,200,255)))
46
47# black on light-green
48colorsets.append(("", (0,0,0), (200,255,200)))
49
50# black on light-grey
51colorsets.append(("", (0,0,0), (200,200,200)))
52
53pygame.font.init()
54
55font = pygame.font.Font("../resources/fonts/visitor1.ttf", 10)
56
57image = pygame.Surface((tile[0] * size[0], (tile[1] * (size[1] + 1)) * len(colorsets)))
58image.fill(image_bg)
59
60yoffset = 0
61for title, fg, bg in colorsets:
62 # display the title inside the tileset
63 title = title[:16].lower()
64 xoffset = (8 - len(title) / 2) * tile[0]
65 for x in xrange(0, len(title)):
66 txt = font.render(title[x], 1, image_fg, image_bg)
67 image.blit(txt, (xoffset + 2, yoffset + 3))
68 xoffset += size[0]
69
70 yoffset += size[1]
71
72 # do the hex code stuff
73 i = 0
74 image.fill(bg, (0, yoffset, size[0] * tile[0], size[1] * tile[1]))
75 for y in xrange(0, size[1]):
76 for x in xrange(0, size[0]):
77 txt = font.render(hex(i)[2:].upper(), 0, fg, bg)
78 image.blit(txt, (x * tile[0] + 2, y * tile[1] + yoffset + 3))
79 i += 1
80 yoffset += (size[1] * tile[1])
81
82pygame.image.save(image, "../resources/tilesets/tileset.png")