rastor 0.1.13

A terminal-based game engine
Documentation
use std::io::stdout;

use color_eyre::Result;
use crossterm::{
    cursor::MoveTo,
    event::KeyCode,
    execute,
    style::Color,
    terminal::{Clear, ClearType, disable_raw_mode, enable_raw_mode},
};
use rastor::{
    key::KeyInput,
    shapes::{Shape, rectangle::Rectangle},
    types::vec2::Vec2,
    utils::get_terminal_size,
};

fn main() -> Result<()> {
    let mut is_running = true;
    color_eyre::install().unwrap();
    let mut stdout = stdout();

    let term_size = get_terminal_size()?;
    let initial_pos = term_size / Vec2::splat(2);
    let mut rect = Rectangle::new(initial_pos.to_f32().into(), Vec2::splat(5.0), Color::Green);
    let mut other_rect = Rectangle::new((initial_pos.to_f32() + 2.0).into(), Vec2::splat(5.0), Color::Green);

    enable_raw_mode().unwrap();

    // KeyInput replaces the old handle_key helper.
    // Initialize with a neutral key (Null) so the sets start empty.
    let mut key_input = KeyInput::new();

    while is_running {
        execute!(stdout, Clear(ClearType::All), MoveTo(0, 0)).unwrap();

        rect.draw();
        rect.update();
        other_rect.draw();
        other_rect.update();

        let rect_collides_with_other = rect.collides_with(&other_rect);
        println!("{}", rect_collides_with_other);

        // Use KeyInput to check for key presses.
        if key_input.is_down(&KeyCode::Char('q')) { is_running = false }
    }
    disable_raw_mode().unwrap();

    println!();
    Ok(())
}