diff options
Diffstat (limited to 'src/world/wall.rs')
| -rw-r--r-- | src/world/wall.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/world/wall.rs b/src/world/wall.rs new file mode 100644 index 0000000..45b0b1e --- /dev/null +++ b/src/world/wall.rs @@ -0,0 +1,52 @@ +//! Walls, solid barriers that are generally unclimbable. +//! +//! This interpretation is generally up to the GM to decide, but generally +//! speaking, a wall cannot be crossed by a player. If special conditions apply +//! (for instance, when the player wants to scale the wall), a check is necessary. +//! If a check is not necessary, then maybe you were not thinking about a wall. + +use super::Component; +use crate::math::{LineSegment, Rect}; +use crate::transformable::NonRigidTransformable; +use nalgebra::Matrix3; +use serde::{Deserialize, Serialize}; + +/// Representation of a solid wall a player cannot go through, except if special +/// conditions apply. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Wall { + shape: LineSegment<f64>, +} + +impl Wall { + /// Create a new wall with the line segment defining it's start and end. + pub fn new(shape: LineSegment<f64>) -> Self { + Self { shape } + } + + /// Get the line shape this wall is based on. + pub fn shape(&self) -> &LineSegment<f64> { + &self.shape + } +} + +impl Component for Wall { + fn bounding_rect(&self) -> Rect<f64> { + Rect::bounding_rect(self.shape.start, self.shape.end) + } + + fn as_non_rigid(&self) -> Option<&dyn NonRigidTransformable> { + Some(self as &dyn NonRigidTransformable) + } + + fn as_non_rigid_mut(&mut self) -> Option<&mut dyn NonRigidTransformable> { + Some(self as &mut dyn NonRigidTransformable) + } +} + +impl NonRigidTransformable for Wall { + fn apply_matrix(&mut self, matrix: &Matrix3<f64>) { + self.shape.start = matrix.transform_point(&self.shape.start.into()).into(); + self.shape.end = matrix.transform_point(&self.shape.end.into()).into(); + } +} |
