Roguelike project?

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

([email protected])

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

Interested in playing? Testing? Developing?
I’ve considered writing one at some point, but I’ve yet to make time
and figure out ncurses.

Matthew M. wrote:

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

Interested in playing? Testing? Developing?
I’ve considered writing one at some point, but I’ve yet to make time
and figure out ncurses.

Sorry: That would be interested in developing. I am novice-intermediate
when it comes to Ruby code, but I thought it would be fun to create a
Ruby roguelike.

Tim M. wrote:

Matthew M. wrote:

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

Interested in playing? Testing? Developing?
I’ve considered writing one at some point, but I’ve yet to make time
and figure out ncurses.

Sorry: That would be interested in developing. I am novice-intermediate
when it comes to Ruby code, but I thought it would be fun to create a
Ruby roguelike.

It would be fun, certainly. Recently, i wrote my first ncurses program,
a snakes game and it was great fun. Since then, I am working on a much
larger ncurses project - would have loved to work with you.

ncurses is pretty easy and fun - one problem i occasionally face is
getting the refreshes correct - otherwise its cool. Remember to wrap
your windows in panels, and its better not to use stdscr if you intend
having multiple pages/windows/levels - use panels.

Nit K. wrote:

Tim M. wrote:

Matthew M. wrote:

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

Interested in playing? Testing? Developing?
I’ve considered writing one at some point, but I’ve yet to make time
and figure out ncurses.

Sorry: That would be interested in developing. I am novice-intermediate
when it comes to Ruby code, but I thought it would be fun to create a
Ruby roguelike.

It would be fun, certainly. Recently, i wrote my first ncurses program,
a snakes game and it was great fun. Since then, I am working on a much
larger ncurses project - would have loved to work with you.

ncurses is pretty easy and fun - one problem i occasionally face is
getting the refreshes correct - otherwise its cool. Remember to wrap
your windows in panels, and its better not to use stdscr if you intend
having multiple pages/windows/levels - use panels.

Yeah, it’s tough finding proper ruby documentation on Ncurses. I’ve just
been using the Ncurses book linked at the ruby-ncurses site. That is
written for C coding tho, so it’s a bit hard porting it over. Panels?
Enlighten me please!

On Fri, Oct 31, 2008 at 3:42 AM, Matthew M. [email protected] wrote:

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

Interested in playing? Testing? Developing?
I’ve considered writing one at some point, but I’ve yet to make time and
figure out ncurses.

esp:
http://github.com/manveru/ver/tree/master/lib/ver/keyboard.rb
http://github.com/manveru/ver/tree/master/lib/ver/window.rb
http://github.com/manveru/ver/tree/master/lib/ver/ncurses.rb

I wrote a rougelike in ruby+ncurses, but the source isn’t online
anymore, i can send you if you like :slight_smile:

^ manveru

Michael F. wrote:

GitHub - manveru/ver: Vi & Emacs in Ruby

esp:
http://github.com/manveru/ver/tree/master/lib/ver/keyboard.rb
http://github.com/manveru/ver/tree/master/lib/ver/window.rb
http://github.com/manveru/ver/tree/master/lib/ver/ncurses.rb

I wrote a rougelike in ruby+ncurses, but the source isn’t online
anymore, i can send you if you like :slight_smile:

^ manveru

Thanks manveru - could you tell me what keyboard.rb does in a nutshell.
I simply bind keys using the “?\C-a” kind of notation to symbols or
procs.

I read your comment in window.rb of the bug that doesnt let you subclass
window. I had a long discussion on this here, i was trying to subclass
Form, iirc. Finally, someone said that the constructor was “shadowed”,
so one cannot make another one (I cannot recall the exact words), or
maybe it was private. So i too had wrapped and delegated like you have.

Tim M. wrote:

Nit K. wrote:

Tim M. wrote:

Matthew M. wrote:
Yeah, it’s tough finding proper ruby documentation on Ncurses. I’ve just
been using the Ncurses book linked at the ruby-ncurses site. That is
written for C coding tho, so it’s a bit hard porting it over. Panels?
Enlighten me please!

  1. The only documentation on ncurses-ruby is the README file the author
    gives.
  2. The only documentation on ncurses is a large file with sample C
    program by one
    Pradeep Padala which comes up on searching google. It is pretty
    comprehensive but mainly examples - no real-world stuff.
  3. Usually, I just grep thru the source, esp form_wrap.c and ncurses.rb.
  4. Another useful source is “man” (if you are using *nix). This can give
    you
    explanations of methods. I use it quite a bit.

Forgive my cut-pasting from “man panel” - will explain after:

