diff options
Diffstat (limited to 'ecs/examples/relationship.rs')
| -rw-r--r-- | ecs/examples/relationship.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/ecs/examples/relationship.rs b/ecs/examples/relationship.rs deleted file mode 100644 index e8fb327..0000000 --- a/ecs/examples/relationship.rs +++ /dev/null @@ -1,48 +0,0 @@ -use ecs::event::start::Start as StartEvent; -use ecs::relationship::Relationship; -use ecs::{Component, Query, World}; - -#[derive(Component)] -struct Sword -{ - attack_strength: u32, -} - -#[derive(Component)] -struct Player; - -#[derive(Component)] -struct Health -{ - health: u32, -} - -struct Holding; - -fn print_player_stats(player_query: Query<(Player, Health, Relationship<Holding, Sword>)>) -{ - for (_, health, sword_relationship) in &player_query { - println!("Player health: {}", health.health); - - if let Some(sword) = sword_relationship.get(0) { - println!("Player sword attack strength: {}", sword.attack_strength); - } - } -} - -fn main() -{ - let mut world = World::new(); - - world.register_system(StartEvent, print_player_stats); - - let sword_uid = world.create_entity((Sword { attack_strength: 17 },)); - - world.create_entity(( - Player, - Health { health: 180 }, - Relationship::<Holding, Sword>::new(sword_uid), - )); - - world.emit(StartEvent); -} |
