basic_game_events/
main.rs

1mod commands;
2mod input;
3mod player;
4mod topic_ids;
5
6use commands::Commands;
7use input::Input;
8use player::Player;
9use pubsub_bus::*;
10use topic_ids::TopicIds;
11
12fn main() {
13    // Create a bus
14    let bus: EventBus<Commands, TopicIds> = EventBus::new();
15
16    // Create players, input, and attach to the bus
17    let player1 = Player { id: 1 };
18    let player2 = Player { id: 2 };
19    let mut input = Input::new();
20
21    bus.add_subscriber(player1);
22    bus.add_subscriber(player2);
23    bus.add_publisher(&mut input, Some(85)).unwrap();
24
25    // Send some events
26    input.publish(Commands::Move { dx: 1.0, dy: 2.0 }, Some(TopicIds::Player2));
27    input.publish(Commands::Move { dx: 1.0, dy: 2.0 }, Some(TopicIds::Player1));
28    input.publish(Commands::Atack, Some(TopicIds::Player2));
29    input.publish(Commands::Atack, Some(TopicIds::Player1));
30}