Panels are curses(3X) windows with the added feature of depth.
Panel functions allow the use of stacked windows and ensure the
proper portions of each window and the curses stdscr window are hidden
or displayed when panels are added, moved, modified or removed. The set
of currently visible panels is the stack of panels. The stdscr
window is beneath all panels, and is not considered part of the stack.

   A  window  is  associated with every panel. The panel routines 

enable you to create, move, hide, and show panels, as well as position
a panel at any desired location in the stack.

   Panel  routines  are  a  functional  layer added to curses(3X), 

make only high-level curses calls, and work anywhere terminfo curses
does.

Basically, in my app i have a main menu, which calls various programs
and when you return from any program, you come back to the main menu -
its precisely like “alpine”. So when Menu calls Contracts, and you
return from Contracts, you want your Menu screen like it was, not with
stuff from Contracts all over. This is best done using panels. A window
gives you a panel. When you remove the panel whats below is
automatically there without your repainting etc.

Pretty neat and efficient compared to many apps I have seen recently
that used windows or stdscr and had to do all this jugglery themselves.
Here’s some snips of code to make it clear:

  my_form_win = WINDOW.new(rows_to_show,0,startrow ,0)
  my_panel = my_form_win.new_panel
  Ncurses::Panel.update_panels

In line 2, I create a panel from my window. Pls note that these will go
into instance variables so the caller can destroy them later - V IMP.

Finally, I have a method “free_all” which frees the fields etc. It also
has:

Ncurses::Panel.del_panel(@panel)  if [email protected]?
@window.delwin if [email protected]?

The rest of the time, you actually can forget you created a panel, and
just keep writing on the window.

====
Now in your game, i can guess when you jump levels you really don’t want
the user to come back (like a stack). However, you could be popping up a
help screen, or a screen where the user can select weapons … and then
come back to the main screen. So its best to wrap those windows in
panels as shown above. The freeing can be put/called in an ensure block.

Also, you may have some side or bottom panels showing scores, weapons,
time, lives etc. These are best implemented by putting a panel at the
bottom or side.

The snakes game i made was based on the sample code from the Pickaxe and
used only stdscr – quite ugly if you ask me and it was only one screen
anyway. However, some folks have actually managed to build an entire app
using stdscr only (“sup”, iirc). “raggle” otoh uses windows but not
panels, so he has to implement some kind of global array of windows, so
he can pop and push. I don’t know their experience in implementing it -
was it clean or did they lose a lot of hair. i can tell you panels
are a clean way to implement layered windows.

On Sat, Nov 1, 2008 at 1:46 AM, Nit K. [email protected] wrote:

I wrote a rougelike in ruby+ncurses, but the source isn’t online
anymore, i can send you if you like :slight_smile:

^ manveru

Thanks manveru - could you tell me what keyboard.rb does in a nutshell.
I simply bind keys using the “?\C-a” kind of notation to symbols or
procs.

It allows me to make any object the receiver of keystrokes, simply by
doing
Keyboard.focus = something
the object has to respond to the #key method and take the name of the
key (as string) as argument.
So, in my code, once i show or hide a window/pane/view that is
interactive, i simply let it take over the focus of Keyboard and don’t
have separate dispatching or some kind of main loop.

keybindings are handled by

but that’s a lot more complicated, building a tree structure and
descends down into it until a matching keybinding is found. that
allows emacs-like keybindings like [C-x C-c].

I read your comment in window.rb of the bug that doesnt let you subclass
window. I had a long discussion on this here, i was trying to subclass
Form, iirc. Finally, someone said that the constructor was “shadowed”,
so one cannot make another one (I cannot recall the exact words), or
maybe it was private. So i too had wrapped and delegated like you have.

Yeah, it was quite a pain… ncurses.rb already does method_missing,
and then this wrapping introduces another layer, not very nice at all.

On 30/10/2008, Tim M. [email protected] wrote:

Anyone interested in a Roguelike game written in Ruby/Ncurses project?
Email me/post here!

([email protected])

There’s one downside to ncurses in Ruby - they do not support
multibyte characters. So your internationalization possibilities are
limited, and so are things like PC names.

In ruby 1.9 you could possibly set LC_CTYPE and use ncursesw but you
would still have to hack the extension.

I have posted a patch for 1.8 some time ago but that would likely
break stuff in Time or the like because ruby 1.8 does not play well
with setting locale.

Thanks

Michal

Michal S. wrote:

On 30/10/2008, Tim M. [email protected] wrote:

There’s one downside to ncurses in Ruby - they do not support
multibyte characters. So your internationalization possibilities are
limited, and so are things like PC names.

Thanks

Michal

Has anyone here used or played about with “slang” / s-lang. Would that
be better in this respect? I don’t believe anyone has written a ruby
binding.

What is the work involved to get ncurses-ruby MB enabled ? Is the
problem at the ruby end, or the ncurses end or the binding ?

