//! 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, } impl Wall { /// Create a new wall with the line segment defining it's start and end. pub fn new(shape: LineSegment) -> Self { Self { shape } } /// Get the line shape this wall is based on. pub fn shape(&self) -> &LineSegment { &self.shape } } impl Component for Wall { fn bounding_rect(&self) -> Rect { 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) { self.shape.start = matrix.transform_point(&self.shape.start.into()).into(); self.shape.end = matrix.transform_point(&self.shape.end.into()).into(); } }