Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to make a ASCII game?

This thread is locked; no one can reply to it. rss feed Print
How to make a ASCII game?
Chris Katko
Member #1,881
January 2002
avatar

What would be your way to go about making the graphics for a Nethack, or Dwarf Fortress game?

I realize I could use Allegro and cache all the text. (Though, it'd probably need shaders to handle color, considering all of the possible permutations.) You also lose any "real" advantage of text (telnet/ssh).

I brought up ncurses and tried it. It's insanely simple to setup and use. One include, and two or three lines of code. However, immediately I was struck with a problem. Linux doesn't support extended ASCII.

Supposedly, you can change terminal emulation modes to get it to work. Nope. None of those work.

Supposedly, you can get a font that has ASCII code pages. But then you're requiring people to have appropriate fonts.

An hour or two of sifting through people's dead links has yielded no success in getting extended page ASCII to work. Which pisses me off. >:(

So I guess I should just go with Allegro, but does anyone here of experience in the matter?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

SiegeLord
Member #7,827
October 2006
avatar

DwarfFortress uses an SDL window, hence the support for custom graphics. I think that's superior to a plain terminal, since it's easier to create custom bitmap fonts.

If you wanted to stick to text mode, I imagine a better method these days is to use UTF8 rather than extended ASCII.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Chris Katko
Member #1,881
January 2002
avatar

I guess I'm just gonna have to use a window. It makes sense, I'm just dragging my feet about writing the renderer.

The thing about UTF-8 is you lose all of the special ASCII characters.

You can't do this:

{"name":"x4ujtucwz6etb6ed8n7m.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/0\/a03715c7166b97eb040e1574efd3f368.gif","w":640,"h":350,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/0\/a03715c7166b97eb040e1574efd3f368"}x4ujtucwz6etb6ed8n7m.gif

With UTF-8, because it doesn't have all the nifty text UI characters.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Elias
Member #358
May 2000

What do you mean? UTF-8 has every single unicode character, which has every single 8-bit ASCII character :)

╔══════════════════════╗
║▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜║
║▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐║
║▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐║
║▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐║
║▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐║
║▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐║
║▌░░░░░░░░░░░░░░░░░░░░▐║
║▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟║
╚══════════════════════╝

--
"Either help out or stop whining" - Evert

Chris Katko
Member #1,881
January 2002
avatar

Do allegro's font parsers support all 256 characters? Because I've got a font that supposedily supports extended characters and all I'm getting is blank over and over for special characters.

Using this font:

http://webdraft.hu/fonts/classic-console/

I'm getting nothing but blanks.

#SelectExpand
1 2class text_renderer_t 3 { 4 public: 5 bool is_initialized = false; 6 ALLEGRO_FONT *_font; 7 8 void load_ttf_font(const char *filename, int size, int flags) 9 { 10 _font = al_load_ttf_font(filename, size, flags); 11 if(_font != NULL)is_initialized = true; 12 13 assert(_font); //debugging for now. no error handler 14 } 15 16 void load_bitmap_font(const char *filename) 17 { 18 _font = al_load_bitmap_font(filename); 19 if(_font != NULL)is_initialized = true; 20 21 assert(_font); //debugging for now. no error handler 22 } 23 24 void draw_char(int x, int y, char character, ALLEGRO_COLOR color) 25 { 26 assert(is_initialized); 27 char text[2]; 28 text[0] = character; 29 text[1] = '\0'; 30 al_draw_text(_font, color, x, y, 0, text); 31 } 32 33 34 }text; 35 36 37// 38 39 text.load_ttf_font("data/clacon.ttf", 16, 0);

Using Allegro 5.1.7, Ubuntu.

[edit] Going through all 256 entries gives:

{"name":"609682","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5e30134ab2a74e70ecf216544545b3f9.png","w":640,"h":222,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/e\/5e30134ab2a74e70ecf216544545b3f9"}609682

*Note the blue rectangle is not related to the font.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Elias
Member #358
May 2000

You need to type in unicode like I did above, or otherwise use a translation table from codepage 437 to unicode. E.g. ╔ is ASCII 201 in cp437 which is unicode 9556, so:

al_draw_text("╔") // wors
al_draw_text(al_utf8_encode(9556)) // works
al_draw_text({0xE2, 0x95, 0x94, 0}) // works

(pseudo code, need to add missing arguments to all functions)

--
"Either help out or stop whining" - Evert

Izual
Member #2,756
September 2002
avatar

If you are going only for the ASCII looks then you can just load one of those character tilesets.
Then create 256 subbitmaps, one for each character. And just draw them to the screen using normal drawing functions.
That way you can even tint them to any color you desire.
This way you can make really nice ASCII looking game backed up by modern hardware. ( X@COM )

Chris Katko
Member #1,881
January 2002
avatar

Elias said:

al_draw_text("╔") // wors

That works! But unfortunately, it appears my ASCII TTF fonts looks ugly as hell no matter what I do. So I'll have to go the bitmap route.

However, shouldn't al_load_ttf_font() support something like AL_DEFAULT_POINT_SIZE (="-1")?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: