HGE2D 0.1.6.2 → 0.1.6.5
raw patch · 3 files changed
+18/−9 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ HGE2D.Instances: instance HGE2D.Classes.Positioned HGE2D.Datas.BoundingBox
Files
- HGE2D.cabal +1/−1
- src/HGE2D/Collision.hs +8/−8
- src/HGE2D/Instances.hs +9/−0
HGE2D.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: HGE2D-version: 0.1.6.2+version: 0.1.6.5 synopsis: 2D game engine written in Haskell description: See README and examples/ for further information license: MIT
src/HGE2D/Collision.hs view
@@ -10,21 +10,21 @@ import HGE2D.Types import HGE2D.Datas import HGE2D.Classes+import HGE2D.Geometry+import HGE2D.Instances -------------------------------------------------------------------------------- -- | Tests whether two objects collide (overlap in any way) doCollide :: (HasBoundingBox a, HasBoundingBox b) => a -> b -> Bool-doCollide hasBB1 hasBB2 = 2.0 * xcenterthis - xcenterother < (xsizethis + xsizeother)- && 2.0 * ycenterthis - ycenterother < (ysizethis + ysizeother)+doCollide hasBB1 hasBB2 = abs (xcenterthis - xcenterother) < 0.5 * (xsizethis + xsizeother) &&+ abs (ycenterthis - ycenterother) < 0.5 * (ysizethis + ysizeother) where (bb1, bb2) = (getBB hasBB1, getBB hasBB2)- (minthis, maxthis) = (bbMin bb1, bbMax bb1)- (minother, maxother) = (bbMin bb2, bbMax bb2)- (xsizethis, ysizethis) = (abs $ (fst minthis) - (fst maxthis), abs $ (snd minthis) - (snd maxthis))- (xsizeother, ysizeother) = (abs $ (fst minother) - (fst maxother), abs $ (snd minother) - (snd maxother))- (xcenterthis, ycenterthis) = ((fst minthis) + (fst maxthis) / 2.0, (snd minthis) + (snd maxthis) / 2.0)- (xcenterother, ycenterother) = ((fst minother) + (fst maxother) / 2.0, (snd minother) + (snd maxother) / 2.0)+ (xsizethis, ysizethis) = (fst $ sizeBB bb1, snd $ sizeBB bb1)+ (xsizeother, ysizeother) = (fst $ sizeBB bb2, snd $ sizeBB bb2)+ (xcenterthis, ycenterthis) = (getX bb1, getY bb1)+ (xcenterother, ycenterother) = (getX bb2, getY bb2) --------------------------------------------------------------------------------
src/HGE2D/Instances.hs view
@@ -43,6 +43,15 @@ getX = getX . rigidPos getY = getY . rigidPos +-- | Instance of Positioned for BoundingBox+instance Positioned BoundingBox where+ getPos bb = (x, y)+ where+ x = 0.5 * ((fst $ bbMin bb) + (fst $ bbMax bb))+ y = 0.5 * ((snd $ bbMin bb) + (snd $ bbMax bb))+ getX = fst . getPos+ getY = snd . getPos+ -------------------------------------------------------------------------------- -- | Instance of Moveable for RealPosition