Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. fn main() {
  2. let container = Container::new();
  3. let messenger = messenger::new();
  4.  
  5. let system = System::new(container, messenger);
  6.  
  7. let velocity = Velocity::new();
  8. container
  9. .create_entity()
  10. .with::<PositionComponent>(Position::new())
  11. .with::<Velocity>(velocity)
  12. .build();
  13. container
  14. .create_entity()
  15. .with::<PositionComponent>(Position::new())
  16. .with::<Velocity>(velocity)
  17. .with::<Renderer>(Renderer::new())
  18. .build();
  19.  
  20. system.add_tickable::<PositionProcessor>().priority(1);
  21. system.add_listener::<PrintLog>().on::<PrintLogMsg>();
  22. system.add_listener::<DisplayLog>().on::<PrintLogMsg>();
  23. system.add_listener::<MouseInputMsg>().on::<MouseInput>();
  24.  
  25. while true {
  26. System.run()
  27. }
  28. }
  29.  
  30. impl Tickable for PositionProcessor {
  31. fn tick(&self, container: &Container, messenger: &Messenger) {
  32. for (entity, position, velocity) in container
  33. .get_entities()
  34. .with::<PositionComponent, Velocity>()
  35. {
  36. entity.push_component::<Renderer>(Renderer::new());
  37. position.x += velocity.x;
  38. position.y += velocity.y;
  39.  
  40. messenger.publish(PrintLogMsg::new("hello world!".to_string()));
  41. }
  42. }
  43. }
  44.  
  45. impl Listener<PrintLogMsg> for PrintLog {
  46. fn trigger(self, container: &Container, messenger: &Messenger, msg: PrintLogMsg) {
  47. println!("{:?}", msg.content);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement