├── .gitignore ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── libtcod-ruby-test └── oryx_tiles.png ├── examples ├── python_tutorial_part_1 │ ├── arial10x10.png │ ├── main.rb │ └── terminal.png └── tile_demo │ ├── oryx_tiles.png │ └── tile_demo.rb ├── ext └── libtcod │ ├── amd64 │ ├── libSDL.dylib │ ├── libSDL.so │ ├── libtcod.dylib │ └── libtcod.so │ ├── i686 │ ├── SDL.dll │ ├── libSDL.dylib │ ├── libSDL.so │ ├── libtcod-mingw.dll │ ├── libtcod.dylib │ └── libtcod.so │ └── powerpc │ ├── libSDL.dylib │ └── libtcod.dylib ├── lib ├── libtcod.rb └── libtcod │ ├── bindings.rb │ ├── cell.rb │ ├── color.rb │ ├── color_consts.rb │ ├── console.rb │ ├── consts.rb │ ├── coord.rb │ ├── map.rb │ ├── rect.rb │ ├── root_console.rb │ ├── struct.rb │ ├── system.rb │ └── version.rb ├── libtcod.gemspec ├── terminal.png └── test ├── color.rb ├── console.rb └── helpers.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | .*.swp 19 | .~ 20 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in libtcod.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Jaiden Mispy 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libtcod-ruby 0.1.1 2 | 3 | Ruby bindings for [libtcod 1.5.1](http://doryen.eptalys.net/libtcod/) 4 | 5 | Currently tested using Ruby 1.9.3 on Linux, Windows and OS X (thanks to [@mistydemeo](https://github.com/mistydemeo)). Other platforms may work if you have libtcod in a place where ffi\_lib knows to get it. All the original C functions are wrapped, following the [original documentation](http://doryen.eptalys.net/data/libtcod/doc/1.5.1/html2/line.html?c=true&cpp=false&cs=false&py=false&lua=false) closely. See the example for slight differences in invocation. 6 | 7 | ## Installation 8 | 9 | gem install libtcod 10 | 11 | ## Examples 12 | 13 | Here's a straight port of the [example code](http://roguebasin.roguelikedevelopment.org/index.php?title=Complete_Roguelike_Tutorial,_using_python%2Blibtcod,_part_1_code#Moving_around) from part 1 of the python tutorial: 14 | 15 | ```ruby 16 | require 'libtcod' 17 | 18 | #actual size of the window 19 | SCREEN_WIDTH = 80 20 | SCREEN_HEIGHT = 50 21 | 22 | LIMIT_FPS = 20 #20 frames-per-second maximum 23 | 24 | def handle_keys 25 | #key = TCOD.console_check_for_keypress() #real-time 26 | key = TCOD.console_wait_for_keypress(true) #turn-based 27 | 28 | if key.vk == TCOD::KEY_ENTER && key.lalt 29 | #Alt+Enter: toggle fullscreen 30 | TCOD.console_set_fullscreen(!TCOD.console_is_fullscreen()) 31 | elsif key.vk == TCOD::KEY_ESCAPE 32 | return true #exit game 33 | end 34 | 35 | #movement keys 36 | if TCOD.console_is_key_pressed(TCOD::KEY_UP) 37 | $playery -= 1 38 | elsif TCOD.console_is_key_pressed(TCOD::KEY_DOWN) 39 | $playery += 1 40 | elsif TCOD.console_is_key_pressed(TCOD::KEY_LEFT) 41 | $playerx -= 1 42 | elsif TCOD.console_is_key_pressed(TCOD::KEY_RIGHT) 43 | $playerx += 1 44 | end 45 | 46 | false 47 | end 48 | 49 | ############################################# 50 | # Initialization & Main Loop 51 | ############################################# 52 | 53 | TCOD.console_set_custom_font('arial10x10.png', TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 0, 0) 54 | TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'ruby/TCOD tutorial', false, TCOD::RENDERER_SDL) 55 | TCOD.sys_set_fps(LIMIT_FPS) 56 | 57 | $playerx = SCREEN_WIDTH/2 58 | $playery = SCREEN_HEIGHT/2 59 | 60 | until TCOD.console_is_window_closed 61 | TCOD.console_set_default_foreground(nil, TCOD::Color::WHITE) 62 | TCOD.console_put_char(nil, $playerx, $playery, '@'.ord, TCOD::BKGND_NONE) 63 | 64 | TCOD.console_flush() 65 | 66 | TCOD.console_put_char(nil, $playerx, $playery, ' '.ord, TCOD::BKGND_NONE) 67 | 68 | #handle keys and exit game if needed 69 | will_exit = handle_keys 70 | break if will_exit 71 | end 72 | ``` 73 | 74 | 75 | ## Contributing 76 | 77 | 1. Fork it 78 | 2. Create your feature branch (`git checkout -b my-new-feature`) 79 | 3. Commit your changes (`git commit -am 'Added some feature'`) 80 | 4. Push to the branch (`git push origin my-new-feature`) 81 | 5. Create new Pull Request 82 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | -------------------------------------------------------------------------------- /bin/libtcod-ruby-test: -------------------------------------------------------------------------------- 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, 'ruby/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 345 | -------------------------------------------------------------------------------- /bin/oryx_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/bin/oryx_tiles.png -------------------------------------------------------------------------------- /examples/python_tutorial_part_1/arial10x10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/examples/python_tutorial_part_1/arial10x10.png -------------------------------------------------------------------------------- /examples/python_tutorial_part_1/main.rb: -------------------------------------------------------------------------------- 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 61 | -------------------------------------------------------------------------------- /examples/python_tutorial_part_1/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/examples/python_tutorial_part_1/terminal.png -------------------------------------------------------------------------------- /examples/tile_demo/oryx_tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/examples/tile_demo/oryx_tiles.png -------------------------------------------------------------------------------- /examples/tile_demo/tile_demo.rb: -------------------------------------------------------------------------------- 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 345 | -------------------------------------------------------------------------------- /ext/libtcod/amd64/libSDL.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/amd64/libSDL.dylib -------------------------------------------------------------------------------- /ext/libtcod/amd64/libSDL.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/amd64/libSDL.so -------------------------------------------------------------------------------- /ext/libtcod/amd64/libtcod.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/amd64/libtcod.dylib -------------------------------------------------------------------------------- /ext/libtcod/amd64/libtcod.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/amd64/libtcod.so -------------------------------------------------------------------------------- /ext/libtcod/i686/SDL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/SDL.dll -------------------------------------------------------------------------------- /ext/libtcod/i686/libSDL.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/libSDL.dylib -------------------------------------------------------------------------------- /ext/libtcod/i686/libSDL.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/libSDL.so -------------------------------------------------------------------------------- /ext/libtcod/i686/libtcod-mingw.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/libtcod-mingw.dll -------------------------------------------------------------------------------- /ext/libtcod/i686/libtcod.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/libtcod.dylib -------------------------------------------------------------------------------- /ext/libtcod/i686/libtcod.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/ext/libtcod/i686/libtcod.so -------------------------------------------------------------------------------- /ext/libtcod/powerpc/libSDL.dylib: -------------------------------------------------------------------------------- 1 | ../i686/libSDL.dylib -------------------------------------------------------------------------------- /ext/libtcod/powerpc/libtcod.dylib: -------------------------------------------------------------------------------- 1 | ../i686/libtcod.dylib -------------------------------------------------------------------------------- /lib/libtcod.rb: -------------------------------------------------------------------------------- 1 | require 'ffi' 2 | require 'libtcod/version' 3 | require 'libtcod/struct' 4 | require 'libtcod/consts' 5 | require 'libtcod/color' 6 | require 'libtcod/bindings' 7 | require 'libtcod/color_consts' 8 | require 'libtcod/system' 9 | require 'libtcod/console' 10 | require 'libtcod/map' 11 | -------------------------------------------------------------------------------- /lib/libtcod/bindings.rb: -------------------------------------------------------------------------------- 1 | APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) 2 | 3 | module TCOD 4 | extend FFI::Library 5 | 6 | LIB_ROOT = File.expand_path('../../../', __FILE__) 7 | 8 | library_name = 'libtcod' 9 | extension = RUBY_PLATFORM.include?('darwin') ? '.dylib' : '.so' 10 | 11 | case RUBY_PLATFORM 12 | when /mingw32/ 13 | library_name << '-mingw' 14 | extension = '.dll' 15 | platform = 'i686' 16 | when /powerpc/ 17 | platform = 'powerpc' 18 | when /x86_64/ 19 | platform = 'amd64' 20 | when /i.86/ 21 | platform = 'i686' 22 | end 23 | 24 | path = File.join(LIB_ROOT, 25 | 'ext/libtcod', 26 | platform, 27 | library_name + extension) 28 | 29 | # This fixes an ffi path issue that prevents ffi to find things on Windows. 30 | path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) 31 | ffi_lib [library_name, path] 32 | 33 | # Remove redundant namespacing 34 | def self.tcod_function(sym, *args) 35 | attach_function(sym[5..-1].to_sym, sym, *args) 36 | end 37 | 38 | tcod_function :TCOD_color_RGB, [ :uchar, :uchar, :uchar ], Color.val 39 | tcod_function :TCOD_color_HSV, [ :float, :float, :float ], Color.val 40 | tcod_function :TCOD_color_equals, [ Color.val, Color.val ], :bool 41 | tcod_function :TCOD_color_add, [ Color.val, Color.val ], Color.val 42 | tcod_function :TCOD_color_subtract, [ Color.val, Color.val ], Color.val 43 | tcod_function :TCOD_color_multiply, [ Color.val, Color.val ], Color.val 44 | tcod_function :TCOD_color_multiply_scalar, [ Color.val, :float ], Color.val 45 | tcod_function :TCOD_color_lerp, [ Color.val, Color.val, :float ], Color.val 46 | tcod_function :TCOD_color_set_HSV, [ :pointer, :float, :float, :float ], :void 47 | tcod_function :TCOD_color_get_HSV, [ Color.val, :pointer, :pointer, :pointer ], :void 48 | tcod_function :TCOD_color_get_hue, [ Color.val ], :float 49 | tcod_function :TCOD_color_set_hue, [ :pointer, :float ], :void 50 | tcod_function :TCOD_color_get_saturation, [ Color.val ], :float 51 | tcod_function :TCOD_color_set_saturation, [ :pointer, :float ], :void 52 | tcod_function :TCOD_color_get_value, [ Color.val ], :float 53 | tcod_function :TCOD_color_set_value, [ :pointer, :float ], :void 54 | tcod_function :TCOD_color_shift_hue, [ :pointer, :float ], :void 55 | tcod_function :TCOD_color_scale_HSV, [ :pointer, :float, :float ], :void 56 | tcod_function :TCOD_color_gen_map, [ :pointer, :int, :pointer, :pointer ], :void 57 | 58 | ### Console module 59 | class Key < MethodStruct 60 | layout :vk, :int, 61 | :c, :uchar, 62 | :pressed, :bool, 63 | :lalt, :bool, 64 | :lctrl, :bool, 65 | :ralt, :bool, 66 | :rctrl, :bool, 67 | :shift, :bool 68 | 69 | def c 70 | self[:c].chr 71 | end 72 | end 73 | 74 | TCOD_renderer_t = :int 75 | TCOD_bkgnd_flag_t = :int 76 | TCOD_alignment_t = :int 77 | TCOD_keycode_t = :int 78 | TCOD_colctrl_t = :int 79 | TCOD_console_t = :pointer 80 | 81 | tcod_function :TCOD_console_init_root, [ :int, :int, :string, :bool, TCOD_renderer_t ], :void 82 | tcod_function :TCOD_console_set_window_title, [ :string ], :void 83 | tcod_function :TCOD_console_set_fullscreen, [ :bool ], :void 84 | tcod_function :TCOD_console_is_fullscreen, [ ], :bool 85 | tcod_function :TCOD_console_is_window_closed, [ ], :bool 86 | tcod_function :TCOD_console_set_custom_font, [ :string, :int, :int, :int ], :void 87 | tcod_function :TCOD_console_map_ascii_code_to_font, [ :int, :int, :int ], :void 88 | tcod_function :TCOD_console_map_ascii_codes_to_font, [ :int, :int, :int, :int ], :void 89 | tcod_function :TCOD_console_map_string_to_font, [ :string, :int, :int ], :void 90 | tcod_function :TCOD_console_set_dirty, [ :int, :int, :int, :int ], :void 91 | tcod_function :TCOD_console_set_default_background, [ :pointer, Color.val ], :void 92 | tcod_function :TCOD_console_set_default_foreground, [ :pointer, Color.val ], :void 93 | tcod_function :TCOD_console_clear, [ :pointer ], :void 94 | tcod_function :TCOD_console_set_char_background, [ :pointer, :int, :int, Color.val, TCOD_bkgnd_flag_t ], :void 95 | tcod_function :TCOD_console_set_char_foreground, [ :pointer, :int, :int, Color.val ], :void 96 | tcod_function :TCOD_console_set_char, [ :pointer, :int, :int, :int ], :void 97 | tcod_function :TCOD_console_put_char, [ :pointer, :int, :int, :int, TCOD_bkgnd_flag_t ], :void 98 | tcod_function :TCOD_console_put_char_ex, [ :pointer, :int, :int, :int, Color.val, Color.val ], :void 99 | tcod_function :TCOD_console_set_background_flag, [ :pointer, TCOD_bkgnd_flag_t ], :void 100 | tcod_function :TCOD_console_get_background_flag, [ :pointer ], TCOD_bkgnd_flag_t 101 | tcod_function :TCOD_console_set_alignment, [ :pointer, TCOD_alignment_t ], :void 102 | tcod_function :TCOD_console_get_alignment, [ :pointer ], TCOD_alignment_t 103 | tcod_function :TCOD_console_print, [ :pointer, :int, :int, :string, :varargs ], :void 104 | tcod_function :TCOD_console_print_ex, [ :pointer, :int, :int, TCOD_bkgnd_flag_t, TCOD_alignment_t, :string, :varargs ], :void 105 | tcod_function :TCOD_console_print_rect, [ :pointer, :int, :int, :int, :int, :string, :varargs ], :int 106 | tcod_function :TCOD_console_print_rect_ex, [ :pointer, :int, :int, :int, :int, TCOD_bkgnd_flag_t, TCOD_alignment_t, :string, :varargs ], :int 107 | tcod_function :TCOD_console_get_height_rect, [ :pointer, :int, :int, :int, :int, :string, :varargs ], :int 108 | tcod_function :TCOD_console_rect, [ :pointer, :int, :int, :int, :int, :bool, TCOD_bkgnd_flag_t ], :void 109 | tcod_function :TCOD_console_hline, [ :pointer, :int, :int, :int, TCOD_bkgnd_flag_t ], :void 110 | tcod_function :TCOD_console_vline, [ :pointer, :int, :int, :int, TCOD_bkgnd_flag_t ], :void 111 | tcod_function :TCOD_console_print_frame, [ :pointer, :int, :int, :int, :int, :bool, TCOD_bkgnd_flag_t, :string, :varargs ], :void 112 | tcod_function :TCOD_console_map_string_to_font_utf, [ :pointer, :int, :int ], :void 113 | tcod_function :TCOD_console_print_utf, [ :pointer, :int, :int, :pointer, :varargs ], :void 114 | tcod_function :TCOD_console_print_ex_utf, [ :pointer, :int, :int, TCOD_bkgnd_flag_t, TCOD_alignment_t, :pointer, :varargs ], :void 115 | tcod_function :TCOD_console_print_rect_utf, [ :pointer, :int, :int, :int, :int, :pointer, :varargs ], :int 116 | tcod_function :TCOD_console_print_rect_ex_utf, [ :pointer, :int, :int, :int, :int, TCOD_bkgnd_flag_t, TCOD_alignment_t, :pointer, :varargs ], :int 117 | tcod_function :TCOD_console_get_height_rect_utf, [ :pointer, :int, :int, :int, :int, :pointer, :varargs ], :int 118 | tcod_function :TCOD_console_get_default_background, [ :pointer ], Color.val 119 | tcod_function :TCOD_console_get_default_foreground, [ :pointer ], Color.val 120 | tcod_function :TCOD_console_get_char_background, [ :pointer, :int, :int ], Color.val 121 | tcod_function :TCOD_console_get_char_foreground, [ :pointer, :int, :int ], Color.val 122 | tcod_function :TCOD_console_get_char, [ :pointer, :int, :int ], :int 123 | tcod_function :TCOD_console_set_fade, [ :uchar, Color.val ], :void 124 | tcod_function :TCOD_console_get_fade, [ ], :uchar 125 | tcod_function :TCOD_console_get_fading_color, [ ], Color.val 126 | tcod_function :TCOD_console_flush, [ ], :void 127 | tcod_function :TCOD_console_set_color_control, [ TCOD_colctrl_t, Color.val, Color.val ], :void 128 | tcod_function :TCOD_console_check_for_keypress, [ :int ], Key.val 129 | tcod_function :TCOD_console_wait_for_keypress, [ :bool ], Key.val 130 | tcod_function :TCOD_console_set_keyboard_repeat, [ :int, :int ], :void 131 | tcod_function :TCOD_console_disable_keyboard_repeat, [ ], :void 132 | tcod_function :TCOD_console_is_key_pressed, [ TCOD_keycode_t ], :bool 133 | tcod_function :TCOD_console_from_file, [ :string ], :pointer 134 | tcod_function :TCOD_console_load_asc, [ :pointer, :string ], :bool 135 | tcod_function :TCOD_console_load_apf, [ :pointer, :string ], :bool 136 | tcod_function :TCOD_console_save_asc, [ :pointer, :string ], :bool 137 | tcod_function :TCOD_console_save_apf, [ :pointer, :string ], :bool 138 | tcod_function :TCOD_console_new, [ :int, :int ], :pointer 139 | tcod_function :TCOD_console_get_width, [ :pointer ], :int 140 | tcod_function :TCOD_console_get_height, [ :pointer ], :int 141 | tcod_function :TCOD_console_set_key_color, [ :pointer, Color.val ], :void 142 | tcod_function :TCOD_console_blit, [ :pointer, :int, :int, :int, :int, :pointer, :int, :int, :float, :float ], :void 143 | tcod_function :TCOD_console_delete, [ :pointer ], :void 144 | tcod_function :TCOD_console_credits, [ ], :void 145 | tcod_function :TCOD_console_credits_reset, [ ], :void 146 | tcod_function :TCOD_console_credits_render, [ :int, :int, :bool ], :bool 147 | 148 | ### System module 149 | EVENT_KEY_PRESS = 1 150 | EVENT_MOUSE_RELEASE = 16 151 | EVENT_KEY_RELEASE = 2 152 | EVENT_MOUSE_MOVE = 4 153 | EVENT_MOUSE_PRESS = 8 154 | EVENT_MOUSE = EVENT_MOUSE_MOVE|EVENT_MOUSE_PRESS|EVENT_MOUSE_RELEASE 155 | EVENT_KEY = EVENT_KEY_PRESS|EVENT_KEY_RELEASE 156 | EVENT_ANY = EVENT_KEY|EVENT_MOUSE 157 | 158 | TCOD_image_t = :pointer 159 | TCOD_list_t = :pointer 160 | 161 | tcod_function :TCOD_sys_elapsed_milli, [ ], :uint32 162 | tcod_function :TCOD_sys_elapsed_seconds, [ ], :float 163 | tcod_function :TCOD_sys_sleep_milli, [ :uint32 ], :void 164 | tcod_function :TCOD_sys_save_screenshot, [ :string ], :void 165 | tcod_function :TCOD_sys_force_fullscreen_resolution, [ :int, :int ], :void 166 | tcod_function :TCOD_sys_set_renderer, [ TCOD_renderer_t ], :void 167 | tcod_function :TCOD_sys_get_renderer, [ ], TCOD_renderer_t 168 | tcod_function :TCOD_sys_set_fps, [ :int ], :void 169 | tcod_function :TCOD_sys_get_fps, [ ], :int 170 | tcod_function :TCOD_sys_get_last_frame_length, [ ], :float 171 | tcod_function :TCOD_sys_get_current_resolution, [ :pointer, :pointer ], :void 172 | tcod_function :TCOD_sys_get_fullscreen_offsets, [ :pointer, :pointer ], :void 173 | tcod_function :TCOD_sys_update_char, [ :int, :int, :int, TCOD_image_t, :int, :int ], :void 174 | tcod_function :TCOD_sys_get_char_size, [ :pointer, :pointer ], :void 175 | #tcod_function :TCOD_sys_get_sdl_window, [ ], :pointer 176 | 177 | tcod_function :TCOD_sys_wait_for_event, [ :int, :pointer, :pointer, :bool ], :int 178 | tcod_function :TCOD_sys_check_for_event, [ :int, :pointer, :pointer ], :int 179 | tcod_function :TCOD_sys_create_directory, [ :string ], :bool 180 | tcod_function :TCOD_sys_delete_file, [ :string ], :bool 181 | tcod_function :TCOD_sys_delete_directory, [ :string ], :bool 182 | tcod_function :TCOD_sys_is_directory, [ :string ], :bool 183 | tcod_function :TCOD_sys_get_directory_content, [ :string, :string ], TCOD_list_t 184 | tcod_function :TCOD_sys_file_exists, [ :string, :varargs ], :bool 185 | tcod_function :TCOD_sys_read_file, [ :string, :pointer, :pointer ], :bool 186 | tcod_function :TCOD_sys_write_file, [ :string, :pointer, :uint32 ], :bool 187 | tcod_function :TCOD_sys_clipboard_set, [ :string ], :void 188 | tcod_function :TCOD_sys_clipboard_get, [ ], :string 189 | tcod_function :TCOD_thread_new, [ callback([ :pointer ], :int), :pointer ], :pointer 190 | tcod_function :TCOD_thread_delete, [ :pointer ], :void 191 | tcod_function :TCOD_sys_get_num_cores, [ ], :int 192 | tcod_function :TCOD_thread_wait, [ :pointer ], :void 193 | tcod_function :TCOD_mutex_new, [ ], :pointer 194 | tcod_function :TCOD_mutex_in, [ :pointer ], :void 195 | tcod_function :TCOD_mutex_out, [ :pointer ], :void 196 | tcod_function :TCOD_mutex_delete, [ :pointer ], :void 197 | tcod_function :TCOD_semaphore_new, [ :int ], :pointer 198 | tcod_function :TCOD_semaphore_lock, [ :pointer ], :void 199 | tcod_function :TCOD_semaphore_unlock, [ :pointer ], :void 200 | tcod_function :TCOD_semaphore_delete, [ :pointer ], :void 201 | tcod_function :TCOD_condition_new, [ ], :pointer 202 | tcod_function :TCOD_condition_signal, [ :pointer ], :void 203 | tcod_function :TCOD_condition_broadcast, [ :pointer ], :void 204 | tcod_function :TCOD_condition_wait, [ :pointer, :pointer ], :void 205 | tcod_function :TCOD_condition_delete, [ :pointer ], :void 206 | tcod_function :TCOD_load_library, [ :string ], :pointer 207 | tcod_function :TCOD_get_function_address, [ :pointer, :string ], :pointer 208 | tcod_function :TCOD_close_library, [ :pointer ], :void 209 | callback(:SDL_renderer_t, [ :pointer ], :void) 210 | tcod_function :TCOD_sys_register_SDL_renderer, [ :SDL_renderer_t ], :void 211 | 212 | ### Line module 213 | class BresenhamData < MethodStruct 214 | layout( 215 | :stepx, :int, 216 | :stepy, :int, 217 | :e, :int, 218 | :deltax, :int, 219 | :deltay, :int, 220 | :origx, :int, 221 | :origy, :int, 222 | :destx, :int, 223 | :desty, :int 224 | ) 225 | end 226 | callback(:TCOD_line_listener_t, [ :int, :int ], :bool) 227 | tcod_function :TCOD_line_init, [ :int, :int, :int, :int ], :void 228 | tcod_function :TCOD_line_step, [ :pointer, :pointer ], :bool 229 | tcod_function :TCOD_line, [ :int, :int, :int, :int, :TCOD_line_listener_t ], :bool 230 | tcod_function :TCOD_line_init_mt, [ :int, :int, :int, :int, :pointer ], :void 231 | tcod_function :TCOD_line_step_mt, [ :pointer, :pointer, :pointer ], :bool 232 | tcod_function :TCOD_line_mt, [ :int, :int, :int, :int, :TCOD_line_listener_t, :pointer ], :bool 233 | 234 | ### Image module 235 | tcod_function :TCOD_image_new, [ :int, :int ], :pointer 236 | tcod_function :TCOD_image_from_console, [ TCOD_console_t ], :pointer 237 | tcod_function :TCOD_image_refresh_console, [ :pointer, TCOD_console_t ], :void 238 | tcod_function :TCOD_image_load, [ :string ], :pointer 239 | tcod_function :TCOD_image_clear, [ :pointer, Color.val ], :void 240 | tcod_function :TCOD_image_invert, [ :pointer ], :void 241 | tcod_function :TCOD_image_hflip, [ :pointer ], :void 242 | tcod_function :TCOD_image_rotate90, [ :pointer, :int ], :void 243 | tcod_function :TCOD_image_vflip, [ :pointer ], :void 244 | tcod_function :TCOD_image_scale, [ :pointer, :int, :int ], :void 245 | tcod_function :TCOD_image_save, [ :pointer, :string ], :void 246 | tcod_function :TCOD_image_get_size, [ :pointer, :pointer, :pointer ], :void 247 | tcod_function :TCOD_image_get_pixel, [ :pointer, :int, :int ], Color.val 248 | tcod_function :TCOD_image_get_alpha, [ :pointer, :int, :int ], :int 249 | tcod_function :TCOD_image_get_mipmap_pixel, [ :pointer, :float, :float, :float, :float ], Color.val 250 | tcod_function :TCOD_image_put_pixel, [ :pointer, :int, :int, Color.val ], :void 251 | tcod_function :TCOD_image_blit, [ :pointer, TCOD_console_t, :float, :float, TCOD_bkgnd_flag_t, :float, :float, :float ], :void 252 | tcod_function :TCOD_image_blit_rect, [ :pointer, TCOD_console_t, :int, :int, :int, :int, TCOD_bkgnd_flag_t ], :void 253 | tcod_function :TCOD_image_blit_2x, [ :pointer, TCOD_console_t, :int, :int, :int, :int, :int, :int ], :void 254 | tcod_function :TCOD_image_delete, [ :pointer ], :void 255 | tcod_function :TCOD_image_set_key_color, [ :pointer, Color.val ], :void 256 | tcod_function :TCOD_image_is_pixel_transparent, [ :pointer, :int, :int ], :bool 257 | 258 | ### Mouse module 259 | class Mouse < MethodStruct 260 | layout( 261 | :x, :int, 262 | :y, :int, 263 | :dx, :int, 264 | :dy, :int, 265 | :cx, :int, 266 | :cy, :int, 267 | :dcx, :int, 268 | :dcy, :int, 269 | :lbutton, :bool, 270 | :rbutton, :bool, 271 | :mbutton, :bool, 272 | :lbutton_pressed, :bool, 273 | :rbutton_pressed, :bool, 274 | :mbutton_pressed, :bool, 275 | :wheel_up, :bool, 276 | :wheel_down, :bool 277 | ) 278 | end 279 | tcod_function :TCOD_mouse_show_cursor, [ :bool ], :void 280 | tcod_function :TCOD_mouse_get_status, [ ], Mouse.val 281 | tcod_function :TCOD_mouse_is_cursor_visible, [ ], :bool 282 | tcod_function :TCOD_mouse_move, [ :int, :int ], :void 283 | #tcod_function :TCOD_mouse_includes_touch, [ :bool ], :void 284 | 285 | ### Parser module 286 | TYPE_NONE = 0 287 | TYPE_BOOL = 1 288 | TYPE_VALUELIST02 = 10 289 | TYPE_LIST = 1024 290 | TYPE_VALUELIST03 = 11 291 | TYPE_VALUELIST04 = 12 292 | TYPE_VALUELIST05 = 13 293 | TYPE_VALUELIST06 = 14 294 | TYPE_VALUELIST07 = 15 295 | TYPE_VALUELIST08 = 16 296 | TYPE_VALUELIST09 = 17 297 | TYPE_VALUELIST10 = 18 298 | TYPE_VALUELIST11 = 19 299 | TYPE_CHAR = 2 300 | TYPE_VALUELIST12 = 20 301 | TYPE_VALUELIST13 = 21 302 | TYPE_VALUELIST14 = 22 303 | TYPE_VALUELIST15 = 23 304 | TYPE_CUSTOM00 = 24 305 | TYPE_CUSTOM01 = 25 306 | TYPE_CUSTOM02 = 26 307 | TYPE_CUSTOM03 = 27 308 | TYPE_CUSTOM04 = 28 309 | TYPE_CUSTOM05 = 29 310 | TYPE_INT = 3 311 | TYPE_CUSTOM06 = 30 312 | TYPE_CUSTOM07 = 31 313 | TYPE_CUSTOM08 = 32 314 | TYPE_CUSTOM09 = 33 315 | TYPE_CUSTOM10 = 34 316 | TYPE_CUSTOM11 = 35 317 | TYPE_CUSTOM12 = 36 318 | TYPE_CUSTOM13 = 37 319 | TYPE_CUSTOM14 = 38 320 | TYPE_CUSTOM15 = 39 321 | TYPE_FLOAT = 4 322 | TYPE_STRING = 5 323 | TYPE_COLOR = 6 324 | TYPE_DICE = 7 325 | TYPE_VALUELIST00 = 8 326 | TYPE_VALUELIST01 = 9 327 | 328 | class Dice < MethodStruct 329 | layout( 330 | :nb_rolls, :int, 331 | :nb_faces, :int, 332 | :multiplier, :float, 333 | :addsub, :float 334 | ) 335 | end 336 | 337 | class TCODValueT < MethodUnion 338 | layout( 339 | :b, :bool, 340 | :c, :char, 341 | :i, :int32, 342 | :f, :float, 343 | :s, :pointer, 344 | :col, Color, 345 | :dice, Dice, 346 | :list, TCOD_list_t, 347 | :custom, :pointer 348 | ) 349 | def s=(str) 350 | @s = FFI::MemoryPointer.from_string(str) 351 | self[:s] = @s 352 | end 353 | def s 354 | @s.get_string(0) 355 | end 356 | end 357 | 358 | class TCODStructIntT < MethodStruct 359 | layout( 360 | :name, :pointer, 361 | :flags, TCOD_list_t, 362 | :props, TCOD_list_t, 363 | :lists, TCOD_list_t, 364 | :structs, TCOD_list_t 365 | ) 366 | def name=(str) 367 | @name = FFI::MemoryPointer.from_string(str) 368 | self[:name] = @name 369 | end 370 | def name 371 | @name.get_string(0) 372 | end 373 | end 374 | 375 | callback(:TCOD_parser_custom_t, [ :pointer, :pointer, :pointer, :string ], TCODValueT.val) 376 | class TCODParserIntT < MethodStruct 377 | layout( 378 | :structs, TCOD_list_t, 379 | :customs, [:TCOD_parser_custom_t, 16], 380 | :fatal, :bool, 381 | :props, TCOD_list_t 382 | ) 383 | end 384 | 385 | class TCODParserListenerT < MethodStruct 386 | layout( 387 | :new_struct, callback([ :pointer, :string ], :bool), 388 | :new_flag, callback([ :string ], :bool), 389 | :new_property, callback([ :string, :int, TCODValueT ], :bool), 390 | :end_struct, callback([ :pointer, :string ], :bool), 391 | :error, callback([ :string ], :void) 392 | ) 393 | end 394 | 395 | tcod_function :TCOD_struct_get_name, [ :pointer ], :string 396 | tcod_function :TCOD_struct_add_property, [ :pointer, :string, :int, :bool ], :void 397 | tcod_function :TCOD_struct_add_list_property, [ :pointer, :string, :int, :bool ], :void 398 | tcod_function :TCOD_struct_add_value_list, [ :pointer, :string, :pointer, :bool ], :void 399 | tcod_function :TCOD_struct_add_value_list_sized, [ :pointer, :string, :pointer, :int, :bool ], :void 400 | tcod_function :TCOD_struct_add_flag, [ :pointer, :string ], :void 401 | tcod_function :TCOD_struct_add_structure, [ :pointer, :pointer ], :void 402 | tcod_function :TCOD_struct_is_mandatory, [ :pointer, :string ], :bool 403 | tcod_function :TCOD_struct_get_type, [ :pointer, :string ], :int 404 | 405 | tcod_function :TCOD_parser_new, [ ], :pointer 406 | tcod_function :TCOD_parser_new_struct, [ :pointer, :string ], :pointer 407 | tcod_function :TCOD_parser_new_custom_type, [ :pointer, :TCOD_parser_custom_t ], :int 408 | tcod_function :TCOD_parser_run, [ :pointer, :string, :pointer ], :void 409 | tcod_function :TCOD_parser_delete, [ :pointer ], :void 410 | tcod_function :TCOD_parser_error, [ :string, :varargs ], :void 411 | tcod_function :TCOD_parser_get_bool_property, [ :pointer, :string ], :bool 412 | tcod_function :TCOD_parser_get_char_property, [ :pointer, :string ], :int 413 | tcod_function :TCOD_parser_get_int_property, [ :pointer, :string ], :int 414 | tcod_function :TCOD_parser_get_float_property, [ :pointer, :string ], :float 415 | tcod_function :TCOD_parser_get_string_property, [ :pointer, :string ], :string 416 | tcod_function :TCOD_parser_get_color_property, [ :pointer, :string ], Color.val 417 | tcod_function :TCOD_parser_get_dice_property, [ :pointer, :string ], Dice.val 418 | tcod_function :TCOD_parser_get_dice_property_py, [ :pointer, :string, :pointer ], :void 419 | tcod_function :TCOD_parser_get_custom_property, [ :pointer, :string ], :pointer 420 | tcod_function :TCOD_parser_get_list_property, [ :pointer, :string, :int ], TCOD_list_t 421 | 422 | tcod_function :TCOD_parse_bool_value, [ ], TCODValueT 423 | tcod_function :TCOD_parse_char_value, [ ], TCODValueT 424 | tcod_function :TCOD_parse_integer_value, [ ], TCODValueT 425 | tcod_function :TCOD_parse_float_value, [ ], TCODValueT 426 | tcod_function :TCOD_parse_string_value, [ ], TCODValueT 427 | tcod_function :TCOD_parse_color_value, [ ], TCODValueT 428 | tcod_function :TCOD_parse_dice_value, [ ], TCODValueT 429 | tcod_function :TCOD_parse_value_list_value, [ :pointer, :int ], TCODValueT 430 | tcod_function :TCOD_parse_property_value, [ :pointer, :pointer, :string, :bool ], TCODValueT 431 | 432 | ### Random module 433 | RNG_MT = 0 434 | RNG_CMWC = 1 435 | 436 | DISTRIBUTION_LINEAR = 0 437 | DISTRIBUTION_GAUSSIAN = 1 438 | DISTRIBUTION_GAUSSIAN_RANGE = 2 439 | DISTRIBUTION_GAUSSIAN_INVERSE = 3 440 | DISTRIBUTION_GAUSSIAN_RANGE_INVERSE = 4 441 | 442 | TCOD_random_algo_t = :int 443 | TCOD_distribution_t = :int 444 | TCOD_random_t = :pointer 445 | 446 | tcod_function :TCOD_random_get_instance, [ ], :pointer 447 | tcod_function :TCOD_random_new, [ TCOD_random_algo_t ], :pointer 448 | tcod_function :TCOD_random_save, [ :pointer ], :pointer 449 | tcod_function :TCOD_random_restore, [ :pointer, :pointer ], :void 450 | tcod_function :TCOD_random_new_from_seed, [ TCOD_random_algo_t, :uint32 ], :pointer 451 | tcod_function :TCOD_random_delete, [ :pointer ], :void 452 | tcod_function :TCOD_random_set_distribution, [ :pointer, TCOD_distribution_t ], :void 453 | tcod_function :TCOD_random_get_int, [ :pointer, :int, :int ], :int 454 | tcod_function :TCOD_random_get_float, [ :pointer, :float, :float ], :float 455 | tcod_function :TCOD_random_get_double, [ :pointer, :double, :double ], :double 456 | tcod_function :TCOD_random_get_int_mean, [ :pointer, :int, :int, :int ], :int 457 | tcod_function :TCOD_random_get_float_mean, [ :pointer, :float, :float, :float ], :float 458 | tcod_function :TCOD_random_get_double_mean, [ :pointer, :double, :double, :double ], :double 459 | tcod_function :TCOD_random_dice_new, [ :string ], Dice.val 460 | tcod_function :TCOD_random_dice_roll, [ :pointer, Dice.val ], :int 461 | tcod_function :TCOD_random_dice_roll_s, [ :pointer, :string ], :int 462 | 463 | ### Noise module 464 | NOISE_DEFAULT_HURST = 0.5 465 | NOISE_DEFAULT_LACUNARITY = 2.0 466 | 467 | NOISE_DEFAULT = 0 468 | NOISE_PERLIN = 1 469 | NOISE_SIMPLEX = 2 470 | NOISE_WAVELET = 4 471 | 472 | tcod_function :TCOD_noise_new, [ :int, :float, :float, TCOD_random_t ], :pointer 473 | tcod_function :TCOD_noise_set_type, [ :pointer, :int ], :void 474 | tcod_function :TCOD_noise_get_ex, [ :pointer, :pointer, :int ], :float 475 | tcod_function :TCOD_noise_get_fbm_ex, [ :pointer, :pointer, :float, :int ], :float 476 | tcod_function :TCOD_noise_get_turbulence_ex, [ :pointer, :pointer, :float, :int ], :float 477 | tcod_function :TCOD_noise_get, [ :pointer, :pointer ], :float 478 | tcod_function :TCOD_noise_get_fbm, [ :pointer, :pointer, :float ], :float 479 | tcod_function :TCOD_noise_get_turbulence, [ :pointer, :pointer, :float ], :float 480 | tcod_function :TCOD_noise_delete, [ :pointer ], :void 481 | 482 | ### FOV module 483 | FOV_BASIC = 0 484 | FOV_DIAMOND = 1 485 | FOV_SHADOW = 2 486 | FOV_PERMISSIVE_0 = 3 487 | FOV_PERMISSIVE_1 = 4 488 | FOV_PERMISSIVE_2 = 5 489 | FOV_PERMISSIVE_3 = 6 490 | FOV_PERMISSIVE_4 = 7 491 | FOV_PERMISSIVE_5 = 8 492 | FOV_PERMISSIVE_6 = 9 493 | FOV_PERMISSIVE_7 = 10 494 | FOV_PERMISSIVE_8 = 11 495 | FOV_RESTRICTIVE = 12 496 | NB_FOV_ALGORITHMS = 13 497 | 498 | TCOD_fov_algorithm_t = :int 499 | 500 | tcod_function :TCOD_map_new, [ :int, :int ], :pointer 501 | tcod_function :TCOD_map_clear, [ :pointer, :bool, :bool ], :void 502 | tcod_function :TCOD_map_copy, [ :pointer, :pointer ], :void 503 | tcod_function :TCOD_map_set_properties, [ :pointer, :int, :int, :bool, :bool ], :void 504 | tcod_function :TCOD_map_delete, [ :pointer ], :void 505 | tcod_function :TCOD_map_compute_fov, [ :pointer, :int, :int, :int, :bool, TCOD_fov_algorithm_t ], :void 506 | tcod_function :TCOD_map_is_in_fov, [ :pointer, :int, :int ], :bool 507 | tcod_function :TCOD_map_set_in_fov, [ :pointer, :int, :int, :bool ], :void 508 | tcod_function :TCOD_map_is_transparent, [ :pointer, :int, :int ], :bool 509 | tcod_function :TCOD_map_is_walkable, [ :pointer, :int, :int ], :bool 510 | tcod_function :TCOD_map_get_width, [ :pointer ], :int 511 | tcod_function :TCOD_map_get_height, [ :pointer ], :int 512 | tcod_function :TCOD_map_get_nb_cells, [ :pointer ], :int 513 | 514 | ### Pathfinding module 515 | TCOD_map_t = :pointer 516 | 517 | callback(:TCOD_path_func_t, [ :int, :int, :int, :int, :pointer ], :float) 518 | tcod_function :TCOD_path_new_using_map, [ TCOD_map_t, :float ], :pointer 519 | tcod_function :TCOD_path_new_using_function, [ :int, :int, :TCOD_path_func_t, :pointer, :float ], :pointer 520 | tcod_function :TCOD_path_compute, [ :pointer, :int, :int, :int, :int ], :bool 521 | tcod_function :TCOD_path_walk, [ :pointer, :pointer, :pointer, :bool ], :bool 522 | tcod_function :TCOD_path_is_empty, [ :pointer ], :bool 523 | tcod_function :TCOD_path_size, [ :pointer ], :int 524 | tcod_function :TCOD_path_reverse, [ :pointer ], :void 525 | tcod_function :TCOD_path_get, [ :pointer, :int, :pointer, :pointer ], :void 526 | tcod_function :TCOD_path_get_origin, [ :pointer, :pointer, :pointer ], :void 527 | tcod_function :TCOD_path_get_destination, [ :pointer, :pointer, :pointer ], :void 528 | tcod_function :TCOD_path_delete, [ :pointer ], :void 529 | tcod_function :TCOD_dijkstra_new, [ TCOD_map_t, :float ], :pointer 530 | tcod_function :TCOD_dijkstra_new_using_function, [ :int, :int, :TCOD_path_func_t, :pointer, :float ], :pointer 531 | tcod_function :TCOD_dijkstra_compute, [ :pointer, :int, :int ], :void 532 | tcod_function :TCOD_dijkstra_get_distance, [ :pointer, :int, :int ], :float 533 | tcod_function :TCOD_dijkstra_path_set, [ :pointer, :int, :int ], :bool 534 | tcod_function :TCOD_dijkstra_is_empty, [ :pointer ], :bool 535 | tcod_function :TCOD_dijkstra_size, [ :pointer ], :int 536 | tcod_function :TCOD_dijkstra_reverse, [ :pointer ], :void 537 | tcod_function :TCOD_dijkstra_get, [ :pointer, :int, :pointer, :pointer ], :void 538 | tcod_function :TCOD_dijkstra_path_walk, [ :pointer, :pointer, :pointer ], :bool 539 | tcod_function :TCOD_dijkstra_delete, [ :pointer ], :void 540 | 541 | ### BSP module 542 | class TCODTreeT < FFI::Struct 543 | layout( 544 | :next, :pointer, 545 | :father, :pointer, 546 | :sons, :pointer 547 | ) 548 | end 549 | tcod_function :TCOD_tree_new, [ ], :pointer 550 | tcod_function :TCOD_tree_add_son, [ :pointer, :pointer ], :void 551 | 552 | 553 | class TCODBspT < MethodStruct 554 | layout( 555 | :tree, TCODTreeT, 556 | :x, :int, 557 | :y, :int, 558 | :w, :int, 559 | :h, :int, 560 | :position, :int, 561 | :level, :uint8, 562 | :horizontal, :bool 563 | ) 564 | end 565 | callback(:TCOD_bsp_callback_t, [ :pointer, :pointer ], :bool) 566 | tcod_function :TCOD_bsp_new, [ ], :pointer 567 | tcod_function :TCOD_bsp_new_with_size, [ :int, :int, :int, :int ], :pointer 568 | tcod_function :TCOD_bsp_delete, [ :pointer ], :void 569 | tcod_function :TCOD_bsp_left, [ :pointer ], :pointer 570 | tcod_function :TCOD_bsp_right, [ :pointer ], :pointer 571 | tcod_function :TCOD_bsp_father, [ :pointer ], :pointer 572 | tcod_function :TCOD_bsp_is_leaf, [ :pointer ], :bool 573 | tcod_function :TCOD_bsp_traverse_pre_order, [ :pointer, :TCOD_bsp_callback_t, :pointer ], :bool 574 | tcod_function :TCOD_bsp_traverse_in_order, [ :pointer, :TCOD_bsp_callback_t, :pointer ], :bool 575 | tcod_function :TCOD_bsp_traverse_post_order, [ :pointer, :TCOD_bsp_callback_t, :pointer ], :bool 576 | tcod_function :TCOD_bsp_traverse_level_order, [ :pointer, :TCOD_bsp_callback_t, :pointer ], :bool 577 | tcod_function :TCOD_bsp_traverse_inverted_level_order, [ :pointer, :TCOD_bsp_callback_t, :pointer ], :bool 578 | tcod_function :TCOD_bsp_contains, [ :pointer, :int, :int ], :bool 579 | tcod_function :TCOD_bsp_find_node, [ :pointer, :int, :int ], :pointer 580 | tcod_function :TCOD_bsp_resize, [ :pointer, :int, :int, :int, :int ], :void 581 | tcod_function :TCOD_bsp_split_once, [ :pointer, :bool, :int ], :void 582 | tcod_function :TCOD_bsp_split_recursive, [ :pointer, TCOD_random_t, :int, :int, :int, :float, :float ], :void 583 | tcod_function :TCOD_bsp_remove_sons, [ :pointer ], :void 584 | 585 | ### Heightmap module 586 | class TCODHeightmapT < MethodStruct 587 | layout( 588 | :w, :int, 589 | :h, :int, 590 | :values, :pointer 591 | ) 592 | end 593 | 594 | TCOD_noise_t = :pointer 595 | float_3 = :pointer # float n[3] 596 | int_4 = :pointer 597 | 598 | tcod_function :TCOD_heightmap_new, [ :int, :int ], :pointer 599 | tcod_function :TCOD_heightmap_delete, [ :pointer ], :void 600 | tcod_function :TCOD_heightmap_get_value, [ :pointer, :int, :int ], :float 601 | tcod_function :TCOD_heightmap_get_interpolated_value, [ :pointer, :float, :float ], :float 602 | tcod_function :TCOD_heightmap_set_value, [ :pointer, :int, :int, :float ], :void 603 | tcod_function :TCOD_heightmap_get_slope, [ :pointer, :int, :int ], :float 604 | tcod_function :TCOD_heightmap_get_normal, [ :pointer, :float, :float, float_3, :float ], :void 605 | tcod_function :TCOD_heightmap_count_cells, [ :pointer, :float, :float ], :int 606 | tcod_function :TCOD_heightmap_has_land_on_border, [ :pointer, :float ], :bool 607 | tcod_function :TCOD_heightmap_get_minmax, [ :pointer, :pointer, :pointer ], :void 608 | tcod_function :TCOD_heightmap_copy, [ :pointer, :pointer ], :void 609 | tcod_function :TCOD_heightmap_add, [ :pointer, :float ], :void 610 | tcod_function :TCOD_heightmap_scale, [ :pointer, :float ], :void 611 | tcod_function :TCOD_heightmap_clamp, [ :pointer, :float, :float ], :void 612 | tcod_function :TCOD_heightmap_normalize, [ :pointer, :float, :float ], :void 613 | tcod_function :TCOD_heightmap_clear, [ :pointer ], :void 614 | tcod_function :TCOD_heightmap_lerp_hm, [ :pointer, :pointer, :pointer, :float ], :void 615 | tcod_function :TCOD_heightmap_add_hm, [ :pointer, :pointer, :pointer ], :void 616 | tcod_function :TCOD_heightmap_multiply_hm, [ :pointer, :pointer, :pointer ], :void 617 | tcod_function :TCOD_heightmap_add_hill, [ :pointer, :float, :float, :float, :float ], :void 618 | tcod_function :TCOD_heightmap_dig_hill, [ :pointer, :float, :float, :float, :float ], :void 619 | tcod_function :TCOD_heightmap_dig_bezier, [ :pointer, int_4, int_4, :float, :float, :float, :float ], :void 620 | tcod_function :TCOD_heightmap_rain_erosion, [ :pointer, :int, :float, :float, TCOD_random_t ], :void 621 | tcod_function :TCOD_heightmap_kernel_transform, [ :pointer, :int, :pointer, :pointer, :pointer, :float, :float ], :void 622 | tcod_function :TCOD_heightmap_add_voronoi, [ :pointer, :int, :int, :pointer, TCOD_random_t ], :void 623 | tcod_function :TCOD_heightmap_add_fbm, [ :pointer, TCOD_noise_t, :float, :float, :float, :float, :float, :float, :float ], :void 624 | tcod_function :TCOD_heightmap_scale_fbm, [ :pointer, TCOD_noise_t, :float, :float, :float, :float, :float, :float, :float ], :void 625 | tcod_function :TCOD_heightmap_islandify, [ :pointer, :float, TCOD_random_t ], :void 626 | 627 | 628 | ### Name Generator module 629 | tcod_function :TCOD_namegen_parse, [ :string, TCOD_random_t ], :void 630 | tcod_function :TCOD_namegen_generate, [ :string, :bool ], :string 631 | tcod_function :TCOD_namegen_generate_custom, [ :string, :string, :bool ], :string 632 | tcod_function :TCOD_namegen_get_sets, [ ], TCOD_list_t 633 | tcod_function :TCOD_namegen_destroy, [ ], :void 634 | end 635 | -------------------------------------------------------------------------------- /lib/libtcod/cell.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Cell 3 | attr_reader :glyph, :fore_color, :back_color 4 | 5 | def initialize(glyph, fore_color, back_color) 6 | @glyph = glyph.ord 7 | @fore_color = fore_color 8 | @back_color = back_color 9 | end 10 | 11 | def ==(other) 12 | other.glyph == @glyph && 13 | other.fore_color == @fore_color && 14 | other.back_color == @back_color 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/libtcod/color.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Color < MethodStruct 3 | layout :r, :uchar, 4 | :g, :uchar, 5 | :b, :uchar 6 | 7 | def self.rgb(red, green, blue) 8 | TCOD.color_RGB(clamp(0, red, 255), 9 | clamp(0, green, 255), 10 | clamp(0, blue, 255)) 11 | end 12 | 13 | def self.hsv(h,s,v) 14 | TCOD.color_HSV(h,s,v) 15 | end 16 | 17 | def self.clamp(lower_bound, color_component, upper_bound) 18 | [lower_bound, [color_component, upper_bound].min].max 19 | end 20 | 21 | def ==(col) 22 | TCOD.color_equals(self, col) 23 | end 24 | 25 | def +(other) 26 | Color.rgb(red + other.red, green + other.green, blue + other.blue) 27 | end 28 | 29 | def -(other) 30 | Color.rgb(red - other.red, green - other.green, blue - other.blue) 31 | end 32 | 33 | def *(col_or_float) 34 | if col_or_float.is_a? Color 35 | TCOD.color_multiply(self, col_or_float) 36 | else 37 | TCOD.color_multiply_scalar(self, col_or_float) 38 | end 39 | end 40 | 41 | def to_s 42 | "" 43 | end 44 | 45 | def to_a 46 | [red, green, blue] 47 | end 48 | 49 | def red=(new_red) 50 | self[:r] = Color.clamp(0, new_red, 255) 51 | end 52 | 53 | def green=(new_green) 54 | self[:g] = Color.clamp(0, new_green, 255) 55 | end 56 | 57 | def blue=(new_blue) 58 | self[:b] = Color.clamp(0, new_blue, 255) 59 | end 60 | 61 | def hue 62 | TCOD.color_get_hue(self) 63 | end 64 | 65 | def hue=(new_hue) 66 | TCOD.color_set_hue(self, new_hue) 67 | end 68 | 69 | def value 70 | TCOD.color_get_value(self) 71 | end 72 | 73 | def value=(new_value) 74 | TCOD.color_set_value(self, new_value) 75 | end 76 | 77 | def saturation 78 | TCOD.color_get_saturation 79 | end 80 | 81 | def saturation=(new_saturation) 82 | TCOD.color_set_saturation(self, new_saturation) 83 | end 84 | 85 | alias_method :red, :r 86 | alias_method :green, :g 87 | alias_method :blue, :b 88 | alias_method :r=, :red= 89 | alias_method :g=, :green= 90 | alias_method :b=, :blue= 91 | 92 | alias_method :h, :hue 93 | alias_method :s, :saturation 94 | alias_method :v, :value 95 | alias_method :h=, :hue= 96 | alias_method :s=, :saturation= 97 | alias_method :v=, :value= 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /lib/libtcod/color_consts.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Color 3 | # default colors 4 | # grey levels 5 | BLACK=Color.rgb(0,0,0) 6 | DARKEST_GREY=Color.rgb(31,31,31) 7 | DARKER_GREY=Color.rgb(63,63,63) 8 | DARK_GREY=Color.rgb(95,95,95) 9 | GREY=Color.rgb(127,127,127) 10 | LIGHT_GREY=Color.rgb(159,159,159) 11 | LIGHTER_GREY=Color.rgb(191,191,191) 12 | LIGHTEST_GREY=Color.rgb(223,223,223) 13 | DARKEST_GRAY=Color.rgb(31,31,31) 14 | DARKER_GRAY=Color.rgb(63,63,63) 15 | DARK_GRAY=Color.rgb(95,95,95) 16 | GRAY=Color.rgb(127,127,127) 17 | LIGHT_GRAY=Color.rgb(159,159,159) 18 | LIGHTER_GRAY=Color.rgb(191,191,191) 19 | LIGHTEST_GRAY=Color.rgb(223,223,223) 20 | WHITE=Color.rgb(255,255,255) 21 | 22 | # sepia 23 | DARKEST_SEPIA=Color.rgb(31,24,15) 24 | DARKER_SEPIA=Color.rgb(63,50,31) 25 | DARK_SEPIA=Color.rgb(94,75,47) 26 | SEPIA=Color.rgb(127,101,63) 27 | LIGHT_SEPIA=Color.rgb(158,134,100) 28 | LIGHTER_SEPIA=Color.rgb(191,171,143) 29 | LIGHTEST_SEPIA=Color.rgb(222,211,195) 30 | 31 | #standard colors 32 | RED=Color.rgb(255,0,0) 33 | FLAME=Color.rgb(255,63,0) 34 | ORANGE=Color.rgb(255,127,0) 35 | AMBER=Color.rgb(255,191,0) 36 | YELLOW=Color.rgb(255,255,0) 37 | LIME=Color.rgb(191,255,0) 38 | CHARTREUSE=Color.rgb(127,255,0) 39 | GREEN=Color.rgb(0,255,0) 40 | SEA=Color.rgb(0,255,127) 41 | TURQUOISE=Color.rgb(0,255,191) 42 | CYAN=Color.rgb(0,255,255) 43 | SKY=Color.rgb(0,191,255) 44 | AZURE=Color.rgb(0,127,255) 45 | BLUE=Color.rgb(0,0,255) 46 | HAN=Color.rgb(63,0,255) 47 | VIOLET=Color.rgb(127,0,255) 48 | PURPLE=Color.rgb(191,0,255) 49 | FUCHSIA=Color.rgb(255,0,255) 50 | MAGENTA=Color.rgb(255,0,191) 51 | PINK=Color.rgb(255,0,127) 52 | CRIMSON=Color.rgb(255,0,63) 53 | 54 | # dark colors 55 | DARK_RED=Color.rgb(191,0,0) 56 | DARK_FLAME=Color.rgb(191,47,0) 57 | DARK_ORANGE=Color.rgb(191,95,0) 58 | DARK_AMBER=Color.rgb(191,143,0) 59 | DARK_YELLOW=Color.rgb(191,191,0) 60 | DARK_LIME=Color.rgb(143,191,0) 61 | DARK_CHARTREUSE=Color.rgb(95,191,0) 62 | DARK_GREEN=Color.rgb(0,191,0) 63 | DARK_SEA=Color.rgb(0,191,95) 64 | DARK_TURQUOISE=Color.rgb(0,191,143) 65 | DARK_CYAN=Color.rgb(0,191,191) 66 | DARK_SKY=Color.rgb(0,143,191) 67 | DARK_AZURE=Color.rgb(0,95,191) 68 | DARK_BLUE=Color.rgb(0,0,191) 69 | DARK_HAN=Color.rgb(47,0,191) 70 | DARK_VIOLET=Color.rgb(95,0,191) 71 | DARK_PURPLE=Color.rgb(143,0,191) 72 | DARK_FUCHSIA=Color.rgb(191,0,191) 73 | DARK_MAGENTA=Color.rgb(191,0,143) 74 | DARK_PINK=Color.rgb(191,0,95) 75 | DARK_CRIMSON=Color.rgb(191,0,47) 76 | 77 | # darker colors 78 | DARKER_RED=Color.rgb(127,0,0) 79 | DARKER_FLAME=Color.rgb(127,31,0) 80 | DARKER_ORANGE=Color.rgb(127,63,0) 81 | DARKER_AMBER=Color.rgb(127,95,0) 82 | DARKER_YELLOW=Color.rgb(127,127,0) 83 | DARKER_LIME=Color.rgb(95,127,0) 84 | DARKER_CHARTREUSE=Color.rgb(63,127,0) 85 | DARKER_GREEN=Color.rgb(0,127,0) 86 | DARKER_SEA=Color.rgb(0,127,63) 87 | DARKER_TURQUOISE=Color.rgb(0,127,95) 88 | DARKER_CYAN=Color.rgb(0,127,127) 89 | DARKER_SKY=Color.rgb(0,95,127) 90 | DARKER_AZURE=Color.rgb(0,63,127) 91 | DARKER_BLUE=Color.rgb(0,0,127) 92 | DARKER_HAN=Color.rgb(31,0,127) 93 | DARKER_VIOLET=Color.rgb(63,0,127) 94 | DARKER_PURPLE=Color.rgb(95,0,127) 95 | DARKER_FUCHSIA=Color.rgb(127,0,127) 96 | DARKER_MAGENTA=Color.rgb(127,0,95) 97 | DARKER_PINK=Color.rgb(127,0,63) 98 | DARKER_CRIMSON=Color.rgb(127,0,31) 99 | 100 | # darkest colors 101 | DARKEST_RED=Color.rgb(63,0,0) 102 | DARKEST_FLAME=Color.rgb(63,15,0) 103 | DARKEST_ORANGE=Color.rgb(63,31,0) 104 | DARKEST_AMBER=Color.rgb(63,47,0) 105 | DARKEST_YELLOW=Color.rgb(63,63,0) 106 | DARKEST_LIME=Color.rgb(47,63,0) 107 | DARKEST_CHARTREUSE=Color.rgb(31,63,0) 108 | DARKEST_GREEN=Color.rgb(0,63,0) 109 | DARKEST_SEA=Color.rgb(0,63,31) 110 | DARKEST_TURQUOISE=Color.rgb(0,63,47) 111 | DARKEST_CYAN=Color.rgb(0,63,63) 112 | DARKEST_SKY=Color.rgb(0,47,63) 113 | DARKEST_AZURE=Color.rgb(0,31,63) 114 | DARKEST_BLUE=Color.rgb(0,0,63) 115 | DARKEST_HAN=Color.rgb(15,0,63) 116 | DARKEST_VIOLET=Color.rgb(31,0,63) 117 | DARKEST_PURPLE=Color.rgb(47,0,63) 118 | DARKEST_FUCHSIA=Color.rgb(63,0,63) 119 | DARKEST_MAGENTA=Color.rgb(63,0,47) 120 | DARKEST_PINK=Color.rgb(63,0,31) 121 | DARKEST_CRIMSON=Color.rgb(63,0,15) 122 | 123 | # light colors 124 | LIGHT_RED=Color.rgb(255,114,114) 125 | LIGHT_FLAME=Color.rgb(255,149,114) 126 | LIGHT_ORANGE=Color.rgb(255,184,114) 127 | LIGHT_AMBER=Color.rgb(255,219,114) 128 | LIGHT_YELLOW=Color.rgb(255,255,114) 129 | LIGHT_LIME=Color.rgb(219,255,114) 130 | LIGHT_CHARTREUSE=Color.rgb(184,255,114) 131 | LIGHT_GREEN=Color.rgb(114,255,114) 132 | LIGHT_SEA=Color.rgb(114,255,184) 133 | LIGHT_TURQUOISE=Color.rgb(114,255,219) 134 | LIGHT_CYAN=Color.rgb(114,255,255) 135 | LIGHT_SKY=Color.rgb(114,219,255) 136 | LIGHT_AZURE=Color.rgb(114,184,255) 137 | LIGHT_BLUE=Color.rgb(114,114,255) 138 | LIGHT_HAN=Color.rgb(149,114,255) 139 | LIGHT_VIOLET=Color.rgb(184,114,255) 140 | LIGHT_PURPLE=Color.rgb(219,114,255) 141 | LIGHT_FUCHSIA=Color.rgb(255,114,255) 142 | LIGHT_MAGENTA=Color.rgb(255,114,219) 143 | LIGHT_PINK=Color.rgb(255,114,184) 144 | LIGHT_CRIMSON=Color.rgb(255,114,149) 145 | 146 | #lighter colors 147 | LIGHTER_RED=Color.rgb(255,165,165) 148 | LIGHTER_FLAME=Color.rgb(255,188,165) 149 | LIGHTER_ORANGE=Color.rgb(255,210,165) 150 | LIGHTER_AMBER=Color.rgb(255,232,165) 151 | LIGHTER_YELLOW=Color.rgb(255,255,165) 152 | LIGHTER_LIME=Color.rgb(232,255,165) 153 | LIGHTER_CHARTREUSE=Color.rgb(210,255,165) 154 | LIGHTER_GREEN=Color.rgb(165,255,165) 155 | LIGHTER_SEA=Color.rgb(165,255,210) 156 | LIGHTER_TURQUOISE=Color.rgb(165,255,232) 157 | LIGHTER_CYAN=Color.rgb(165,255,255) 158 | LIGHTER_SKY=Color.rgb(165,232,255) 159 | LIGHTER_AZURE=Color.rgb(165,210,255) 160 | LIGHTER_BLUE=Color.rgb(165,165,255) 161 | LIGHTER_HAN=Color.rgb(188,165,255) 162 | LIGHTER_VIOLET=Color.rgb(210,165,255) 163 | LIGHTER_PURPLE=Color.rgb(232,165,255) 164 | LIGHTER_FUCHSIA=Color.rgb(255,165,255) 165 | LIGHTER_MAGENTA=Color.rgb(255,165,232) 166 | LIGHTER_PINK=Color.rgb(255,165,210) 167 | LIGHTER_CRIMSON=Color.rgb(255,165,188) 168 | 169 | # lightest colors 170 | LIGHTEST_RED=Color.rgb(255,191,191) 171 | LIGHTEST_FLAME=Color.rgb(255,207,191) 172 | LIGHTEST_ORANGE=Color.rgb(255,223,191) 173 | LIGHTEST_AMBER=Color.rgb(255,239,191) 174 | LIGHTEST_YELLOW=Color.rgb(255,255,191) 175 | LIGHTEST_LIME=Color.rgb(239,255,191) 176 | LIGHTEST_CHARTREUSE=Color.rgb(223,255,191) 177 | LIGHTEST_GREEN=Color.rgb(191,255,191) 178 | LIGHTEST_SEA=Color.rgb(191,255,223) 179 | LIGHTEST_TURQUOISE=Color.rgb(191,255,239) 180 | LIGHTEST_CYAN=Color.rgb(191,255,255) 181 | LIGHTEST_SKY=Color.rgb(191,239,255) 182 | LIGHTEST_AZURE=Color.rgb(191,223,255) 183 | LIGHTEST_BLUE=Color.rgb(191,191,255) 184 | LIGHTEST_HAN=Color.rgb(207,191,255) 185 | LIGHTEST_VIOLET=Color.rgb(223,191,255) 186 | LIGHTEST_PURPLE=Color.rgb(239,191,255) 187 | LIGHTEST_FUCHSIA=Color.rgb(255,191,255) 188 | LIGHTEST_MAGENTA=Color.rgb(255,191,239) 189 | LIGHTEST_PINK=Color.rgb(255,191,223) 190 | LIGHTEST_CRIMSON=Color.rgb(255,191,207) 191 | 192 | # desaturated colors 193 | DESATURATED_RED=Color.rgb(127,63,63) 194 | DESATURATED_FLAME=Color.rgb(127,79,63) 195 | DESATURATED_ORANGE=Color.rgb(127,95,63) 196 | DESATURATED_AMBER=Color.rgb(127,111,63) 197 | DESATURATED_YELLOW=Color.rgb(127,127,63) 198 | DESATURATED_LIME=Color.rgb(111,127,63) 199 | DESATURATED_CHARTREUSE=Color.rgb(95,127,63) 200 | DESATURATED_GREEN=Color.rgb(63,127,63) 201 | DESATURATED_SEA=Color.rgb(63,127,95) 202 | DESATURATED_TURQUOISE=Color.rgb(63,127,111) 203 | DESATURATED_CYAN=Color.rgb(63,127,127) 204 | DESATURATED_SKY=Color.rgb(63,111,127) 205 | DESATURATED_AZURE=Color.rgb(63,95,127) 206 | DESATURATED_BLUE=Color.rgb(63,63,127) 207 | DESATURATED_HAN=Color.rgb(79,63,127) 208 | DESATURATED_VIOLET=Color.rgb(95,63,127) 209 | DESATURATED_PURPLE=Color.rgb(111,63,127) 210 | DESATURATED_FUCHSIA=Color.rgb(127,63,127) 211 | DESATURATED_MAGENTA=Color.rgb(127,63,111) 212 | DESATURATED_PINK=Color.rgb(127,63,95) 213 | DESATURATED_CRIMSON=Color.rgb(127,63,79) 214 | 215 | # metallic 216 | BRASS=Color.rgb(191,151,96) 217 | COPPER=Color.rgb(197,136,124) 218 | GOLD=Color.rgb(229,191,0) 219 | SILVER=Color.rgb(203,203,203) 220 | 221 | # miscellaneous 222 | CELADON=Color.rgb(172,255,175) 223 | PEACH=Color.rgb(255,159,127) 224 | end 225 | end 226 | -------------------------------------------------------------------------------- /lib/libtcod/console.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Console 3 | attr_accessor :width, :height, :ptr 4 | 5 | def self.root 6 | @instance = new RootConsole 7 | end 8 | 9 | def initialize(width, height) 10 | @width = w 11 | @height = h 12 | @ptr = TCOD.console_new(w, h) 13 | 14 | # Note: We don't need to define a finalizer for the root console! 15 | ObjectSpace.define_finalizer(self, self.class.finalize(ptr)) 16 | end 17 | 18 | def root? 19 | false 20 | end 21 | 22 | def set_default_background(color) 23 | TCOD.console_set_default_background(@ptr, color) 24 | end 25 | 26 | def set_default_foreground(color) 27 | TCOD.console_set_default_foreground(@ptr, color) 28 | end 29 | 30 | def clear 31 | TCOD.console_clear(@ptr) 32 | end 33 | 34 | def set_char_background(x, y, col, flag=TCOD::BKGND_SET) 35 | TCOD.console_set_char_background(@ptr, x, y, col, flag) 36 | end 37 | 38 | def set_char_foreground(x, y, col) 39 | TCOD.console_set_char_foreground(@ptr, x, y, col) 40 | end 41 | 42 | def put_char(x, y, c, flag=BKGND_DEFAULT) 43 | TCOD.console_put_char(@ptr, x, y, c.ord, flag) 44 | end 45 | 46 | def put_char_ex(x, y, c, foreground, background) 47 | TCOD.console_put_char_ex(@ptr, x, y, c.ord, foreground, background) 48 | end 49 | 50 | def set_background_flag(bkgnd_flag) 51 | TCOD.console_set_background_flag(@ptr, bkgnd_flag) 52 | end 53 | 54 | def set_alignment(alignment) 55 | TCOD.console_set_alignment(@ptr, alignment) 56 | end 57 | 58 | def print(x, y, fmt, *args) 59 | TCOD.console_print(@ptr, x, y, fmt, *args) 60 | end 61 | 62 | def print_ex(x, y, bkgnd_flag, alignment, fmt, *args) 63 | TCOD.console_print_ex(@ptr, x, y, bkgnd_flag, alignment, fmt, *args) 64 | end 65 | 66 | def print_rect(x, y, w, h, fmt, *args) 67 | TCOD.console_print_rect(@ptr, x, y, w, h, fmt, *args) 68 | end 69 | 70 | def print_rect_ex(x, y, w, h, bkgnd_flag, alignment, fmt, *args) 71 | TCOD.console_print_rect_ex(@ptr, x, y, w, h, bkgnf_flag, alignment, fmt, *args) 72 | end 73 | 74 | def flush 75 | TCOD.console_flush 76 | end 77 | 78 | def blit(src, xSrc, ySrc, wSrc, hSrc, xDst, yDst, foregroundAlpha=1.0, backgroundAlpha=1.0) 79 | TCOD.console_blit(src.ptr, xSrc, ySrc, wSrc, hSrc, @ptr, xDst, yDst, foregroundAlpha, backgroundAlpha) 80 | end 81 | 82 | def self.finalize(ptr) 83 | proc { TCOD.console_delete(ptr) } 84 | end 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /lib/libtcod/consts.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | # background rendering modes 3 | BKGND_NONE = 0 4 | BKGND_SET = 1 5 | BKGND_MULTIPLY = 2 6 | BKGND_LIGHTEN = 3 7 | BKGND_DARKEN = 4 8 | BKGND_SCREEN = 5 9 | BKGND_COLOR_DODGE = 6 10 | BKGND_COLOR_BURN = 7 11 | BKGND_ADD = 8 12 | BKGND_ADDA = 9 13 | BKGND_BURN = 10 14 | BKGND_OVERLAY = 11 15 | BKGND_ALPH = 12 16 | BKGND_DEFAULT=13 17 | 18 | # non blocking key events types 19 | KEY_PRESSED = 1 20 | KEY_RELEASED = 2 21 | 22 | # key codes 23 | KEY_NONE = 0 24 | KEY_ESCAPE = 1 25 | KEY_BACKSPACE = 2 26 | KEY_TAB = 3 27 | KEY_ENTER = 4 28 | KEY_SHIFT = 5 29 | KEY_CONTROL = 6 30 | KEY_ALT = 7 31 | KEY_PAUSE = 8 32 | KEY_CAPSLOCK = 9 33 | KEY_PAGEUP = 10 34 | KEY_PAGEDOWN = 11 35 | KEY_END = 12 36 | KEY_HOME = 13 37 | KEY_UP = 14 38 | KEY_LEFT = 15 39 | KEY_RIGHT = 16 40 | KEY_DOWN = 17 41 | KEY_PRINTSCREEN = 18 42 | KEY_INSERT = 19 43 | KEY_DELETE = 20 44 | KEY_LWIN = 21 45 | KEY_RWIN = 22 46 | KEY_APPS = 23 47 | KEY_0 = 24 48 | KEY_1 = 25 49 | KEY_2 = 26 50 | KEY_3 = 27 51 | KEY_4 = 28 52 | KEY_5 = 29 53 | KEY_6 = 30 54 | KEY_7 = 31 55 | KEY_8 = 32 56 | KEY_9 = 33 57 | KEY_KP0 = 34 58 | KEY_KP1 = 35 59 | KEY_KP2 = 36 60 | KEY_KP3 = 37 61 | KEY_KP4 = 38 62 | KEY_KP5 = 39 63 | KEY_KP6 = 40 64 | KEY_KP7 = 41 65 | KEY_KP8 = 42 66 | KEY_KP9 = 43 67 | KEY_KPADD = 44 68 | KEY_KPSUB = 45 69 | KEY_KPDIV = 46 70 | KEY_KPMUL = 47 71 | KEY_KPDEC = 48 72 | KEY_KPENTER = 49 73 | KEY_F1 = 50 74 | KEY_F2 = 51 75 | KEY_F3 = 52 76 | KEY_F4 = 53 77 | KEY_F5 = 54 78 | KEY_F6 = 55 79 | KEY_F7 = 56 80 | KEY_F8 = 57 81 | KEY_F9 = 58 82 | KEY_F10 = 59 83 | KEY_F11 = 60 84 | KEY_F12 = 61 85 | KEY_NUMLOCK = 62 86 | KEY_SCROLLLOCK = 63 87 | KEY_SPACE = 64 88 | KEY_CHAR = 65 89 | 90 | ### special chars 91 | 92 | # single walls 93 | CHAR_HLINE = 196 94 | CHAR_VLINE = 179 95 | CHAR_NE = 191 96 | CHAR_NW = 218 97 | CHAR_SE = 217 98 | CHAR_SW = 192 99 | CHAR_TEEW = 180 100 | CHAR_TEEE = 195 101 | CHAR_TEEN = 193 102 | CHAR_TEES = 194 103 | CHAR_CROSS = 197 104 | 105 | # double walls 106 | CHAR_DHLINE = 205 107 | CHAR_DVLINE = 186 108 | CHAR_DNE = 187 109 | CHAR_DNW = 201 110 | CHAR_DSE = 188 111 | CHAR_DSW = 200 112 | CHAR_DTEEW = 185 113 | CHAR_DTEEE = 204 114 | CHAR_DTEEN = 202 115 | CHAR_DTEES = 203 116 | CHAR_DCROSS = 206 117 | 118 | # blocks 119 | CHAR_BLOCK1 = 176 120 | CHAR_BLOCK2 = 177 121 | CHAR_BLOCK3 = 178 122 | 123 | # arrows 124 | CHAR_ARROW_N = 24 125 | CHAR_ARROW_S = 25 126 | CHAR_ARROW_E = 26 127 | CHAR_ARROW_W = 27 128 | 129 | # arrows without tail 130 | CHAR_ARROW2_N = 30 131 | CHAR_ARROW2_S = 31 132 | CHAR_ARROW2_E = 16 133 | CHAR_ARROW2_W = 17 134 | 135 | # double arrows 136 | CHAR_DARROW_H = 29 137 | CHAR_DARROW_V = 18 138 | 139 | # GUI stuff 140 | CHAR_CHECKBOX_UNSET = 224 141 | CHAR_CHECKBOX_SET = 225 142 | CHAR_RADIO_UNSET = 9 143 | CHAR_RADIO_SET = 10 144 | 145 | # sub-pixel resolution kit 146 | CHAR_SUBP_NW = 226 147 | CHAR_SUBP_NE = 227 148 | CHAR_SUBP_N = 228 149 | CHAR_SUBP_SE = 229 150 | CHAR_SUBP_DIAG = 230 151 | CHAR_SUBP_E = 231 152 | CHAR_SUBP_SW = 232 153 | 154 | # misc characters 155 | CHAR_BULLET = 7 156 | CHAR_BULLET_INV = 8 157 | CHAR_BULLET_SQUARE = 254 158 | CHAR_CENT = 189 159 | CHAR_CLUB = 5 160 | CHAR_COPYRIGHT = 184 161 | CHAR_CURRENCY = 207 162 | CHAR_DIAMOND = 4 163 | CHAR_DIVISION = 246 164 | CHAR_EXCLAM_DOUBLE = 19 165 | CHAR_FEMALE = 12 166 | CHAR_FUNCTION = 159 167 | CHAR_GRADE = 248 168 | CHAR_HALF = 171 169 | CHAR_HEART = 3 170 | CHAR_LIGHT = 15 171 | CHAR_MALE = 11 172 | CHAR_MULTIPLICATION = 158 173 | CHAR_NOTE = 13 174 | CHAR_NOTE_DOUBLE = 14 175 | CHAR_ONE_QUARTER = 172 176 | CHAR_PILCROW = 20 177 | CHAR_POUND = 156 178 | CHAR_POW1 = 251 179 | CHAR_POW2 = 253 180 | CHAR_POW3 = 252 181 | CHAR_RESERVED = 169 182 | CHAR_SECTION = 21 183 | CHAR_SMILIE = 1 184 | CHAR_SMILIE_INV = 2 185 | CHAR_SPADE = 6 186 | CHAR_THREE_QUARTERS = 243 187 | CHAR_UMLAUT = 249 188 | CHAR_YEN = 190 189 | 190 | # font flags 191 | FONT_LAYOUT_ASCII_INCOL = 1 192 | FONT_LAYOUT_ASCII_INROW = 2 193 | FONT_TYPE_GREYSCALE = 4 194 | FONT_TYPE_GRAYSCALE = 4 195 | FONT_LAYOUT_TCOD = 8 196 | 197 | # color control codes 198 | COLCTRL_1=1 199 | COLCTRL_2=2 200 | COLCTRL_3=3 201 | COLCTRL_4=4 202 | COLCTRL_5=5 203 | COLCTRL_NUMBER=5 204 | COLCTRL_FORE_RGB=6 205 | COLCTRL_BACK_RGB=7 206 | COLCTRL_STOP=8 207 | 208 | # renderers 209 | RENDERER_GLSL=0 210 | RENDERER_OPENGL=1 211 | RENDERER_SDL=2 212 | NB_RENDERERS=3 213 | 214 | # alignment 215 | LEFT=0 216 | RIGHT=1 217 | CENTER=2 218 | end 219 | -------------------------------------------------------------------------------- /lib/libtcod/coord.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Coord 3 | attr_reader :x, :y 4 | 5 | def initialize(x, y) 6 | @x = x 7 | @y = y 8 | end 9 | 10 | def ==(other) 11 | @x == other.x && @y == other.y 12 | end 13 | 14 | def +(other) 15 | Coord.new(@x + other.x, @y + other.y) 16 | end 17 | 18 | def -(other) 19 | Coord.new(@x - other.x, @y - other.y) 20 | end 21 | 22 | def to_s 23 | "p(#{x}, #{y})" 24 | end 25 | 26 | def to_a 27 | [x, y] 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/libtcod/map.rb: -------------------------------------------------------------------------------- 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 109 | -------------------------------------------------------------------------------- /lib/libtcod/rect.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class Rect 3 | attr_reader :position, :width, :height 4 | 5 | def initialize(position, width, height) 6 | if width < 1 7 | fail ArgumentError, 8 | "ArgumentError: Rect width must be strictly positive (#{width})" 9 | elsif height < 1 10 | fail ArgumentError, 11 | "ArgumentError: Rect height must be strictly positive (#{height})" 12 | end 13 | 14 | @position = position 15 | @width = width 16 | @height = height 17 | end 18 | 19 | def left 20 | @position.x 21 | end 22 | 23 | def right 24 | @position.x + width - 1 25 | end 26 | 27 | def top 28 | @position.y 29 | end 30 | 31 | def bottom 32 | @position.y + height - 1 33 | end 34 | 35 | def center 36 | [(right - left) / 2, (bottom - top) / 2] 37 | end 38 | 39 | def x_range 40 | left..right 41 | end 42 | 43 | def y_range 44 | top..bottom 45 | end 46 | 47 | def include?(coord) 48 | x_range.include?(coord.x) && y_range.include?(coord.y) 49 | end 50 | 51 | def ==(other) 52 | @position == other.position && 53 | @width == other.width && 54 | @height == other.height 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/libtcod/root_console.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | class RootConsole < Console 3 | private_class_method :new 4 | 5 | def initialize 6 | @width = System.screen_width 7 | @height = System.screen_height 8 | @ptr = nil 9 | end 10 | 11 | def root? 12 | true 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/libtcod/struct.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | # Wrapper for FFI::Struct which allows access of 3 | # properties by method as well as indexing. 4 | 5 | class MethodStruct < FFI::Struct 6 | class << self 7 | alias_method :old_layout, :layout 8 | 9 | def layout(*keys) 10 | old_layout(*keys) 11 | keys.each_slice(2).each do |key,type| 12 | define_method(key) do 13 | self[key] 14 | end 15 | end 16 | end 17 | end 18 | end 19 | 20 | class MethodUnion < FFI::Union 21 | class << self 22 | alias_method :old_layout, :layout 23 | 24 | def layout(*keys) 25 | old_layout(*keys) 26 | keys.each_slice(2).each do |key,type| 27 | define_method(key) do 28 | self[key] 29 | end 30 | end 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/libtcod/system.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | module System 3 | def self.register_sdl_renderer(&b) 4 | TCOD.sys_register_SDL_renderer(&b) 5 | end 6 | 7 | def self.screen_width 8 | @screen_width 9 | end 10 | 11 | def self.screen_height 12 | @screen_height 13 | end 14 | 15 | def self.init_tcod(options = {}) 16 | @screen_width = options.fetch(:width, 80) 17 | @screen_height = options.fetch(:height, 25) 18 | @title = options.fetch(:title, '') 19 | fullscreen = options.fetch(:fullscreen, false) 20 | renderer = options.fetch(:renderer, RENDERER_SDL) 21 | 22 | TCOD.console_init_root(@screen_width, 23 | @screen_height, 24 | @title, 25 | fullscreen, 26 | renderer) 27 | end 28 | 29 | def self.title 30 | @title 31 | end 32 | 33 | def self.title=(new_title) 34 | @title = new_title 35 | TCOD.console_set_window_title(new_title) 36 | end 37 | 38 | def self.fullscreen? 39 | @fullscreen 40 | end 41 | 42 | def self.to_fullscreen 43 | @fullscreen = true 44 | TCOD.console_set_fullscreen(true) 45 | end 46 | 47 | def self.to_windowed 48 | @fullscreen = false 49 | TCOD.console_set_fullscreen(false) 50 | end 51 | 52 | def self.window_closed? 53 | TCOD.console_is_window_closed 54 | end 55 | 56 | def self.flush 57 | TCOD.console_flush 58 | end 59 | 60 | def self.check_for_keypress(flags = TCOD::KEY_PRESSED) 61 | TCOD.console_check_for_keypress(flags) 62 | end 63 | 64 | def self.wait_for_keypress(flush = false) 65 | TCOD.console_wait_for_keypress(flush) 66 | end 67 | 68 | def self.key_pressed?(keycode) 69 | TCOD.console_is_key_pressed(keycode) 70 | end 71 | 72 | def self.set_custom_font(font_file, flags, columns = 0, rows = 0) 73 | TCOD.console_set_custom_font(font_file, flags, columns, rows) 74 | end 75 | 76 | def self.map_ascii_code_to_font(ascii_code, coord) 77 | TCOD.console_map_ascii_code_to_font(ascii_code.ord, coord.x, coord.y) 78 | end 79 | 80 | def self.map_ascii_codes_to_font(ascii_code, n, offset) 81 | TCOD.console_map_ascii_code_to_font(ascii_code.ord, n, offset.x, offset.y) 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /lib/libtcod/version.rb: -------------------------------------------------------------------------------- 1 | module TCOD 2 | VERSION = "0.1.1" 3 | end 4 | -------------------------------------------------------------------------------- /libtcod.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/libtcod/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["Jaiden Mispy"] 6 | gem.email = ["mispy@staff.draftable.com"] 7 | gem.description = %q{Ruby bindings for the libtcod roguelike library} 8 | gem.summary = %q{Ruby bindings for the libtcod roguelike library} 9 | gem.homepage = "" 10 | 11 | gem.files = `git ls-files`.split($\) 12 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 13 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 14 | gem.name = "libtcod" 15 | gem.require_paths = ["lib"] 16 | gem.version = TCOD::VERSION 17 | 18 | gem.add_development_dependency 'minitest' 19 | 20 | gem.add_runtime_dependency 'ffi', '~> 1.9.3' 21 | end 22 | -------------------------------------------------------------------------------- /terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mispy-archive/libtcod/b4ae9da97495624340df60c2b234627fe44708ba/terminal.png -------------------------------------------------------------------------------- /test/color.rb: -------------------------------------------------------------------------------- 1 | require_relative 'helpers' 2 | require 'libtcod' 3 | require 'minitest/autorun' 4 | 5 | class TestColor < Minitest::Test 6 | def setup 7 | @c1 = TCOD::Color.rgb(255,0,1) 8 | @c2 = TCOD::Color.rgb(100,4,58) 9 | end 10 | 11 | def test_create_colors 12 | c = TCOD::Color.rgb(5,5,5) 13 | c2 = TCOD::Color.hsv(5,5,5) 14 | end 15 | 16 | def test_compare_colors 17 | c1 = TCOD::Color.rgb(2, 4, 8) 18 | c2 = TCOD::Color.rgb(2, 4, 8) 19 | c3 = TCOD::Color.rgb(8, 16, 32) 20 | assert_equal c1, c2 21 | refute_equal c1, c3 22 | end 23 | 24 | def test_multiply_colors 25 | c1 = TCOD::Color.rgb(55,100,250) 26 | c2 = TCOD::Color.rgb(70, 130, 224) 27 | c3 = c1 * c2 28 | assert_equal c3, TCOD::Color.rgb(15, 50, 219) 29 | end 30 | 31 | def test_multiply_colors_float 32 | c1 = TCOD::Color.rgb(55,100,250) 33 | c2 = c1*2 34 | assert_equal c2, TCOD::Color.rgb(110, 200, 255) 35 | end 36 | 37 | def test_adding_colors 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /test/console.rb: -------------------------------------------------------------------------------- 1 | require_relative 'helpers' 2 | require 'libtcod' 3 | require 'minitest/autorun' 4 | 5 | class TestConsole < Minitest::Test 6 | def setup 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/helpers.rb: -------------------------------------------------------------------------------- 1 | APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) 2 | $: << File.join(APP_ROOT, 'lib') 3 | --------------------------------------------------------------------------------