ASCII-game is the game that only uses a printable character from ASCII character set to render the game's visual elements. There are two distinct types of ASCII games:
Games that use ASCII characters but render them using standard high-fidelity graphics. Perfect examples of these types of games would be beautiful Cogmind, Stone Story RPG, and ASCIIDENT games. These games bring the unique ASCII-art but sadly don't play in a classic terminal. While they lack the nostalgic retro-gaming feel - they avoid most of the inherent limitation of the native ASCII games we are discussing below.
Native ASCII games use text ANSI terminal to render the game. These games not only use ASCII characters, but they render entire gameplay on a classic ANSI terminal in a pure text mode. These games can play on computers that don't even have the graphics support like classic mainframe terminals. While such capability is unlikely to be important for many users - it does bring the authentic retro-game aesthetics and gameplay.
There are many good examples of these games including ASCII Patrol, Curse Of War, ASCII Sector, or Pyramid Builder. And, although not a game in a strict definition, the ASCIIQuarium is one of the beautiful examples of what a simple native ASCII game can look like.
ASCIIQuarium and the desire to replicate its visual effects in other games was one of the inspirations and drivers behind the decision to build CosPlay game engine in the first place. In the end, CosPlay provides capabilities that go way beyond what ASCIIQuarium requires and allows to build much more visually rich native ASCII games.
CosPlay game engine is purpose built for development of the native ASCII games. CosPlay games play natively in any ANSI terminal in a pure text mode. The idea behind the CosPlay is to bring the visual sophistication of the graphics rendered games to the world of native ASCII games.
Native ASCII games, as a genre, have number of quirks and technical limitations. Some of these limitations are obvious, while others are less so:
Even though CosPlay's effective FPS is usually around 1,000 on modern computers, the typical ANSI terminal struggles to render a full screen update even at partly 30 FPS. Large frame updates tend to result in "rolling shutter" effect, which is pronounced more for certain shapes and certain movement directions. This effect is noticeable regardless of which game engine is used. For example, you can see that effect on ASCIIQuarium mentioned before that is written in plain C++.
It is important to note that this effect is more pronounced for horizontal movement of large vertical shapes. Try to avoid this type of movement in your games.
While this is mostly self-explanatory it is worthwhile to note that unlike traditional graphics games that operate with minimal resolution of one pixel - native ASCII games operate with 100-200 pixel (one character) rectangle as their minimal resolution unit. The content of that character pixel rectangle is also very limited - it is limited to the characters in ASCII character set. The color of the character is also different from a pixel: character has optional background, mandatory foreground color as well as the shape of the character glyph that also affects the overall color of the character rectangle on the screen.
In the end, this is more of a feature than a limitation. ASCII art is flourishing avant-garde culture and there is a countless online collections of the existing ASCII art that one can borrow or use for inspiration:
It should come as no surprise that animation in ANSI terminal can only happen in one character units. You can't move by individual pixel - you only move by 10-20 pixel at a time depending on the font size used by your terminal. Even the specific font size is not directly available to the game.
Discrete animation is obviously more jerky and stuttering comparing to the pixel-based animation of the traditional graphics games. Vertical movement is more jerky than horizontal one since character height is usually larger than the character width.
There are two ways to mitigate this limitation:
Use smaller shapes for animation, prefer horizontal movement, and avoid prolong movements. "Rolling shutter" effect does not happen on each frame (more like every 20-40 frames) and so shorter animation sequences have a lesser chance of encountering this effect.
Use discrete animation as an artistic tool. When used properly and consistently it can result in a unique visual design of the game. No other game does it better than Stone Story RPG.
One of the less obvious problems with the discrete animation is the way to control the speed of movement in the game. When you object can only move 10-20 pixels at a time - it takes more finesse to provide slower or faster movements with a minimum visual degradation. Look at various animation examples to see some techniques to accomplish that.
CosPlay provides several state-of-the-art tools for sophisticated and visually rich discrete animations including programmable shaders, particle effects, sprite animations and ASCII video support.
Handling the player input is one of the less-obvious quirks of the native ASCII games. This is specific to the native ASCII games only.
The way that non-terminal games read player input is very different from the way the ANSI terminal reads its keyboard input. Native ASCII games do not have direct access to the keyboard due to compatibility issues with various ANSI terminals. These games can only rely on ANSI capabilities to read keyboard input which comes with some limitations.
First of all, only certain combination of keys are detected and returned as ANSI sequences and thus available to the CosPlay. In particular, Option and Alt control keys are universally ignored by the ANSI terminals. Also, many combinations share the same return code: for example, Ctrl+M and Enter return the same ANSI code
0x000D in which case CosPlay makes a unilateral decision and always returns Enter key ignoring Ctrl+M choice all together. See CPKeyboardKey type for the list of detectable and available keyboard keys.
Secondly, the speed with which the terminal read the keyboard input and makes it available to the CosPlay is dependent on the particular terminal. Repeated key presses are also detected differently by different terminals. See CPKeyboardEvent type for API details on how to handle repeated key presses.
Thirdly, and this is probably the most unexpected side effect, is the fact ANSI terminals do not detect more than one key pressed at a time. For example, if the player presses Space and keeps holding it (e.g. shooting enemies) - no other key presses will be detected until the player releases the Space key. What this means is that it is impossible to implement combined actions like moving and shooting in the same time by solely relying on the keyboard events. This is one of the most serious limitations in native ASCII games.
Multiple Key Presses
ANSI terminals do not detect multiple key presses. For example, if the player presses a particular keyboard key and keeps holding it - no other key presses will be detected until the player releases that key. What this means is that it is impossible to implement combined actions like moving and shooting in the same time by solely relying on keyboard events.
While straight vertical and horizontal lines are easy to draw using ASCII characters, the curved lines like polynomials, circle and ellipses are much harder to draw. It is even more so if you want to have an algorithm to draw them. Furthermore, there's no a single agreed upon style on how to draw curved or angled lines using ASCII. In many cases, this is a style preference rather than a hard rule. This is in stark contrast with the traditional graphics based games where angled and curved lines have several well known standard approaches.
Class CPCanvas provides many methods for drawing various shapes. It also has a support for smoothing the angled lines using a well-known ASCII art techniques. However, it is worth noting that most curved lines will require hand-drawn approach.
For example, consider the following subtle curvatures (borrowed from the excellent ASCII art tutorial by Richard Crawford):
/ / / / / / ____/ _.-~ _,-~ _.-' _.-' _.-' / ,^ ,^ ," ,` ,' / / / / / / / / / / / / ____/ __.-~ __,-~ __.-" __.-' __.-`
First line is a default naive drawing. Second and third curves differ only in use of
'.' (line 2 and line 6). This is just one of several stylistic modifications one could make - in this particular case, use of
',' make the curvature appear more angular at the connection point. Later options make the curve even smoother by utilising
'`' characters. Last line looks particular smooth.
If that curvature can be modelled as a poly-line CosPlay can draw these curvatures automatically using
drawArtPolyline(...) in CPCanvas class. However, as mentioned above, for many other, more complicated cases, you will have to resort to hand drawing.
Note also that CPCanvas class provides extensive drawing methods for rendering circles. CosPlay also have prefab circle images built-in.