libtcod 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/bin/libtcod-ruby-test +344 -0
- data/bin/oryx_tiles.png +0 -0
- data/examples/python_tutorial_part_1/main.rb +60 -58
- data/examples/tile_demo/tile_demo.rb +4 -1
- data/lib/libtcod.rb +1 -0
- data/lib/libtcod/bindings.rb +10 -6
- data/lib/libtcod/console.rb +93 -80
- data/lib/libtcod/map.rb +108 -0
- data/lib/libtcod/version.rb +1 -1
- metadata +8 -3
data/README.md
CHANGED
@@ -0,0 +1,344 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# TCOD ruby tutorial with tiles
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'libtcod'
|
8
|
+
|
9
|
+
#actual size of the window
|
10
|
+
SCREEN_WIDTH = 50
|
11
|
+
SCREEN_HEIGHT = 37
|
12
|
+
|
13
|
+
#size of the $map
|
14
|
+
MAP_WIDTH = SCREEN_WIDTH
|
15
|
+
MAP_HEIGHT = SCREEN_HEIGHT
|
16
|
+
|
17
|
+
#parameters for dungeon generator
|
18
|
+
ROOM_MAX_SIZE = 10
|
19
|
+
ROOM_MIN_SIZE = 6
|
20
|
+
MAX_ROOMS = 30
|
21
|
+
|
22
|
+
FOV_ALGO = 0 #default FOV algorithm
|
23
|
+
FOV_LIGHT_WALLS = true #light walls or not
|
24
|
+
TORCH_RADIUS = 10
|
25
|
+
|
26
|
+
LIMIT_FPS = 20 #20 frames-per-second maximum
|
27
|
+
|
28
|
+
GROUND_COLOR = TCOD::Color.rgb(77, 60, 41)
|
29
|
+
|
30
|
+
WALL_TILE = 256 #first tile in the first row of tiles
|
31
|
+
MAGE_TILE = 256 + 32 #first tile in the 2nd row of tiles
|
32
|
+
SKELETON_TILE = 256 + 32 + 1 #2nd tile in the 2nd row of tiles
|
33
|
+
|
34
|
+
class Tile
|
35
|
+
attr_accessor :blocked, :explored, :block_sight
|
36
|
+
|
37
|
+
#a tile of the $map and its properties
|
38
|
+
def initialize(blocked, block_sight = nil)
|
39
|
+
@blocked = blocked
|
40
|
+
|
41
|
+
#all tiles start unexplored
|
42
|
+
@explored = false
|
43
|
+
|
44
|
+
#by default, if a tile.equal? blocked, it also blocks sight
|
45
|
+
if block_sight.nil?
|
46
|
+
@block_sight = blocked
|
47
|
+
else
|
48
|
+
@block_sight = block_sight
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Rect
|
54
|
+
attr_accessor :x1, :y1, :x2, :y2
|
55
|
+
#a rectangle on the $map. used to characterize a room.
|
56
|
+
def initialize (x, y, w, h)
|
57
|
+
@x1 = x
|
58
|
+
@y1 = y
|
59
|
+
@x2 = x + w
|
60
|
+
@y2 = y + h
|
61
|
+
end
|
62
|
+
|
63
|
+
def center
|
64
|
+
center_x = (@x1 + @x2) / 2
|
65
|
+
center_y = (@y1 + @y2) / 2
|
66
|
+
[center_x, center_y]
|
67
|
+
end
|
68
|
+
|
69
|
+
def intersect (other)
|
70
|
+
#returns true if this rectangle intersects with another one
|
71
|
+
return (@x1 <= other.x2 and @x2 >= other.x1 and
|
72
|
+
@y1 <= other.y2 and @y2 >= other.y1)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Obj
|
77
|
+
attr_accessor :x, :y, :char, :color
|
78
|
+
|
79
|
+
#this.equal? a generic object: the $player, a monster, an item, the stairs...
|
80
|
+
#it's always represented by a character on screen.
|
81
|
+
def initialize (x, y, char, color)
|
82
|
+
@x = x
|
83
|
+
@y = y
|
84
|
+
@char = char
|
85
|
+
@color = color
|
86
|
+
end
|
87
|
+
|
88
|
+
def move (dx, dy)
|
89
|
+
#move by the given amount, if the destination.equal? not blocked
|
90
|
+
if not $map[@x + dx][@y + dy].blocked
|
91
|
+
@x += dx
|
92
|
+
@y += dy
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def draw
|
97
|
+
#only show if it's visible to the $player
|
98
|
+
if TCOD.map_is_in_fov($fov_map, @x, @y)
|
99
|
+
#set the color and then draw the character that represents this object at its position
|
100
|
+
TCOD.console_set_default_foreground($con, @color)
|
101
|
+
TCOD.console_put_char($con, @x, @y, @char.ord, TCOD::BKGND_NONE)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def clear
|
106
|
+
#erase the character that represents this object
|
107
|
+
TCOD.console_put_char($con, @x, @y, ' '.ord, TCOD::BKGND_NONE)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_room(room)
|
112
|
+
#go through the tiles in the rectangle and make them passable
|
113
|
+
p "#{room.x1}, #{room.x2}, #{room.y1}, #{room.y2}"
|
114
|
+
(room.x1 + 1 ... room.x2).each do |x|
|
115
|
+
(room.y1 + 1 ... room.y2).each do |y|
|
116
|
+
$map[x][y].blocked = false
|
117
|
+
$map[x][y].block_sight = false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def create_h_tunnel(x1, x2, y)
|
123
|
+
#horizontal tunnel. min() and max() are used in case x1>x2
|
124
|
+
([x1,x2].min ... [x1,x2].max + 1).each do |x|
|
125
|
+
$map[x][y].blocked = false
|
126
|
+
$map[x][y].block_sight = false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def create_v_tunnel(y1, y2, x)
|
131
|
+
#vertical tunnel
|
132
|
+
([y1,y2].min ... [y1,y2].max + 1).each do |y|
|
133
|
+
$map[x][y].blocked = false
|
134
|
+
$map[x][y].block_sight = false
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def make_map
|
139
|
+
# fill $map with "blocked" tiles
|
140
|
+
#$map = [[0]*MAP_HEIGHT]*MAP_WIDTH
|
141
|
+
$map = []
|
142
|
+
0.upto(MAP_WIDTH-1) do |x|
|
143
|
+
$map.push([])
|
144
|
+
0.upto(MAP_HEIGHT-1) do |y|
|
145
|
+
$map[x].push(Tile.new(true))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
rooms = []
|
150
|
+
num_rooms = 0
|
151
|
+
|
152
|
+
0.upto(MAX_ROOMS) do |r|
|
153
|
+
#random width and height
|
154
|
+
w = TCOD.random_get_int(nil, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
|
155
|
+
h = TCOD.random_get_int(nil, ROOM_MIN_SIZE, ROOM_MAX_SIZE)
|
156
|
+
#random position without going out of the boundaries of the $map
|
157
|
+
x = TCOD.random_get_int(nil, 0, MAP_WIDTH - w - 1)
|
158
|
+
y = TCOD.random_get_int(nil, 0, MAP_HEIGHT - h - 1)
|
159
|
+
|
160
|
+
|
161
|
+
#"Rect" class makes rectangles easier to work with
|
162
|
+
new_room = Rect.new(x, y, w, h)
|
163
|
+
|
164
|
+
#run through the other rooms and see if they intersect with this one
|
165
|
+
failed = false
|
166
|
+
rooms.each do |other_room|
|
167
|
+
if new_room.intersect(other_room)
|
168
|
+
failed = true
|
169
|
+
break
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
unless failed
|
174
|
+
#this means there are no intersections, so this room.equal? valid
|
175
|
+
|
176
|
+
#"paint" it to the $map's tiles
|
177
|
+
create_room(new_room)
|
178
|
+
|
179
|
+
#center coordinates of new room, will be useful later
|
180
|
+
new_x, new_y = new_room.center
|
181
|
+
|
182
|
+
|
183
|
+
#there's a 30% chance of placing a skeleton slightly off to the center of this room
|
184
|
+
if TCOD.random_get_int(nil, 1, 100) <= 30
|
185
|
+
skeleton = Obj.new(new_x + 1, new_y, SKELETON_TILE, TCOD::Color::LIGHT_YELLOW)
|
186
|
+
$objects.push(skeleton)
|
187
|
+
end
|
188
|
+
|
189
|
+
if num_rooms == 0
|
190
|
+
#this.equal? the first room, where the $player starts at
|
191
|
+
$player.x = new_x
|
192
|
+
$player.y = new_y
|
193
|
+
else
|
194
|
+
#all rooms after the first
|
195
|
+
#connect it to the previous room with a tunnel
|
196
|
+
|
197
|
+
#center coordinates of previous room
|
198
|
+
prev_x, prev_y = rooms[num_rooms-1].center()
|
199
|
+
|
200
|
+
#draw a coin(random number that.equal? either 0 or 1)
|
201
|
+
if TCOD.random_get_int(nil, 0, 1) == 1
|
202
|
+
#first move horizontally, then vertically
|
203
|
+
create_h_tunnel(prev_x, new_x, prev_y)
|
204
|
+
create_v_tunnel(prev_y, new_y, new_x)
|
205
|
+
else
|
206
|
+
#first move vertically, then horizontally
|
207
|
+
create_v_tunnel(prev_y, new_y, prev_x)
|
208
|
+
create_h_tunnel(prev_x, new_x, new_y)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
#finally, append the new room to the list
|
213
|
+
rooms.push(new_room)
|
214
|
+
num_rooms += 1
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
def render_all
|
221
|
+
if $fov_recompute
|
222
|
+
#recompute FOV if needed(the $player moved or something)
|
223
|
+
$fov_recompute = false
|
224
|
+
TCOD.map_compute_fov($fov_map, $player.x, $player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
|
225
|
+
|
226
|
+
#go through all tiles, and set their background color according to the FOV
|
227
|
+
0.upto(MAP_HEIGHT-1) do |y|
|
228
|
+
0.upto(MAP_WIDTH-1) do |x|
|
229
|
+
visible = TCOD.map_is_in_fov($fov_map, x, y)
|
230
|
+
wall = $map[x][y].block_sight
|
231
|
+
if not visible
|
232
|
+
#if it's not visible right now, the $player can only see it if it's explored
|
233
|
+
if $map[x][y].explored
|
234
|
+
if wall
|
235
|
+
TCOD.console_put_char_ex($con, x, y, WALL_TILE.ord, TCOD::Color::WHITE * 0.5, TCOD::Color::BLACK)
|
236
|
+
else
|
237
|
+
TCOD.console_put_char_ex($con, x, y, ' '.ord, TCOD::Color::BLACK, GROUND_COLOR * 0.5)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
else
|
241
|
+
#it's visible
|
242
|
+
if wall
|
243
|
+
TCOD.console_put_char_ex($con, x, y, WALL_TILE.ord, TCOD::Color::WHITE, TCOD::Color::BLACK)
|
244
|
+
else
|
245
|
+
TCOD.console_put_char_ex($con, x, y, ' '.ord, TCOD::Color::BLACK, GROUND_COLOR)
|
246
|
+
end
|
247
|
+
#since it's visible, explore it
|
248
|
+
$map[x][y].explored = true
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
#draw all objects in the list
|
255
|
+
$objects.each do |object|
|
256
|
+
object.draw()
|
257
|
+
end
|
258
|
+
|
259
|
+
#blit the contents of "con" to the root console
|
260
|
+
TCOD.console_blit($con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, nil, 0, 0, 1.0, 1.0)
|
261
|
+
end
|
262
|
+
|
263
|
+
def handle_keys
|
264
|
+
#key = TCOD.console_check_for_keypress() #real-time
|
265
|
+
key = TCOD.console_wait_for_keypress(true) #turn-based
|
266
|
+
|
267
|
+
if key.vk == TCOD::KEY_ENTER and key.lalt
|
268
|
+
#Alt+Enter: toggle fullscreen
|
269
|
+
TCOD.console_set_fullscreen(!TCOD.console_is_fullscreen)
|
270
|
+
elsif key.vk == TCOD::KEY_ESCAPE
|
271
|
+
return true #exit game
|
272
|
+
end
|
273
|
+
|
274
|
+
#movement keys
|
275
|
+
if TCOD.console_is_key_pressed(TCOD::KEY_UP)
|
276
|
+
$player.move(0, -1)
|
277
|
+
$fov_recompute = true
|
278
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_DOWN)
|
279
|
+
$player.move(0, 1)
|
280
|
+
$fov_recompute = true
|
281
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_LEFT)
|
282
|
+
$player.move(-1, 0)
|
283
|
+
$fov_recompute = true
|
284
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_RIGHT)
|
285
|
+
$player.move(1, 0)
|
286
|
+
$fov_recompute = true
|
287
|
+
end
|
288
|
+
false
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
#############################################
|
293
|
+
# Initialization & Main Loop
|
294
|
+
#############################################
|
295
|
+
|
296
|
+
#note that we must specify the number of tiles on the font, which was enlarged a bit
|
297
|
+
TCOD.console_set_custom_font(File.join(File.dirname(__FILE__), 'oryx_tiles.png'), TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 32, 12)
|
298
|
+
TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/TCOD tutorial', false, TCOD::RENDERER_SDL)
|
299
|
+
TCOD.sys_set_fps(LIMIT_FPS)
|
300
|
+
$con = TCOD.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
|
301
|
+
|
302
|
+
|
303
|
+
TCOD.console_map_ascii_codes_to_font(256, 32, 0, 5) #$map all characters in 1st row
|
304
|
+
TCOD.console_map_ascii_codes_to_font(256+32, 32, 0, 6) #$map all characters in 2nd row
|
305
|
+
|
306
|
+
|
307
|
+
#create object representing the $player
|
308
|
+
$player = Obj.new(0, 0, MAGE_TILE, TCOD::Color::WHITE)
|
309
|
+
|
310
|
+
#the list of objects with just the $player
|
311
|
+
$objects = [$player]
|
312
|
+
|
313
|
+
#generate $map(at this point it's not drawn to the screen)
|
314
|
+
make_map()
|
315
|
+
|
316
|
+
#create the FOV $map, according to the generated $map
|
317
|
+
$fov_map = TCOD.map_new(MAP_WIDTH, MAP_HEIGHT)
|
318
|
+
0.upto(MAP_HEIGHT-1) do |y|
|
319
|
+
0.upto(MAP_WIDTH-1) do |x|
|
320
|
+
TCOD.map_set_properties($fov_map, x, y, !$map[x][y].block_sight, !$map[x][y].blocked)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
$fov_recompute = true
|
326
|
+
|
327
|
+
trap('SIGINT') { exit! }
|
328
|
+
|
329
|
+
until TCOD.console_is_window_closed()
|
330
|
+
|
331
|
+
#render the screen
|
332
|
+
render_all()
|
333
|
+
|
334
|
+
TCOD.console_flush()
|
335
|
+
|
336
|
+
#erase all objects at their old locations, before they move
|
337
|
+
$objects.each do |object|
|
338
|
+
object.clear()
|
339
|
+
end
|
340
|
+
|
341
|
+
#handle keys and exit game if needed
|
342
|
+
will_exit = handle_keys()
|
343
|
+
break if will_exit
|
344
|
+
end
|
data/bin/oryx_tiles.png
ADDED
Binary file
|
@@ -1,58 +1,60 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'libtcod'
|
4
|
-
|
5
|
-
#actual size of the window
|
6
|
-
SCREEN_WIDTH = 80
|
7
|
-
SCREEN_HEIGHT = 50
|
8
|
-
|
9
|
-
LIMIT_FPS = 20 #20 frames-per-second maximum
|
10
|
-
|
11
|
-
def handle_keys
|
12
|
-
#key = TCOD.console_check_for_keypress() #real-time
|
13
|
-
key = TCOD.console_wait_for_keypress(true) #turn-based
|
14
|
-
|
15
|
-
if key.vk == TCOD::KEY_ENTER && key.lalt
|
16
|
-
#Alt+Enter: toggle fullscreen
|
17
|
-
TCOD.console_set_fullscreen(!TCOD.console_is_fullscreen())
|
18
|
-
elsif key.vk == TCOD::KEY_ESCAPE
|
19
|
-
return true #exit game
|
20
|
-
end
|
21
|
-
|
22
|
-
#movement keys
|
23
|
-
if TCOD.console_is_key_pressed(TCOD::KEY_UP)
|
24
|
-
$playery -= 1
|
25
|
-
elsif TCOD.console_is_key_pressed(TCOD::KEY_DOWN)
|
26
|
-
$playery += 1
|
27
|
-
elsif TCOD.console_is_key_pressed(TCOD::KEY_LEFT)
|
28
|
-
$playerx -= 1
|
29
|
-
elsif TCOD.console_is_key_pressed(TCOD::KEY_RIGHT)
|
30
|
-
$playerx += 1
|
31
|
-
end
|
32
|
-
|
33
|
-
false
|
34
|
-
end
|
35
|
-
|
36
|
-
#############################################
|
37
|
-
# Initialization & Main Loop
|
38
|
-
#############################################
|
39
|
-
|
40
|
-
TCOD.console_set_custom_font('arial10x10.png', TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 0, 0)
|
41
|
-
TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'ruby/TCOD tutorial', false, TCOD::RENDERER_SDL)
|
42
|
-
TCOD.sys_set_fps(LIMIT_FPS)
|
43
|
-
|
44
|
-
$playerx = SCREEN_WIDTH/2
|
45
|
-
$playery = SCREEN_HEIGHT/2
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
TCOD.
|
52
|
-
|
53
|
-
TCOD.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'libtcod'
|
4
|
+
|
5
|
+
#actual size of the window
|
6
|
+
SCREEN_WIDTH = 80
|
7
|
+
SCREEN_HEIGHT = 50
|
8
|
+
|
9
|
+
LIMIT_FPS = 20 #20 frames-per-second maximum
|
10
|
+
|
11
|
+
def handle_keys
|
12
|
+
#key = TCOD.console_check_for_keypress() #real-time
|
13
|
+
key = TCOD.console_wait_for_keypress(true) #turn-based
|
14
|
+
|
15
|
+
if key.vk == TCOD::KEY_ENTER && key.lalt
|
16
|
+
#Alt+Enter: toggle fullscreen
|
17
|
+
TCOD.console_set_fullscreen(!TCOD.console_is_fullscreen())
|
18
|
+
elsif key.vk == TCOD::KEY_ESCAPE
|
19
|
+
return true #exit game
|
20
|
+
end
|
21
|
+
|
22
|
+
#movement keys
|
23
|
+
if TCOD.console_is_key_pressed(TCOD::KEY_UP)
|
24
|
+
$playery -= 1
|
25
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_DOWN)
|
26
|
+
$playery += 1
|
27
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_LEFT)
|
28
|
+
$playerx -= 1
|
29
|
+
elsif TCOD.console_is_key_pressed(TCOD::KEY_RIGHT)
|
30
|
+
$playerx += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
#############################################
|
37
|
+
# Initialization & Main Loop
|
38
|
+
#############################################
|
39
|
+
|
40
|
+
TCOD.console_set_custom_font('./arial10x10.png', TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 0, 0)
|
41
|
+
TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'ruby/TCOD tutorial', false, TCOD::RENDERER_SDL)
|
42
|
+
TCOD.sys_set_fps(LIMIT_FPS)
|
43
|
+
|
44
|
+
$playerx = SCREEN_WIDTH/2
|
45
|
+
$playery = SCREEN_HEIGHT/2
|
46
|
+
|
47
|
+
trap('SIGINT') { exit! }
|
48
|
+
|
49
|
+
until TCOD.console_is_window_closed
|
50
|
+
TCOD.console_set_default_foreground(nil, TCOD::Color::WHITE)
|
51
|
+
TCOD.console_put_char(nil, $playerx, $playery, '@'.ord, TCOD::BKGND_NONE)
|
52
|
+
|
53
|
+
TCOD.console_flush()
|
54
|
+
|
55
|
+
TCOD.console_put_char(nil, $playerx, $playery, ' '.ord, TCOD::BKGND_NONE)
|
56
|
+
|
57
|
+
#handle keys and exit game if needed
|
58
|
+
will_exit = handle_keys
|
59
|
+
break if will_exit
|
60
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
#
|
3
4
|
# TCOD ruby tutorial with tiles
|
4
5
|
#
|
@@ -293,7 +294,7 @@ end
|
|
293
294
|
#############################################
|
294
295
|
|
295
296
|
#note that we must specify the number of tiles on the font, which was enlarged a bit
|
296
|
-
TCOD.console_set_custom_font('oryx_tiles.png', TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 32, 12)
|
297
|
+
TCOD.console_set_custom_font(File.join(File.dirname(__FILE__), 'oryx_tiles.png'), TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 32, 12)
|
297
298
|
TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/TCOD tutorial', false, TCOD::RENDERER_SDL)
|
298
299
|
TCOD.sys_set_fps(LIMIT_FPS)
|
299
300
|
$con = TCOD.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
|
@@ -323,6 +324,8 @@ end
|
|
323
324
|
|
324
325
|
$fov_recompute = true
|
325
326
|
|
327
|
+
trap('SIGINT') { exit! }
|
328
|
+
|
326
329
|
until TCOD.console_is_window_closed()
|
327
330
|
|
328
331
|
#render the screen
|
data/lib/libtcod.rb
CHANGED
data/lib/libtcod/bindings.rb
CHANGED
@@ -77,6 +77,10 @@ module TCOD
|
|
77
77
|
:ralt, :bool,
|
78
78
|
:rctrl, :bool,
|
79
79
|
:shift, :bool
|
80
|
+
|
81
|
+
def c
|
82
|
+
self[:c].chr
|
83
|
+
end
|
80
84
|
end
|
81
85
|
|
82
86
|
TCOD_renderer_t = :int
|
@@ -264,7 +268,7 @@ module TCOD
|
|
264
268
|
tcod_function :TCOD_image_is_pixel_transparent, [ :pointer, :int, :int ], :bool
|
265
269
|
|
266
270
|
### Mouse module
|
267
|
-
class
|
271
|
+
class Mouse < MethodStruct
|
268
272
|
layout(
|
269
273
|
:x, :int,
|
270
274
|
:y, :int,
|
@@ -284,11 +288,11 @@ module TCOD
|
|
284
288
|
:wheel_down, :bool
|
285
289
|
)
|
286
290
|
end
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
#
|
291
|
+
tcod_function :TCOD_mouse_show_cursor, [ :bool ], :void
|
292
|
+
tcod_function :TCOD_mouse_get_status, [ ], Mouse
|
293
|
+
tcod_function :TCOD_mouse_is_cursor_visible, [ ], :bool
|
294
|
+
tcod_function :TCOD_mouse_move, [ :int, :int ], :void
|
295
|
+
#tcod_function :TCOD_mouse_includes_touch, [ :bool ], :void
|
292
296
|
|
293
297
|
### Parser module
|
294
298
|
TYPE_NONE = 0
|
data/lib/libtcod/console.rb
CHANGED
@@ -1,80 +1,93 @@
|
|
1
|
-
module TCOD
|
2
|
-
class Console
|
3
|
-
attr_accessor :width, :height, :ptr
|
4
|
-
|
5
|
-
def self.root
|
6
|
-
@root ||= TCOD::Console.new(0, 0, true)
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(w, h, root=false)
|
10
|
-
if root
|
11
|
-
@ptr = nil
|
12
|
-
else
|
13
|
-
@width = w
|
14
|
-
@height = w
|
15
|
-
@ptr = TCOD.console_new(w, h)
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def
|
28
|
-
def
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def
|
43
|
-
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def
|
51
|
-
TCOD.
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
def
|
76
|
-
TCOD.
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
|
1
|
+
module TCOD
|
2
|
+
class Console
|
3
|
+
attr_accessor :width, :height, :ptr
|
4
|
+
|
5
|
+
def self.root
|
6
|
+
@root ||= TCOD::Console.new(0, 0, true)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(w, h, root=false)
|
10
|
+
if root
|
11
|
+
@ptr = nil
|
12
|
+
else
|
13
|
+
@width = w
|
14
|
+
@height = w
|
15
|
+
@ptr = TCOD.console_new(w, h)
|
16
|
+
end
|
17
|
+
|
18
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(ptr))
|
19
|
+
end
|
20
|
+
|
21
|
+
def init_root(width, height, title, fullscreen=false, renderer=RENDERER_SDL)
|
22
|
+
TCOD.console_init_root(width, height, title, fullscreen, renderer)
|
23
|
+
Console.root.width = width
|
24
|
+
Console.root.height = height
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_window_title(title); TCOD.console_set_window_title(title); end
|
28
|
+
def set_fullscreen(bool); TCOD.console_set_fullscreen(bool); end
|
29
|
+
def is_fullscreen?; TCOD.console_is_fullscreen; end
|
30
|
+
def window_closed?; TCOD.console_is_window_closed; end
|
31
|
+
def set_custom_font(fontFile, flags, nb_char_horiz=0, nb_char_vertic=0)
|
32
|
+
TCOD.console_set_custom_font(fontFile, flags, nb_char_horiz, nb_char_vertic)
|
33
|
+
end
|
34
|
+
def map_ascii_code_to_font(asciiCode, fontCharX, fontCharY)
|
35
|
+
TCOD.console_map_ascii_code_to_font(asciiCode.ord, fontCharX, fontCharY)
|
36
|
+
end
|
37
|
+
def map_ascii_codes_to_font(asciiCode, nbCodes, fontCharX, fontCharY)
|
38
|
+
TCOD.console_map_ascii_code_to_font(asciiCode.ord, nbCodes, fontCharX, fontCharY)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def set_default_background(color); TCOD.console_set_default_background(@ptr, color); end
|
43
|
+
def set_default_foreground(color); TCOD.console_set_default_foreground(@ptr, color); end
|
44
|
+
def clear; TCOD.console_clear(@ptr); end
|
45
|
+
|
46
|
+
def set_char_background(x, y, col, flag=TCOD::BKGND_SET)
|
47
|
+
TCOD.console_set_char_background(@ptr, x, y, col, flag)
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_char_foreground(x, y, col)
|
51
|
+
TCOD.console_set_char_foreground(@ptr, x, y, col)
|
52
|
+
end
|
53
|
+
|
54
|
+
def put_char(x, y, c, flag=BKGND_DEFAULT)
|
55
|
+
TCOD.console_put_char(@ptr, x, y, c.ord, flag)
|
56
|
+
end
|
57
|
+
def put_char_ex(x, y, c, foreground, background)
|
58
|
+
TCOD.console_put_char_ex(@ptr, x, y, c.ord, foreground, background)
|
59
|
+
end
|
60
|
+
def set_background_flag(bkgnd_flag)
|
61
|
+
TCOD.console_set_background_flag(@ptr, bkgnd_flag)
|
62
|
+
end
|
63
|
+
def set_alignment(alignment)
|
64
|
+
TCOD.console_set_alignment(@ptr, alignment)
|
65
|
+
end
|
66
|
+
def print(x, y, fmt, *args)
|
67
|
+
TCOD.console_print(@ptr, x, y, fmt, *args)
|
68
|
+
end
|
69
|
+
def print_ex(x, y, bkgnd_flag, alignment, fmt, *args)
|
70
|
+
TCOD.console_print_ex(@ptr, x, y, bkgnd_flag, alignment, fmt, *args)
|
71
|
+
end
|
72
|
+
def print_rect(x, y, w, h, fmt, *args)
|
73
|
+
TCOD.console_print_rect(@ptr, x, y, w, h, fmt, *args)
|
74
|
+
end
|
75
|
+
def print_rect_ex(x, y, w, h, bkgnd_flag, alignment, fmt, *args)
|
76
|
+
TCOD.console_print_rect_ex(@ptr, x, y, w, h, bkgnf_flag, alignment, fmt, *args)
|
77
|
+
end
|
78
|
+
|
79
|
+
def flush; TCOD.console_flush; end
|
80
|
+
|
81
|
+
def check_for_keypress(flags=TCOD::KEY_PRESSED); TCOD.console_check_for_keypress(flags); end
|
82
|
+
def wait_for_keypress(flush=false); TCOD.console_wait_for_keypress(flush); end
|
83
|
+
def key_pressed?(keycode); TCOD.console_is_key_pressed(keycode); end
|
84
|
+
|
85
|
+
def blit(src, xSrc, ySrc, wSrc, hSrc, xDst, yDst, foregroundAlpha=1.0, backgroundAlpha=1.0)
|
86
|
+
TCOD.console_blit(src.ptr, xSrc, ySrc, wSrc, hSrc, @ptr, xDst, yDst, foregroundAlpha, backgroundAlpha)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.finalize(ptr)
|
90
|
+
proc { TCOD.console_delete(ptr) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/libtcod/map.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
module TCOD
|
2
|
+
class Map
|
3
|
+
attr_reader :ptr
|
4
|
+
|
5
|
+
def initialize(width, height)
|
6
|
+
@width = width
|
7
|
+
@height = height
|
8
|
+
@ptr = TCOD.map_new(width, height)
|
9
|
+
|
10
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(ptr))
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_properties(x, y, is_transparent, is_walkable)
|
14
|
+
TCOD.map_set_properties(@ptr, x, y, is_transparent, is_walkable)
|
15
|
+
end
|
16
|
+
|
17
|
+
def compute_fov(x, y, max_radius, light_walls, algo)
|
18
|
+
TCOD.map_compute_fov(@ptr, x, y, max_radius, light_walls, algo)
|
19
|
+
end
|
20
|
+
|
21
|
+
def in_fov?(x, y)
|
22
|
+
TCOD.map_is_in_fov(@ptr, x, y)
|
23
|
+
end
|
24
|
+
|
25
|
+
def clone
|
26
|
+
map = Map.new(@width, @height)
|
27
|
+
TCOD.map_copy(@ptr, map.ptr)
|
28
|
+
map
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.finalize(ptr)
|
32
|
+
proc { TCOD.map_delete(ptr) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Path
|
37
|
+
attr_reader :ptr
|
38
|
+
|
39
|
+
def self.by_map(tcod_map, diagonalCost=1.41)
|
40
|
+
Path.new TCOD.path_new_using_map(tcod_map.ptr, diagonalCost)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.by_callback(width, height, user_data=nil, diagonalCost=1.41, &b)
|
44
|
+
Path.new TCOD.path_new_using_function(width, height, b, user_data, diagonalCost)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generally shouldn't be called directly
|
48
|
+
def initialize(ptr)
|
49
|
+
@ptr = ptr
|
50
|
+
|
51
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(ptr))
|
52
|
+
end
|
53
|
+
|
54
|
+
# Compute a path between two points
|
55
|
+
# ox, oy - Coordinates of the origin of the path
|
56
|
+
# dx, dy - Coordinates of the destination of the path
|
57
|
+
# Returns false if there is no possible path.
|
58
|
+
def compute(ox, oy, dx, dy)
|
59
|
+
TCOD.path_compute(@ptr, ox, oy, dx, dy)
|
60
|
+
end
|
61
|
+
|
62
|
+
def walk(recalculate_when_needed=true)
|
63
|
+
px = FFI::MemoryPointer.new(:int)
|
64
|
+
py = FFI::MemoryPointer.new(:int)
|
65
|
+
if TCOD.path_walk(@ptr, px, py, recalculate_when_needed)
|
66
|
+
[px.read_int, py.read_int]
|
67
|
+
else
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def empty?; TCOD.path_is_empty(@ptr); end
|
73
|
+
def size; TCOD.path_size(@ptr); end
|
74
|
+
def reverse!; TCOD.path_reverse(@ptr); end
|
75
|
+
|
76
|
+
def [](index)
|
77
|
+
px = FFI::MemoryPointer.new(:int)
|
78
|
+
py = FFI::MemoryPointer.new(:int)
|
79
|
+
TCOD.path_get(@ptr, index, px, py)
|
80
|
+
[px.read_int, py.read_int]
|
81
|
+
end
|
82
|
+
|
83
|
+
def origin
|
84
|
+
px = FFI::MemoryPointer.new(:int)
|
85
|
+
py = FFI::MemoryPointer.new(:int)
|
86
|
+
TCOD.path_get_origin(@ptr, px, py)
|
87
|
+
[px.read_int, py.read_int]
|
88
|
+
end
|
89
|
+
|
90
|
+
def destination
|
91
|
+
px = FFI::MemoryPointer.new(:int)
|
92
|
+
py = FFI::MemoryPointer.new(:int)
|
93
|
+
TCOD.path_get_destination(@ptr, px, py)
|
94
|
+
[px.read_int, py.read_int]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.finalize(ptr)
|
98
|
+
proc { TCOD.path_delete(ptr) }
|
99
|
+
end
|
100
|
+
|
101
|
+
# Custom additions
|
102
|
+
def each(&b)
|
103
|
+
0.upto(self.size-1) do |i|
|
104
|
+
yield self[i]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/libtcod/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libtcod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -46,7 +46,9 @@ dependencies:
|
|
46
46
|
description: Ruby bindings for the libtcod roguelike library
|
47
47
|
email:
|
48
48
|
- mispy@staff.draftable.com
|
49
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- libtcod-ruby-test
|
51
|
+
- oryx_tiles.png
|
50
52
|
extensions: []
|
51
53
|
extra_rdoc_files: []
|
52
54
|
files:
|
@@ -55,6 +57,8 @@ files:
|
|
55
57
|
- LICENSE
|
56
58
|
- README.md
|
57
59
|
- Rakefile
|
60
|
+
- bin/libtcod-ruby-test
|
61
|
+
- bin/oryx_tiles.png
|
58
62
|
- clib/amd64/libSDL.so
|
59
63
|
- clib/amd64/libtcod.so
|
60
64
|
- clib/i686/SDL.dll
|
@@ -71,6 +75,7 @@ files:
|
|
71
75
|
- lib/libtcod/color_consts.rb
|
72
76
|
- lib/libtcod/console.rb
|
73
77
|
- lib/libtcod/consts.rb
|
78
|
+
- lib/libtcod/map.rb
|
74
79
|
- lib/libtcod/struct.rb
|
75
80
|
- lib/libtcod/system.rb
|
76
81
|
- lib/libtcod/version.rb
|