diff options
| author | troido <troido@protonmail.com> | 2020-01-29 22:53:06 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-01-29 22:53:06 +0100 |
| commit | 286be37225b5de1fb438db0a4029fd391b35c13e (patch) | |
| tree | c865ca269f43d7666275d1d72096dad805135705 /src/components.rs | |
| parent | 88f275bc427033b7981e0dc2fc5cb4b711fd5fb1 (diff) | |
players can no longer walk through walls
Diffstat (limited to 'src/components.rs')
| -rw-r--r-- | src/components.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components.rs b/src/components.rs index 07de1d5..c72ba61 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,10 +1,13 @@ +use std::ops; + use specs::{ VecStorage, Component }; use super::controls::Control; +use super::util::clamp; #[derive(Component, Debug, Hash, PartialEq, Eq, Clone, Copy)] @@ -14,6 +17,31 @@ pub struct Position { pub y: i32 } +impl ops::Add<Position> for Position { + type Output = Position; + + fn add(self, other: Position) -> Position { + Position { + x: self.x + other.x, + y: self.y + other.y + } + } +} + +impl Position { + + pub fn new(x: i32, y: i32) -> Position { + Position {x, y} + } + + pub fn clamp(self, smaller: Position, larger: Position) -> Position { + Position { + x: clamp(self.x, smaller.x, larger.x), + y: clamp(self.y, smaller.y, larger.y) + } + } +} + #[derive(Component, Debug, Clone)] #[storage(VecStorage)] pub struct Visible { @@ -24,3 +52,7 @@ pub struct Visible { #[derive(Component, Debug)] #[storage(VecStorage)] pub struct Controller(pub Control); + +#[derive(Component, Debug)] +#[storage(VecStorage)] +pub struct Blocking; |
