Getty Ritter 4 years ago
parent
commit
ad5e08d682
5 changed files with 22 additions and 18 deletions
  1. 9 8
      src/components.rs
  2. 8 4
      src/game.rs
  3. 0 1
      src/main.rs
  4. 4 3
      src/resources.rs
  5. 1 2
      src/sys/physics.rs

+ 9 - 8
src/components.rs

@@ -1,6 +1,6 @@
+use crate::types::World;
 use specs::world::WorldExt;
 use specs::{Component, NullStorage, VecStorage};
-use crate::types::World;
 
 /// Register all the components with the world.
 pub fn register(world: &mut specs::World) {
@@ -121,7 +121,8 @@ pub struct Blocking {
 impl Blocking {
     /// create a `Blocking` component for an entity given a specified shape
     pub fn new_shape<S>(e: specs::Entity, w: &mut World, volume: S) -> Blocking
-    where S: ncollide2d::shape::Shape<f32>
+    where
+        S: ncollide2d::shape::Shape<f32>,
     {
         let (handle, _) = w.add(
             nalgebra::geometry::Isometry::identity(),
@@ -130,16 +131,16 @@ impl Blocking {
             ncollide2d::pipeline::object::GeometricQueryType::Proximity(0.0),
             e,
         );
-        Blocking {
-            handle,
-        }
+        Blocking { handle }
     }
 
     /// create an 11pxx11px box for an entity
     pub fn new_box(e: specs::Entity, w: &mut World) -> Blocking {
-        Blocking::new_shape(e, w, ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(
-            11.0, 11.0,
-        )))
+        Blocking::new_shape(
+            e,
+            w,
+            ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(11.0, 11.0)),
+        )
     }
 
     /// create a 11px ball for an entity

+ 8 - 4
src/game.rs

@@ -1,9 +1,9 @@
-use ggez::{Context, GameResult};
 use ggez::event::EventHandler;
+use ggez::{Context, GameResult};
 
 use specs::world::WorldExt;
 
-use crate::{components,resources,sys};
+use crate::{components, resources, sys};
 
 /// The shared values that the game state needs, specifically as the specs world
 pub struct MyGame {
@@ -51,7 +51,9 @@ impl EventHandler for MyGame {
         if keycode == winit::VirtualKeyCode::Escape {
             ggez::event::quit(ctx);
         }
-        self.world.write_resource::<resources::KeySet>().insert(keycode);
+        self.world
+            .write_resource::<resources::KeySet>()
+            .insert(keycode);
     }
 
     fn key_up_event(
@@ -60,6 +62,8 @@ impl EventHandler for MyGame {
         keycode: winit::VirtualKeyCode,
         _keymod: ggez::event::KeyMods,
     ) {
-        self.world.write_resource::<resources::KeySet>().remove(&keycode);
+        self.world
+            .write_resource::<resources::KeySet>()
+            .remove(&keycode);
     }
 }

+ 0 - 1
src/main.rs

@@ -9,7 +9,6 @@ pub mod sys;
 pub mod types;
 
 fn main() -> Result<(), ggez::error::GameError> {
-
     // Make a Context and an EventLoop.
     let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
         .add_resource_path({

+ 4 - 3
src/resources.rs

@@ -56,7 +56,7 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
                     let y = y as f32 * consts::TILE_SIZE;
                     let u = ((n - 1) % 32) as u8;
                     let v = ((n - u as u32 - 1) / 32) as u8;
-                    let is_blocking = tilesets[0].tiles[(n-1) as usize].properties["pass"]
+                    let is_blocking = tilesets[0].tiles[(n - 1) as usize].properties["pass"]
                         == consts::TILED_FALSE;
                     let mut e = w
                         .create_entity_unchecked()
@@ -81,7 +81,8 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
         }
     }
 
-    let e = w.create_entity_unchecked()
+    let e = w
+        .create_entity_unchecked()
         .with(Position {
             x: 3.0 * consts::TILE_SIZE,
             y: 3.0 * consts::TILE_SIZE,
@@ -99,5 +100,5 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
         let mut h = w.write_resource::<World>();
         Blocking::new_ball(entity, &mut h)
     })
-        .build();
+    .build();
 }

+ 1 - 2
src/sys/physics.rs

@@ -30,8 +30,7 @@ impl<'a> specs::System<'a> for Collide {
                     pos.clone()
                 };
                 let obj = w.get_mut(bl.handle).unwrap();
-                obj.set_position(
-                    Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero()));
+                obj.set_position(Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero()));
             })
             .collect();
         w.update();