Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » How to make an ASCII game in terminal?

This thread is locked; no one can reply to it. rss feed Print
How to make an ASCII game in terminal?
Mark Oates
Member #1,146
March 2001
avatar

I would like to modify certain coordinates on the terminal screen for example. How would I be able to draw, say, char c at x, y? All I know is that the terminal outputs chars and scrolls up like a typewriter.

I'm talking about a graphics-based game that plays out on the terminal in all it's ASCII glory. Do you have a big char buffer and just clear/write it? How does something like that work?

Any help, thanks :)

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

SiegeLord
Member #7,827
October 2006
avatar

I think you typically use something like ncurses. It literally has a function that allows you to print stuff at the location you want.

No idea how it actually works underneath the hood though :P.

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

bamccaig
Member #7,536
July 2006
avatar

You will probably want to look into the curses library family... Generally there's the problem of different terminals speaking different "control characters" so you will certainly want a library to do it. In the general sense, control characters written as bytes to the terminal device (just as with any other data) are specially interpreted... Knowing that you can achieve dynamic content on supported terminals and emulators.

/beaten

Audric
Member #907
January 2001

In case you're curious, such library typically relies on the terminal's support of some character sequences, especially using the characters with codes in the 0-31 range.
For example in a MS-DOS or Linux/Unix console, printing the C string: "\x1B[10;12H" would move the cursor to position 10, 12
( \x1B is the single character of ASCII code 27: 'ESC')
http://www.real-world-systems.com/docs/ANSIcode.html

Polybios
Member #12,293
October 2010

Yeah, ANSI-codes are fun. Didn't work on Windows, though, last time I tried.
There might be old conio.h support on some Windows compilers, I believe there is also Windows API stuff to clear a terminal screen and to do other things. You can hack together some simple abstraction if you feel like it.

bamccaig
Member #7,536
July 2006
avatar

I don't think cmd.exe supports ANSI. At least, not colors... I have a Mercurial wrapper that toggles the color configuration setting so that paged things that are piped to less use "ansi" and unpaged things use "win32" codes, whatever that means, but I imagine it's custom...

Audric
Member #907
January 2001

Reminds me of my time maintaining a MUD :) Clients connected using telnet, color codes...
Nowadays there is a running "Nyan cat" server if you want to see how your telnet.exe supports the standards
http://nyancat.dakko.us/

Niunio
Member #1,975
March 2002
avatar

conio.h would make the work too. I don't know if any modern compiler still support it though. Free Pascal has CRT units.

-----------------
Current projects: Allegro.pas | MinGRo

Gideon Weems
Member #3,925
October 2003

Ways to do it (links in Python):

Input is a key concept. You wait for a character (not keypress) to appear. Any notion of a key being held down is limited by users' key repeat rates and your ability to hack around them. Double-width characters require extra care. I have found developing within XTerm (maintained by the same maintainer as ncurses) has provided peace of mind, as XTerm is ubiquitous and goes hand in hand with ncurses.

Draw text the way the terminal does naturally--left to right, top to bottom. Doing otherwise can slow down your program.

Chris Katko
Member #1,881
January 2002
avatar

Have you considered "emulating" terminal?

Terminal
+ Works over SSH / etc
- Bandwidth issues
- Features are only available per terminal software support
- Portability problems (UNIX color codes on UNIX, Windows/UNIX both support different resolution sizes, as well as line ending encoding)

Emulated:
+ No need for users to have a terminal
+ Simulate any features as needed
+ Faster draw rate
- No actual terminal support, so no cool SSHing

Remember Dwarf Fortress? They moved over to emulated terminal so that people could easily switch out text characters with graphic tilesets.

One thing I've loved that most people never saw: You can edit font glyphs in real time in DOS. So you can actually draw "graphics" in text mode.

All of these are standard 16-color (<- IIRC) text mode from the same game system:

{"name":"maxresdefault.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa78507cc38ac3f6b2fadc282ed78f88.jpg","w":1920,"h":1080,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa78507cc38ac3f6b2fadc282ed78f88"}maxresdefault.jpg

{"name":"320px-And.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/9\/e9e2fbec0f4787576e8ed8441ae20fe5.png","w":320,"h":175,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/9\/e9e2fbec0f4787576e8ed8441ae20fe5"}320px-And.png

{"name":"glade03.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0f450e5c723857228a8bafd4b07987eb.png","w":592,"h":322,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/f\/0f450e5c723857228a8bafd4b07987eb"}glade03.png

{"name":"ejet2.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/4\/a4585810b48b3964a7a5cdd6f9614de9.gif","w":640,"h":350,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/4\/a4585810b48b3964a7a5cdd6f9614de9"}ejet2.gif

MegaZeux was a spiritual successor to ZZT and basically "ZZT on crack". Some of my first games ever were made in MegaZeux.

I loved working within the constraints of 256 glyphs of ~16x8 bicolor, 16 colors total. You could do "animations" by changing glyphs--either replacing one character with another, or changing the glyph itself. (Like a bitmap version of palette swapping. Changing the glyph changed all characters using it.) You could do bigger characters by combining glyphs together.

People did INSANE stuff with Megazeux like doing actual animated cutscenes by spamming glyph and palette color changes each frame.

Megazeux also supported MODs/S3ms.

video

This is text mode!

-----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

Mark Oates
Member #1,146
March 2001
avatar

Have you considered "emulating" terminal?

I have actually, but it's not something I'm interested in. The purpose of this project would be to have a terminal window with graphical output alongside other programs in a multi-pane terminal session.

Emulating an ASCII-only display in, say, a Allegro is a bit overkill since I'm actually going for "underkill" :P

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Gideon Weems
Member #3,925
October 2003

I had never heard of MegaZeux until now. Had it come along at the right time in my life, I would have fallen head over heels for it. S3M support seals the deal.

Thanks for the history lesson.

Chris Katko
Member #1,881
January 2002
avatar

Megazeux correction, it was VGA text mode so you have a 64-color (real-time adjustable) palette. This video explains the details of how the software works.

video

-----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: