Imrpoved component structure

This commit is contained in:
2025-11-26 22:05:39 +01:00
parent 7096849b65
commit 3f07ca0ff6
5 changed files with 93 additions and 9 deletions
+37 -2
View File
@@ -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();