4 releases

✓ Uses Rust 2018 edition

0.2.0 Jan 13, 2020
0.1.2 Dec 30, 2019
0.1.1 Dec 30, 2019
0.1.0 Dec 27, 2019

#58 in Game development

Apache-2.0

34KB
886 lines

lancat license downloads

ruscii

An easy library to make terminal applications and games in rust.

The aim of this project is to make easier the game development in terminals. Any contribution, issue, or pull request would be welcome!

Features

  • Optimized to render fast in terminals.
  • Multi-platform (Linux, Windows and MacOS)
  • Multi-terminal (See crossterm terminal support)
  • Enable key press and release events in terminal (essential for games!)
  • Easy to use. Make your terminal game in a few lines!
  • Easy way to recover the terminal state at error.

Examples

You can found several examples into the example folder.

To test an example, install ruscii with the examples flag and run it.

cargo install ruscii --examples
~/.cargo/bin/<example_name>

Or clone the repo and execute inside of it:

cargo run --example <example_name> --release

Some of these examples:

Space invaders (200 lines):

asciicast

Pong (150 lines):

asciicast

Note: the first asciimedia playback could be shown laggy, a second playback fix this issue.

Getting started

Test it in your own terminal!

Add the following line to your dependencies section in Cargo.toml file:

ruscii = "0.1"

Copy the following code in your main.rs to run the base ruscii application:

use ruscii::app::{App, State};
use ruscii::terminal::{Window};
use ruscii::drawing::{Pencil};
use ruscii::keyboard::{KeyEvent, Key};
use ruscii::spatial::{Vec2};
use ruscii::gui::{FPSCounter};

fn main() {
    let mut fps_counter = FPSCounter::new();
    let mut app = App::new();

    app.run(|app_state: &mut State, window: &mut Window| {
        for key_event in app_state.keyboard().last_key_events() {
            match key_event {
                KeyEvent::Pressed(Key::Esc) => app_state.stop(),
                KeyEvent::Pressed(Key::Q) => app_state.stop(),
                _ => (),
            }
        }

        fps_counter.update();

        let mut pencil = Pencil::new(window.canvas_mut());
        pencil.draw_text(&format!("FPS: {}", fps_counter.count()), Vec2::xy(1, 1));
    });
}

Dependencies

~1–1.4MB
~27K SLoC