Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
iiYese committed Dec 17, 2023
1 parent d036600 commit 9b3b06c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ struct Pos(Vec3);
#[derive(Component)]
struct Character;

#[derive(Component)]
struct Weapon {
uses: u32,
strength: u32,
}

#[derive(Component)]
struct Stick;

#[derive(Clone, Copy)]
enum Climate {
Freezing,
Expand Down Expand Up @@ -74,9 +83,32 @@ impl Food {
}
}

#[derive(Component)]
struct Apple;

#[derive(Relation)]
struct Inventory;

fn setup(mut cmds: Commands) {
// Spawn character with some starting items.
cmds.spawn((Character, Pos(Vec3::default())))
.scope::<Inventory>(|invt| {
// Give them a starting weapon & 3 food items
invt.add((Weapon { uses: 32, strength: 4 }, Stick))
.add((Food::Raw { freshness: 128. }, Apple))
.add((Food::Raw { freshness: 128. }, Apple))
.add((Food::Raw { freshness: 128. }, Apple));
});

// Alternatively construct relatiosn manually.
// This might be more appropriate for changing an inventory or making more complex graphs.
let char = cmds.spawn((Character, Pos(Vec3::default()))).id();
cmds.spawn((Weapon { uses: 32, strength: 4, }, Stick)).set::<Inventory>(char);
cmds.spawn((Food::Raw { freshness: 128. }, Apple)).set::<Inventory>(char);
cmds.spawn((Food::Raw { freshness: 128. }, Apple)).set::<Inventory>(char);
cmds.spawn((Food::Raw { freshness: 128. }, Apple)).set::<Inventory>(char);
}

fn tick_food(
mut characters: Query<((&Character, &Pos), Relations<Inventory>)>,
mut inventory_food: Query<&mut Food, Without<Pos>>,
Expand All @@ -101,6 +133,7 @@ fn drop_item_from_inventory(
mut commands: Commands,
mut events: EventReader<TargetEvent>,
characters: Query<&Pos, With<Character>>,
food: Query<Entity, With<Food>>,
) {
// Set an items position to the position of the character that last had the item
// in their inventory when they drop it.
Expand All @@ -115,7 +148,7 @@ fn drop_item_from_inventory(
}

#[derive(Relation)]
#[aery(Symmetric)]
#[aery(Symmetric, Poly)]
struct FuseJoint;

#[derive(Component)]
Expand Down

0 comments on commit 9b3b06c

Please sign in to comment.