Browse Source

Start doing some commenting

Getty Ritter 5 years ago
parent
commit
b1f4d62d9f
3 changed files with 33 additions and 10 deletions
  1. 30 7
      src/components.rs
  2. 1 1
      src/res.rs
  3. 2 2
      src/sys/input.rs

+ 30 - 7
src/components.rs

@@ -1,5 +1,6 @@
 use specs::{Component, VecStorage, NullStorage};
 
+/// Register all the components with the world.
 pub fn register(world: &mut specs::World) {
     world.register::<Position>();
     world.register::<Velocity>();
@@ -7,9 +8,12 @@ pub fn register(world: &mut specs::World) {
     world.register::<Background>();
     world.register::<Foreground>();
     world.register::<Decoration>();
-    world.register::<Movable>();
+    world.register::<Controlled>();
 }
 
+/// The `Position` component represents (in world coordinates) a thing
+/// that has a position in the world, measured from the top-left of
+/// the thing.
 #[derive(Component, Debug)]
 #[storage(VecStorage)]
 pub struct Position {
@@ -18,11 +22,15 @@ pub struct Position {
 }
 
 impl Position {
+    /// Convert a `Position` to a screen point
     pub fn to_point(&self) -> ggez::nalgebra::Point2<f32> {
         ggez::nalgebra::Point2::new(self.x * 3.0, self.y * 3.0)
     }
 }
 
+/// The `Velocity` componenent is present on any entity that moves
+/// through the world, and represents its rate of change per
+/// time-unit.
 #[derive(Component, Debug)]
 #[storage(VecStorage)]
 pub struct Velocity {
@@ -30,12 +38,9 @@ pub struct Velocity {
     pub dy: f32,
 }
 
-impl Velocity {
-    pub fn to_point(&self) -> ggez::nalgebra::Point2<f32> {
-        ggez::nalgebra::Point2::new(self.dx * 3.0, self.dy * 3.0)
-    }
-}
 
+/// The `Sprite` components represents the current display location of
+/// a sprite in the spritesheet.
 #[derive(Component, Debug)]
 #[storage(VecStorage)]
 pub struct Sprite {
@@ -44,6 +49,8 @@ pub struct Sprite {
 }
 
 impl Sprite {
+    /// Convert a `Sprite` into the rectangle that specifies the
+    /// sprite location on the spritesheet
     pub fn to_rect(&self) -> ggez::graphics::Rect {
         ggez::graphics::Rect {
             x: (1.0 / 32.0) * self.u as f32,
@@ -54,18 +61,34 @@ impl Sprite {
     }
 }
 
+/// A drawing-phase component: represents tiles that appear in the
+/// background of everything.
 #[derive(Component, Default, Debug)]
 #[storage(NullStorage)]
 pub struct Background;
 
+/// A drawing-phase component: represents tiles which appear in the
+/// foreground, possibly entities.
 #[derive(Component, Default, Debug)]
 #[storage(NullStorage)]
 pub struct Foreground;
 
+/// A drawing-phase component: represents tiles which appear on top of
+/// everything else, such as the tops of trees or roofs of houses.
 #[derive(Component, Default, Debug)]
 #[storage(NullStorage)]
 pub struct Decoration;
 
+/// A component that represents entities which are controlled by the
+/// keyboard.
 #[derive(Component, Default, Debug)]
 #[storage(NullStorage)]
-pub struct Movable;
+pub struct Controlled;
+
+/// A component that represents entities which can collide with other
+/// things.
+#[derive(Component, Debug)]
+#[storage(VecStorage)]
+pub struct Collision {
+    pub has_collision: bool
+}

+ 1 - 1
src/res.rs

@@ -55,6 +55,6 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
         .with(Sprite { u: 8, v: 0 })
         .with(Velocity { dx: 0.0, dy: 0.0 })
         .with(Foreground)
-        .with(Movable)
+        .with(Controlled)
         .build();
 }

+ 2 - 2
src/sys/input.rs

@@ -1,4 +1,4 @@
-use crate::components::{Movable, Velocity};
+use crate::components::{Controlled, Velocity};
 use crate::game::MyGame;
 
 use sdl2::keyboard as sdl;
@@ -10,7 +10,7 @@ pub struct Move<'t> {
 
 impl<'a, 't> specs::System<'a> for Move<'t> {
     type SystemData = (
-        specs::ReadStorage<'a, Movable>,
+        specs::ReadStorage<'a, Controlled>,
         specs::WriteStorage<'a, Velocity>,
     );