Libtcod
Ruby bindings for the libtcod roguelike library
Install / Use
/learn @mispy-archive/LibtcodREADME
libtcod-ruby 0.1.1
Ruby bindings for libtcod 1.5.1
Currently tested using Ruby 1.9.3 on Linux, Windows and OS X (thanks to @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 closely. See the example for slight differences in invocation.
Installation
gem install libtcod
Examples
Here's a straight port of the example code from part 1 of the python tutorial:
require 'libtcod'
#actual size of the window
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
LIMIT_FPS = 20 #20 frames-per-second maximum
def handle_keys
#key = TCOD.console_check_for_keypress() #real-time
key = TCOD.console_wait_for_keypress(true) #turn-based
if key.vk == TCOD::KEY_ENTER && key.lalt
#Alt+Enter: toggle fullscreen
TCOD.console_set_fullscreen(!TCOD.console_is_fullscreen())
elsif key.vk == TCOD::KEY_ESCAPE
return true #exit game
end
#movement keys
if TCOD.console_is_key_pressed(TCOD::KEY_UP)
$playery -= 1
elsif TCOD.console_is_key_pressed(TCOD::KEY_DOWN)
$playery += 1
elsif TCOD.console_is_key_pressed(TCOD::KEY_LEFT)
$playerx -= 1
elsif TCOD.console_is_key_pressed(TCOD::KEY_RIGHT)
$playerx += 1
end
false
end
#############################################
# Initialization & Main Loop
#############################################
TCOD.console_set_custom_font('arial10x10.png', TCOD::FONT_TYPE_GREYSCALE | TCOD::FONT_LAYOUT_TCOD, 0, 0)
TCOD.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'ruby/TCOD tutorial', false, TCOD::RENDERER_SDL)
TCOD.sys_set_fps(LIMIT_FPS)
$playerx = SCREEN_WIDTH/2
$playery = SCREEN_HEIGHT/2
until TCOD.console_is_window_closed
TCOD.console_set_default_foreground(nil, TCOD::Color::WHITE)
TCOD.console_put_char(nil, $playerx, $playery, '@'.ord, TCOD::BKGND_NONE)
TCOD.console_flush()
TCOD.console_put_char(nil, $playerx, $playery, ' '.ord, TCOD::BKGND_NONE)
#handle keys and exit game if needed
will_exit = handle_keys
break if will_exit
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
