lemunozm / ruscii

Terminal graphics engine: build your games in the terminal!
Apache License 2.0
171 stars 15 forks source link

Example is not working #39

Closed ShlomiRex closed 1 year ago

ShlomiRex commented 1 year ago

When I run the example given in README I get:

error[E0599]: no function or associated item named `new` found for struct `FPSCounter` in the current scope
 --> src\main.rs:9:39
  |
9 |     let mut fps_counter = FPSCounter::new();
  |                                       ^^^ function or associated item not found in `FPSCounter`

error[E0599]: no function or associated item named `new` found for struct `App` in the current scope
  --> src\main.rs:10:24
   |
10 |     let mut app = App::new();
   |                        ^^^ function or associated item not found in `App`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `tetris-rust` due to 2 previous errors

The code is:

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

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));
    });
}
pumken commented 1 year ago

Hey, @ShlomiRex!

It seems that we didn't update the README.md to reflect changes in the API following the update to version 0.4.0. There should be a fixed version on the way, but in case you see this before changes take place, just replace FPSCounter::new() and App::new() with FPSCounter::default() and App::default(), respectively.

Thanks for pointing these out!

ShlomiRex commented 1 year ago

@pumken Hi, I changed it and it compiels and runs now. However, the example still doesn't work as expected: image

I only see FPS counter and nothing else. I'm on windows 10.

pumken commented 1 year ago

That's pretty much all that example should do: show that the library can produce a dynamic text-based UI. If you'd like examples that more completely show the abilities of the library, you should try the code in the examples folder.

If you have any further questions, feel free to ask!