Michael F. wrote:

http://github.com/manveru/ver/tree/master/lib/ver/keymap.rb
but that’s a lot more complicated, building a tree structure and
descends down into it until a matching keybinding is found. that
allows emacs-like keybindings like [C-x C-c].

I am interested in doing key mappings like Vi and emacs. Did look
through the code a bit
.
Could you tell me in brief how you map something like C-x C-c.

  1. Do you use some ncurses feature like waiting / delay for another key.

  2. Or when C-x is pressed, you check your structure to see if its
    mapped, and if there’s something more like a C-c, then you wait more.

  3. something else. Like after the C-x you do another getch() for the
    next character.

Have you faced problems handling Alt-keys ? Do you find that 2 key codes
are generated (I am on a mac, btw.). I am fine with F1 etc using
TERM=screen.

On 01/11/2008, Nit K. [email protected] wrote:

What is the work involved to get ncurses-ruby MB enabled ? Is the
problem at the ruby end, or the ncurses end or the binding ?

It’s at the Ruby end. 1.8 does not work with locale but ncurses seems
to use locale to determine encoding. Also ruby does not use ncursesw
when they are available.

1.9 could work but the extension would probably have to be updated to
at least link against ncursesw - at least that is how it worked for
me.

Thanks

Michal

Michael F. wrote:

On Sun, Nov 2, 2008 at 7:55 AM, Michal S. [email protected]
wrote:

binding.
at least link against ncursesw - at least that is how it worked for
me.

Could we use the new Ruby FFI to spare us the C mess?
Haah! I read that today and was wondering myself. But i am not clear on
how to link to .so or .a files. The example of getpid seems a little
“magical” to me (still a newbie)

Not to go offtopic, but does it mean we can load ncurse.so and then fire
away.

On Sun, Nov 2, 2008 at 6:32 AM, Nit K. [email protected] wrote:

how to link to .so or .a files. The example of getpid seems a little
“magical” to me (still a newbie)

Not to go offtopic, but does it mean we can load ncurse.so and then fire
away.

Yes - the FFI interface is really easy to use. You just need to
specify which lib you are referencing with the #ffi_lib method.

require ‘rubygems’
require ‘ffi’

module NCursesFFI
extend FFI::Library
ffi_lib ‘ncurses’
attach_function ‘clear’, [], :int
attach_function ‘endwin’, [], :int
attach_function ‘getch’, [], :int
attach_function ‘initscr’, [], :int
attach_function ‘printw’, [ :string ], :int
attach_function ‘refresh’, [], :int
end

NCursesFFI.initscr
NCursesFFI.printw(“Hello again”)
NCursesFFI.refresh
NCursesFFI.getch
NCursesFFI.endwin

Regards,
Sean

Sean O’halpin wrote:

Yes - the FFI interface is really easy to use. You just need to
specify which lib you are referencing with the #ffi_lib method.

require ‘rubygems’
require ‘ffi’

module NCursesFFI
extend FFI::Library

Seem to be other dependencies other than the gem (which installed fine).
Does it expect Jruby or rubinius ? I get:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

Nit K. wrote:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

It supports “darwin”, but not the “powerpc” cpu.

On Sun, Nov 2, 2008 at 7:55 AM, Michal S. [email protected]
wrote:

binding.
at least link against ncursesw - at least that is how it worked for
me.

Could we use the new Ruby FFI to spare us the C mess?

On Mon, Nov 3, 2008 at 3:42 PM, Nit K. [email protected] wrote:

extend FFI::Library

Seem to be other dependencies other than the gem (which installed fine).
Does it expect Jruby or rubinius ? I get:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

I’m running on Ubuntu 8.10:

$ ruby -v
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-linux]

Regards,
Sean

Michael F. wrote:

Thanks manveru - could you tell me what keyboard.rb does in a nutshell.
I simply bind keys using the “?\C-a” kind of notation to symbols or
procs.

It allows me to make any object the receiver of keystrokes, simply by
doing
Keyboard.focus = something
the object has to respond to the #key method and take the name of the
key (as string) as argument.
So, in my code, once i show or hide a window/pane/view that is
interactive, i simply let it take over the focus of Keyboard and don’t
have separate dispatching or some kind of main loop.

manver, i’ve been pouring through your code, and even tried out ver!

Then for kicks, i linked only keyboard.rb to a sample program and with
only a couple lines added it worked. Prints out the control keys and ESC
key combos.
It even gets Esc-a and Esc-A separately - wonderful. (it did hang when
ESC was pressed twice).

However, it does not accept/print the Alt-keys - is that deliberate, or
did have you not looked into it.

I have had problems with alt-keys (since they generate 2 bytes and that
goes thru my getch() loop twice, often leaving an extra char in the edit
field.