Browse Source

Allow creating an entity as a helper

Getty Ritter 4 years ago
parent
commit
1e1d438094
2 changed files with 6 additions and 4 deletions
  1. 4 0
      carpet/src/lib.rs
  2. 2 4
      ch2/src/main.rs

+ 4 - 0
carpet/src/lib.rs

@@ -310,6 +310,10 @@ impl<Idx: Tile + 'static> Game<Idx> {
         self.world.world.insert(r);
     }
 
+    pub fn create_entity(&mut self) -> specs::world::EntityBuilder {
+        self.world.world.create_entity()
+    }
+
     pub fn run(self) -> ggez::GameResult<()> {
         let Game { mut world, mut ctx, mut evloop } = self;
         ggez::event::run(&mut ctx, &mut evloop, &mut world)

+ 2 - 4
ch2/src/main.rs

@@ -81,8 +81,7 @@ fn main() -> Result<(), GameError> {
     game.register::<MoveLeft>();
     game.world.print([1, 1], "Hello, world!");
 
-    game.world.world
-        .create_entity()
+    game.create_entity()
         .with(Pos { x: 40, y: 25 })
         .with(Renderable {
             glyph: carpet::CP437::from_char('A'),
@@ -91,8 +90,7 @@ fn main() -> Result<(), GameError> {
         .build();
 
     for i in 0..10 {
-        game.world.world
-            .create_entity()
+        game.create_entity()
             .with(Pos { x: i * 7, y: 20 })
             .with(Renderable {
                 glyph: carpet::CP437::from_char('X'),