Browse code
updates to deal with fonts and field of view
Ed L authored on 27/06/2013 23:35:49
Showing 3 changed files
Showing 3 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,25 @@ |
1 |
+#!/usr/bin/python |
|
2 |
+# |
|
3 |
+# Edward Langley (C) 2013 |
|
4 |
+# |
|
5 |
+# For rotating Dwarf Fortress tilesets to workaround TCOD limitations. |
|
6 |
+# These tilesets also need to have the pink background removed. (I think) |
|
7 |
+# |
|
8 |
+import Image |
|
9 |
+import numpy |
|
10 |
+import argparse |
|
11 |
+ |
|
12 |
+parser = argparse.ArgumentParser() |
|
13 |
+parser.add_argument('fro') |
|
14 |
+parser.add_argument('to') |
|
15 |
+args = parser.parse_args() |
|
16 |
+ |
|
17 |
+file = Image.open(args.fro) |
|
18 |
+data = numpy.asarray(file) |
|
19 |
+ |
|
20 |
+tiles = [numpy.split(col,16,1) for col in numpy.split(data,16)] |
|
21 |
+tiles = zip(*tiles) |
|
22 |
+tiles = [numpy.concatenate(x,1) for x in tiles] |
|
23 |
+tiles = numpy.concatenate(tiles) |
|
24 |
+Image.fromarray(tiles).save(args.to) |
|
25 |
+ |
... | ... |
@@ -703,6 +703,7 @@ def console_get_height(con): |
703 | 703 |
return _lib.TCOD_console_get_height(con) |
704 | 704 |
|
705 | 705 |
def console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL, nb_char_horiz=0, nb_char_vertic=0): |
706 |
+ print 'flags -->', flags, FONT_LAYOUT_TCOD|FONT_TYPE_GREYSCALE |
|
706 | 707 |
_lib.TCOD_console_set_custom_font(c_char_p(fontFile), flags, nb_char_horiz, nb_char_vertic) |
707 | 708 |
|
708 | 709 |
def console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY): |
... | ... |
@@ -38,15 +38,15 @@ import time |
38 | 38 |
inst = lambda a:a() |
39 | 39 |
@inst |
40 | 40 |
class Settings: |
41 |
- SCREEN_WIDTH = 75 |
|
42 |
- SCREEN_HEIGHT = 40 |
|
41 |
+ SCREEN_WIDTH = 37 |
|
42 |
+ SCREEN_HEIGHT = 20 |
|
43 | 43 |
DISPLAY_HEIGHT = SCREEN_HEIGHT+2 |
44 | 44 |
LIMIT_FPS = 20 |
45 | 45 |
BASE = 8 |
46 | 46 |
LEVELS = 3 |
47 | 47 |
|
48 | 48 |
libtcod.console_init_root(Settings.SCREEN_WIDTH, Settings.DISPLAY_HEIGHT, 'Mapping', False) |
49 |
-libtcod.console_set_custom_font("terminal.png",libtcod.FONT_LAYOUT_ASCII_INROW) |
|
49 |
+libtcod.console_set_custom_font("terminal.png",libtcod.FONT_LAYOUT_ASCII_INROW|libtcod.FONT_TYPE_GREYSCALE) |
|
50 | 50 |
#libtcod.console_set_fullscreen(True) |
51 | 51 |
con = libtcod.console_new(Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT) |
52 | 52 |
blank = libtcod.console_new(Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT) |
... | ... |
@@ -55,7 +55,7 @@ blank = libtcod.console_new(Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT) |
55 | 55 |
|
56 | 56 |
|
57 | 57 |
message_con = libtcod.console_new(Settings.SCREEN_WIDTH, 2) |
58 |
-#libtcod.console_set_default_background(message_con,libtcod.red) |
|
58 |
+libtcod.console_set_default_background(message_con,libtcod.red) |
|
59 | 59 |
#libtcod.console_set_default_background(blank,libtcod.red) |
60 | 60 |
|
61 | 61 |
|
... | ... |
@@ -68,13 +68,13 @@ mapping = {} |
68 | 68 |
|
69 | 69 |
colors = { |
70 | 70 |
':': colorsys.rgb_to_hsv(0.0,0.0,1.0), |
71 |
- chr(241): colorsys.rgb_to_hsv(0.0,1.0,0.0), |
|
71 |
+ chr(5): colorsys.rgb_to_hsv(0.0,0.5,0.0), |
|
72 | 72 |
'*': colorsys.rgb_to_hsv(1.0,1.0,0.0), |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
df = 1/40.0 |
76 | 76 |
for x in range(-20,20): |
77 |
- char = random.choice(['.','.','.','*','*',';',':','"',"'",chr(241),'`']) |
|
77 |
+ char = random.choice(['.','.','.','*','*',';',':','"',"'",chr(5),'`']) |
|
78 | 78 |
if char in colors: |
79 | 79 |
h,s,v = colors[char] |
80 | 80 |
print s,v |
... | ... |
@@ -96,7 +96,7 @@ names = { |
96 | 96 |
':': ('pond',True,True), |
97 | 97 |
'"': ('heath',True,False), |
98 | 98 |
"'": ('marsh',1-0.15,False), |
99 |
- chr(241): ('forest',False,True), |
|
99 |
+ chr(5): ('forest',False,True), |
|
100 | 100 |
'`': ('copse',1-0.5,False), |
101 | 101 |
} |
102 | 102 |
|
... | ... |
@@ -131,7 +131,7 @@ class LevelMap(object): |
131 | 131 |
|
132 | 132 |
def get_color(self, level,x,y, color): |
133 | 133 |
fovmap = self.get_fovmap(level) |
134 |
- if libtcod.map_is_in_fov(fovmap, x,y): |
|
134 |
+ if libtcod.map_is_in_fov(fovmap, x,y) and libtcod.map_is_walkable(fovmap,x,y): |
|
135 | 135 |
#print 'cell in fov', level,x,y, libtcod.map_get_width(fovmap), libtcod.map_get_height(fovmap) |
136 | 136 |
color = [x/255 for x in color] |
137 | 137 |
h,s,v = colorsys.rgb_to_hsv(*color) |
... | ... |
@@ -156,6 +156,7 @@ lm.calculate_level(level) |
156 | 156 |
libtcod.console_set_default_foreground(message_con, libtcod.white) |
157 | 157 |
for c in [con,message_con]: |
158 | 158 |
libtcod.console_set_default_foreground(c, libtcod.white) |
159 |
+ libtcod.console_clear(c) |
|
159 | 160 |
|
160 | 161 |
offset_x, offset_y = 0,0 |
161 | 162 |
MAP_Y,MAP_X = len(mp.data[level]), len(mp.data[level][0]) |
... | ... |
@@ -167,11 +168,11 @@ ak=0 |
167 | 168 |
while not libtcod.console_is_window_closed(): |
168 | 169 |
t0 = time.time() |
169 | 170 |
|
170 |
- if player_x - offset_x >= Settings.SCREEN_WIDTH-10: offset_x += 20 |
|
171 |
- elif player_x - offset_x < 10: offset_x -= 20 |
|
171 |
+ if player_x - offset_x >= Settings.SCREEN_WIDTH-5: offset_x += 5 |
|
172 |
+ elif player_x - offset_x < 5: offset_x -= 5 |
|
172 | 173 |
|
173 |
- if player_y - offset_y >= Settings.SCREEN_HEIGHT-10: offset_y += 20 |
|
174 |
- elif player_y - offset_y < 10: offset_y -= 20 |
|
174 |
+ if player_y - offset_y >= Settings.SCREEN_HEIGHT-5: offset_y += 5 |
|
175 |
+ elif player_y - offset_y < 5: offset_y -= 5 |
|
175 | 176 |
|
176 | 177 |
offset_y = min(offset_y,MAP_Y-Settings.SCREEN_HEIGHT) |
177 | 178 |
offset_y = max(offset_y,0) |
... | ... |
@@ -181,6 +182,7 @@ while not libtcod.console_is_window_closed(): |
181 | 182 |
|
182 | 183 |
t1 = time.time() |
183 | 184 |
lm.comp_fov(level, player_x, player_y,10) |
185 |
+ player_screen_pos = player_x-offset_x,player_y-offset_y |
|
184 | 186 |
for y,row in enumerate(mp.data[level][offset_y:offset_y+Settings.SCREEN_HEIGHT]): |
185 | 187 |
for x,cell in enumerate(row[offset_x:offset_x+Settings.SCREEN_WIDTH]): |
186 | 188 |
color,char,bgcolor = mapping.get(cell, (libtcod.Color(0,0,0),' ',libtcod.Color(0,0,0))) |
... | ... |
@@ -188,15 +190,17 @@ while not libtcod.console_is_window_closed(): |
188 | 190 |
color = lm.get_color(level, x+offset_x, y+offset_y, color) |
189 | 191 |
bgcolor = lm.get_color(level, x+offset_x, y+offset_y, bgcolor) |
190 | 192 |
|
193 |
+ if (x,y) == player_screen_pos: |
|
194 |
+ #color = libtcod.Color(128,128,128) |
|
195 |
+ char = '\x01' |
|
196 |
+ |
|
197 |
+ |
|
191 | 198 |
libtcod.console_set_char_foreground(con, x,y, color) |
192 | 199 |
libtcod.console_set_char_background(con, x,y, bgcolor) |
193 | 200 |
libtcod.console_set_char(con,x,y,char) |
194 | 201 |
|
195 | 202 |
print 'draw loop:', time.time()-t1 |
196 | 203 |
|
197 |
- libtcod.console_set_char_foreground(con, player_x-offset_x,player_y-offset_y, libtcod.white) |
|
198 |
- libtcod.console_set_char(con,player_x-offset_x,player_y-offset_y,'\x01') |
|
199 |
- |
|
200 | 204 |
libtcod.console_print(message_con, 0,1,lm.get_tile_type(level, player_x,player_y)[0]) |
201 | 205 |
libtcod.console_blit(message_con, 0,0, Settings.SCREEN_WIDTH,2, 0, 0,Settings.DISPLAY_HEIGHT-2) |
202 | 206 |
|
... | ... |
@@ -261,7 +265,7 @@ while not libtcod.console_is_window_closed(): |
261 | 265 |
nx,ny = libtcod.line_step() |
262 | 266 |
while None not in {nx,ny}: |
263 | 267 |
if not lm.get_walkable(level,nx,ny): |
264 |
- libtcod.console_print(message_con, 0,0,'You can\'t walk through a %s' % lm.get_tile_type(level, nx,ny)[0]) |
|
268 |
+ libtcod.console_print(message_con, 0,0,'You cannot walk through a %s' % lm.get_tile_type(level, nx,ny)[0]) |
|
265 | 269 |
break |
266 | 270 |
print nx,ny |
267 | 271 |
player_x,player_y = nx,ny |