Imrpoved component structure
This commit is contained in:
+37
-2
@@ -3,8 +3,6 @@ pub mod components;
|
||||
use osmium::{renderer::Point, terminal};
|
||||
|
||||
fn main() {
|
||||
terminal::hide_cursor().unwrap();
|
||||
|
||||
let engine = osmium::init();
|
||||
|
||||
let my_rect = engine.entity(|r| {
|
||||
@@ -15,6 +13,43 @@ fn main() {
|
||||
|
||||
my_rect.component(components::Velocity(Point { x: 0, y: 0 }));
|
||||
|
||||
components::threads::tick(&engine);
|
||||
components::threads::key(&engine);
|
||||
|
||||
engine.on_event({
|
||||
let my_rect = my_rect.clone();
|
||||
move |e: &crossterm::event::Event| {
|
||||
if let Some(key_event) = e.as_key_event() {
|
||||
match key_event.code {
|
||||
crossterm::event::KeyCode::Right => {
|
||||
my_rect.update_component(|c: &mut components::Velocity| {
|
||||
c.0.x = 100;
|
||||
});
|
||||
}
|
||||
crossterm::event::KeyCode::Left => {
|
||||
my_rect.update_component(|c: &mut components::Velocity| {
|
||||
c.0.x = -100;
|
||||
});
|
||||
}
|
||||
|
||||
crossterm::event::KeyCode::Down => {
|
||||
my_rect.update_component(|c: &mut components::Velocity| {
|
||||
c.0.y = 100;
|
||||
});
|
||||
}
|
||||
crossterm::event::KeyCode::Up => {
|
||||
my_rect.update_component(|c: &mut components::Velocity| {
|
||||
c.0.y = -100;
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
terminal::hide_cursor().unwrap();
|
||||
|
||||
engine.start();
|
||||
|
||||
terminal::show_cursor().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user