34 lines
1.1 KiB
Haskell
34 lines
1.1 KiB
Haskell
module Dodge.Magnet where
|
|
|
|
import Control.Lens
|
|
import Dodge.Data.Bullet
|
|
import Dodge.Data.Magnet
|
|
import Geometry
|
|
|
|
dampField :: Magnet -> Bullet -> Bullet
|
|
dampField mg pt = case pt of
|
|
Bullet{} | dist (_buPos pt) (_mgPos mg) < 100 -> pt & buVel *~ 0.5
|
|
_ -> pt
|
|
|
|
curveLeftField :: Magnet -> Bullet -> Bullet
|
|
curveLeftField mg pt = case pt of
|
|
Bullet{} | dist (_buPos pt) (_mgPos mg) < 500 -> pt & buVel %~ rotateV 0.2
|
|
_ -> pt
|
|
|
|
curveAroundField :: Float -> Float -> Magnet -> Bullet -> Bullet
|
|
curveAroundField minrad maxrad mg pt = case pt of
|
|
Bullet{} | thedist < maxrad -> pt & buVel %~ rotateToCircle
|
|
where
|
|
thedist = dist btpos mgpos
|
|
mgpos = _mgPos mg
|
|
btpos = _buPos pt
|
|
rotateToCircle vel
|
|
| (isLHS mgpos btpos (btpos +.+ vel) && isRHS mgpos btpos (mgpos +.+ vNormal vel))
|
|
|| (isRHS mgpos btpos (btpos +.+ vel) && isLHS mgpos btpos (mgpos +.+ vNormal vel)) =
|
|
rotateV rot vel
|
|
| otherwise = rotateV (negate rot) vel
|
|
rot
|
|
| thedist < minrad = 0.5
|
|
| otherwise = 0.5 * ((maxrad - thedist) / (maxrad - minrad)) ** 2
|
|
_ -> pt
|