switch to circle based collision
This commit is contained in:
parent
92569c2345
commit
d91f4bf9c1
1 changed files with 31 additions and 31 deletions
62
src/Test.hs
62
src/Test.hs
|
@ -250,34 +250,34 @@ checkBoundsCollision
|
|||
checkBoundsCollision
|
||||
pos@(V2 or oc) npos@(V2 fr fc) acc@(V2 mr mc)
|
||||
(Boundaries (minr, minc) (maxr, maxc))
|
||||
| (fr - fromIntegral (floor fr) >= minr &&
|
||||
fr - fromIntegral (floor fr) <= maxr) &&
|
||||
(fc - fromIntegral (floor fc) >= minc &&
|
||||
fc - fromIntegral (floor fc) <= maxc) &&
|
||||
(or - fromIntegral (floor or) < minr ||
|
||||
or - fromIntegral (floor or) > maxr) =
|
||||
(V2 (0 * mr) (1 * mc))
|
||||
| (fr - fromIntegral (floor fr) >= minr &&
|
||||
fr - fromIntegral (floor fr) <= maxr) &&
|
||||
(fc - fromIntegral (floor fc) >= minc &&
|
||||
fc - fromIntegral (floor fc) <= maxc) &&
|
||||
(oc - fromIntegral (floor oc) < minc ||
|
||||
oc - fromIntegral (floor oc) > maxc) =
|
||||
(V2 (1 * mr) (0 * mc))
|
||||
| (fr - fromIntegral (floor fr) < minr ||
|
||||
fr - fromIntegral (floor fr) > maxr) &&
|
||||
(fc - fromIntegral (floor fc) < minc ||
|
||||
fc - fromIntegral (floor fc) > maxc) =
|
||||
(V2 (1 * mr) (1 * mc))
|
||||
| (fr - fromIntegral (floor fr) < minr ||
|
||||
fr - fromIntegral (floor fr) > maxr) &&
|
||||
(fc - fromIntegral (floor fc) >= minc &&
|
||||
fc - fromIntegral (floor fc) <= maxc) =
|
||||
(V2 (1 * mr) (1 * mc))
|
||||
| (fr - fromIntegral (floor fr) >= minr &&
|
||||
fr - fromIntegral (floor fr) <= maxr) &&
|
||||
(fc - fromIntegral (floor fc) < minc ||
|
||||
fc - fromIntegral (floor fc) > maxc) =
|
||||
(V2 (1 * mr) (1 * mc))
|
||||
| otherwise =
|
||||
(V2 (0 * mr) (0 * mc))
|
||||
| ntestr && ntestc && not testr = V2 (0 * mr) (1 * mc)
|
||||
| ntestc && ntestr && not testc = V2 (1 * mr) (0 * mc)
|
||||
| not ntestr && not ntestc = V2 (1 * mr) (1 * mc)
|
||||
| not ntestr && ntestc = V2 (1 * mr) (1 * mc)
|
||||
| not ntestc && ntestr = V2 (1 * mr) (1 * mc)
|
||||
| otherwise = V2 (0 * mr) (0 * mc)
|
||||
where
|
||||
ntestr
|
||||
| ndistr <= hheight + 0.07 = True
|
||||
| ncdistsq <= 0.005 = True
|
||||
| otherwise = False
|
||||
ntestc
|
||||
| ndistc <= hwidth + 0.07 = True
|
||||
| ncdistsq <= 0.005 = True
|
||||
| otherwise = False
|
||||
testr
|
||||
| distr <= hheight + 0.07 = True
|
||||
| cdistsq <= 0.005 = True
|
||||
| otherwise = False
|
||||
testc
|
||||
| distc <= hwidth + 0.07 = True
|
||||
| cdistsq <= 0.005 = True
|
||||
| otherwise = False
|
||||
ndistr = abs ((fr - fromIntegral (floor fr)) - (minr + hheight))
|
||||
ndistc = abs ((fc - fromIntegral (floor fc)) - (minc + hwidth))
|
||||
distr = abs ((or - fromIntegral (floor or)) - (minr + hheight))
|
||||
distc = abs ((oc - fromIntegral (floor oc)) - (minc + hwidth))
|
||||
hheight = (maxr - minr) / 2
|
||||
hwidth = (maxc - minc) / 2
|
||||
ncdistsq = (ndistr - hheight) ^ 2 + (ndistc - hwidth) ^ 2
|
||||
cdistsq = (distr - hheight) ^ 2 + (distc - hwidth) ^ 2
|
||||
|
|
Loading…
Reference in a new issue