aboutsummaryrefslogtreecommitdiff
path: root/src/world/wall.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-27 14:01:50 +0100
committerArne Dußin2021-02-02 22:16:15 +0100
commitf92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch)
tree20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/world/wall.rs
parentc60a6d07efb120724b308e29e8e70f27c87c952d (diff)
downloadgraf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz
graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/world/wall.rs')
-rw-r--r--src/world/wall.rs52
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();
+ }
+}