Replaced Degrees and Radians with a single Angle type
[kaka/rust-sdl-test.git] / src / core / level / mod.rs
index 5df8ba6..00f3009 100644 (file)
@@ -1,4 +1,4 @@
-use common::{Point, Dimension, Intersection, supercover_line};
+use common::{Point, Dimension, Intersection, Angle, ToAngle, supercover_line};
 use core::render::Renderer;
 use sprites::SpriteManager;
 use std::rc::Rc;
@@ -89,6 +89,14 @@ impl Level {
        // walls
        for wall in &self.walls {
            for e in &wall.edges {
+               let c = (e.p1 + e.p2) / 2.0;
+               let a = (e.p2 - e.p1).to_angle() + std::f64::consts::FRAC_PI_2.radians();
+
+               renderer.draw_line(
+                   <(i32, i32)>::from(c.to_i32()),
+                   <(i32, i32)>::from((c + Point::from(a) * 10.0).to_i32()),
+                   (255, 128, 0));
+
                renderer.draw_line(
                    <(i32, i32)>::from(e.p1.to_i32()),
                    <(i32, i32)>::from(e.p2.to_i32()),
@@ -99,15 +107,13 @@ impl Level {
 
     pub fn intersect_walls(&self, p1: Point<f64>, p2: Point<f64>) -> IntersectResult {
        for c in self.wall_grid.grid_coordinates_on_line(p1, p2) {
-           if let walls = &self.wall_grid.cells[c.x][c.y] {
-               for w in walls {
-                   if let Intersection::Point(p) = Intersection::lines(p1, p2, w.p1, w.p2) {
-                       let wall = Wall {
-                           region: &self.walls[w.region],
-                           edge: w,
-                       };
-                       return IntersectResult::Intersection(wall, p)
-                   }
+           for w in &self.wall_grid.cells[c.x][c.y] {
+               if let Intersection::Point(p) = Intersection::lines(p1, p2, w.p1, w.p2) {
+                   let wall = Wall {
+                       region: &self.walls[w.region],
+                       edge: w,
+                   };
+                   return IntersectResult::Intersection(wall, p)
                }
            }
        }
@@ -240,4 +246,8 @@ impl<'a> Wall<'a> {
            edge,
        }
     }
+
+    pub fn normal(&self) -> Angle {
+       (self.edge.p2 - self.edge.p1).to_angle() + std::f64::consts::FRAC_PI_2.radians()
+    }
 }