Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let container = Container::new();
- let messenger = messenger::new();
- let system = System::new(container, messenger);
- let velocity = Velocity::new();
- container
- .create_entity()
- .with::<PositionComponent>(Position::new())
- .with::<Velocity>(velocity)
- .build();
- container
- .create_entity()
- .with::<PositionComponent>(Position::new())
- .with::<Velocity>(velocity)
- .with::<Renderer>(Renderer::new())
- .build();
- system.add_tickable::<PositionProcessor>().priority(1);
- system.add_listener::<PrintLog>().on::<PrintLogMsg>();
- system.add_listener::<DisplayLog>().on::<PrintLogMsg>();
- system.add_listener::<MouseInputMsg>().on::<MouseInput>();
- while true {
- System.run()
- }
- }
- impl Tickable for PositionProcessor {
- fn tick(&self, container: &Container, messenger: &Messenger) {
- for (entity, position, velocity) in container
- .get_entities()
- .with::<PositionComponent, Velocity>()
- {
- entity.push_component::<Renderer>(Renderer::new());
- position.x += velocity.x;
- position.y += velocity.y;
- messenger.publish(PrintLogMsg::new("hello world!".to_string()));
- }
- }
- }
- impl Listener<PrintLogMsg> for PrintLog {
- fn trigger(self, container: &Container, messenger: &Messenger, msg: PrintLogMsg) {
- println!("{:?}", msg.content);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement