diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-05-31 14:53:37 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-05-31 14:53:37 +0200 |
commit | 79db730d4e42ce592af753059422410979ff26b0 (patch) | |
tree | 93a49e0200051ef6a6ee3131c2dbc8d052941589 /game_server/src/collide.rs | |
parent | a8908cac9524fabdcf4232c1394a51848f0335af (diff) |
tart implementing game logic
Diffstat (limited to 'game_server/src/collide.rs')
-rw-r--r-- | game_server/src/collide.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/game_server/src/collide.rs b/game_server/src/collide.rs new file mode 100644 index 0000000..4169787 --- /dev/null +++ b/game_server/src/collide.rs @@ -0,0 +1,36 @@ +pub trait Collide<Rhs> { + fn collides(&self, other: &Rhs) -> bool; +} + +impl Collide<Vec2> for Vec2 { + fn collides(self, other: Self) { + self == other + } +} + +impl Collide<Vec2> for Box { + fn collides(self, other: Vec2) { + self.pos < other < self.pos + self.size + } +} + +impl Collide<Box> for Box { + fn collides(self, other: Self) { + self.collides(other.pos) + || other.collides(self.pos) + } +} + +impl Collide<Vec2> for RBox { + fn collides(self, other: Vec2) { + + || other.pos < self.pos < other.pos + other.size + } +} + +impl Collide<Box> for Box { + fn collides(self, other: Self) { + self.pos < other.pos < self.pos + self.size + || other.pos < self.pos < other.pos + other.size + } +} |