From f92e9f6f07b1e3834c2ca58ce3510734819d08e4 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 27 Jan 2021 14:01:50 +0100 Subject: Rework graf karto to fit the client/server structure --- src/world/wall.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/world/wall.rs (limited to 'src/world/wall.rs') 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, +} + +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(); + } +} -- cgit v1.2.3-70-g09d2