Skip to content

mispy-archive/libtcod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b4ae9da · Jul 19, 2015

History

52 Commits
Dec 20, 2014
Jun 23, 2013
Jul 19, 2015
Jul 2, 2015
Jun 1, 2013
Nov 5, 2014
May 30, 2013
May 30, 2013
Oct 20, 2014
May 30, 2013
May 12, 2014
May 31, 2013

Repository files navigation

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Ruby bindings for the libtcod roguelike library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages