Refactor projectiles
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
module Dodge.Item.Weapon.Drone where
|
||||
import Dodge.Projectile.Draw
|
||||
--import Dodge.Projectile.Draw
|
||||
import Dodge.Data
|
||||
import Dodge.Default.Weapon
|
||||
--import Dodge.Default
|
||||
@@ -7,17 +7,10 @@ import Dodge.SoundLogic.LoadSound
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Geometry
|
||||
import Picture
|
||||
import qualified IntMapHelp as IM
|
||||
import ShapePicture
|
||||
import Shape
|
||||
|
||||
--import qualified Data.Set as S
|
||||
--import qualified SDL
|
||||
--import Data.Maybe
|
||||
import Control.Lens
|
||||
--import Control.Applicative
|
||||
--import Control.Monad.State
|
||||
--import System.Random
|
||||
|
||||
droneLauncher :: Item
|
||||
droneLauncher = defaultWeapon
|
||||
@@ -49,18 +42,19 @@ aDroneWithItemParams
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
|
||||
where
|
||||
am = _itConsumption it
|
||||
i = IM.newKey $ _props w
|
||||
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
|
||||
dir = _crDir cr
|
||||
--ammoMvs pj w' = foldr (\pjP -> _pjMoveParam pjP (_pjIntParam pjP) it cr pj) w' (_amPjParams am)
|
||||
theShell = Drone
|
||||
{ _prPos = pos
|
||||
, _pjStartPos = pos
|
||||
, _pjVel = rotateV dir (V2 1 0)
|
||||
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am)
|
||||
, _pjID = i
|
||||
, _pjUpdate = const id
|
||||
}
|
||||
aDroneWithItemParams = undefined
|
||||
--aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
|
||||
-- where
|
||||
-- am = _itConsumption it
|
||||
-- i = IM.newKey $ _props w
|
||||
-- pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
|
||||
-- dir = _crDir cr
|
||||
-- --ammoMvs pj w' = foldr (\pjP -> _pjMoveParam pjP (_pjIntParam pjP) it cr pj) w' (_amPjParams am)
|
||||
-- theShell = Drone
|
||||
-- { _prPos = pos
|
||||
-- , _pjStartPos = pos
|
||||
-- , _pjVel = rotateV dir (V2 1 0)
|
||||
-- , _prDraw = undefined
|
||||
-- , _pjID = i
|
||||
-- , _pjUpdate = const id
|
||||
-- }
|
||||
|
||||
@@ -15,7 +15,6 @@ import ShapePicture
|
||||
import Shape
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
|
||||
--grenade :: Item
|
||||
@@ -218,41 +217,43 @@ moveRemoteBomb itid time pID w
|
||||
|
||||
|
||||
throwRemoteBomb :: Creature -> World -> World
|
||||
throwRemoteBomb cr w = setLocation
|
||||
$ removePict
|
||||
$ resetFire
|
||||
-- $ resetName
|
||||
$ over props addG w
|
||||
where
|
||||
cid = _crID cr
|
||||
addG = IM.insert i $ Projectile
|
||||
{ _prPos = p
|
||||
, _pjStartPos = p
|
||||
, _pjVel = v
|
||||
, _prDraw = const mempty
|
||||
, _pjID = i
|
||||
, _pjUpdate = \_ -> moveRemoteBomb itid 50 i
|
||||
}
|
||||
i = IM.newKey $ _props w
|
||||
v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w)
|
||||
v | magV v' > 6 = 6 *.* normalizeV v'
|
||||
| otherwise = v'
|
||||
j = crSel cr
|
||||
-- resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE"
|
||||
removePict = id -- set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> mempty
|
||||
resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse)
|
||||
$ \_ -> explodeRemoteBomb itid i
|
||||
p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
|
||||
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
|
||||
| otherwise = p'
|
||||
maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just
|
||||
setLocation :: World -> World
|
||||
setLocation w' = case maybeitid of
|
||||
Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid
|
||||
& itemPositions %~ IM.insert newitid (InInv cid j)
|
||||
_ -> w'
|
||||
newitid = IM.newKey $ _itemPositions w
|
||||
itid = fromMaybe newitid maybeitid
|
||||
throwRemoteBomb = undefined
|
||||
--throwRemoteBomb cr w = undefined
|
||||
-- setLocation
|
||||
-- $ removePict
|
||||
-- $ resetFire
|
||||
---- $ resetName
|
||||
-- $ over props addG w
|
||||
-- where
|
||||
-- cid = _crID cr
|
||||
-- addG = IM.insert i $ Projectile
|
||||
-- { _prPos = p
|
||||
-- , _pjStartPos = p
|
||||
-- , _pjVel = v
|
||||
-- , _prDraw = const mempty
|
||||
-- , _pjID = i
|
||||
-- , _pjUpdate = \_ -> moveRemoteBomb itid 50 i
|
||||
-- }
|
||||
-- i = IM.newKey $ _props w
|
||||
-- v' = 0.02 / _cameraZoom w *.* rotateV (_cameraRot w) ( _mousePos w)
|
||||
-- v | magV v' > 6 = 6 *.* normalizeV v'
|
||||
-- | otherwise = v'
|
||||
-- j = crSel cr
|
||||
---- resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE"
|
||||
-- removePict = id -- set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> mempty
|
||||
-- resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse)
|
||||
-- $ \_ -> explodeRemoteBomb itid i
|
||||
-- p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
|
||||
-- p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
|
||||
-- | otherwise = p'
|
||||
-- maybeitid = w ^? creatures . ix cid . crInv . ix j . itID . _Just
|
||||
-- setLocation :: World -> World
|
||||
-- setLocation w' = case maybeitid of
|
||||
-- Nothing -> w' & creatures . ix cid . crInv . ix j . itID ?~ newitid
|
||||
-- & itemPositions %~ IM.insert newitid (InInv cid j)
|
||||
-- _ -> w'
|
||||
-- newitid = IM.newKey $ _itemPositions w
|
||||
-- itid = fromMaybe newitid maybeitid
|
||||
|
||||
explodeRemoteBomb :: Int -> Int -> Creature -> World -> World
|
||||
explodeRemoteBomb itid pjid cr w
|
||||
|
||||
@@ -6,7 +6,6 @@ module Dodge.Item.Weapon.Launcher
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Payload
|
||||
import Dodge.Projectile.Draw
|
||||
import Dodge.Reloading.Action
|
||||
import Dodge.EnergyBall
|
||||
import Dodge.Default.Weapon
|
||||
@@ -128,14 +127,14 @@ thrustParam = TweakParam
|
||||
, _nameTweak = "THRUST DELAY"
|
||||
}
|
||||
|
||||
pjThrust :: Int -> Prop -> World -> World
|
||||
pjThrust :: Int -> Proj -> World -> World
|
||||
pjThrust i = pjEffTimeRange (st,et) doThrust
|
||||
where
|
||||
et | i == 0 = 36
|
||||
| otherwise = 40 - (i * 20)
|
||||
st = et - 100
|
||||
|
||||
pjTrack :: Int -> Int -> Prop -> World -> World
|
||||
pjTrack :: Int -> Int -> Proj -> World -> World
|
||||
pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
|
||||
where
|
||||
et | i == 0 = 36
|
||||
@@ -143,22 +142,23 @@ pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
|
||||
st = et - 100
|
||||
rotateToTarget _ = fromMaybe id $ do
|
||||
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
|
||||
return $ props . ix (_pjID pj) . pjSpin .~ turnToAmount 0.15 (_prPos pj) tpos (argV $ _pjAcc pj)
|
||||
return $ projectiles . ix (_prjID pj) . prjSpin .~ turnToAmount 0.15 (_prjPos pj) tpos
|
||||
(argV $ _prjAcc pj)
|
||||
itPoint = pointToItem $ _itemPositions w IM.! itid
|
||||
|
||||
doThrust :: Prop -> World -> World
|
||||
doThrust :: Proj -> World -> World
|
||||
doThrust pj w = w
|
||||
& randGen .~ g
|
||||
& props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
|
||||
& projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
|
||||
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
|
||||
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) 3 10
|
||||
& shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
|
||||
where
|
||||
accel = _pjAcc pj
|
||||
i = _pjID pj
|
||||
oldPos = _prPos pj
|
||||
vel = _pjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
accel = _prjAcc pj
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
|
||||
r1 = randInCirc 10 & evalState $ _randGen w
|
||||
@@ -175,7 +175,7 @@ fireShell it cr = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID c
|
||||
spinamount = _shellSpinAmount params
|
||||
thrustdelay = _shellThrustDelay params
|
||||
|
||||
moveShell :: Prop -- ^ Projectile id
|
||||
moveShell :: Proj -- ^ Projectile id
|
||||
-> World
|
||||
-> World
|
||||
moveShell pj w
|
||||
@@ -186,56 +186,51 @@ moveShell pj w
|
||||
| time > -300 = w
|
||||
| otherwise = doExplode
|
||||
where
|
||||
time = _pjTimer pj
|
||||
time = _prjTimer pj
|
||||
doExplode = w
|
||||
& _pjPayload pj oldPos
|
||||
& usePayload (_prjPayload pj) oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
& props %~ IM.delete i
|
||||
i = _pjID pj
|
||||
oldPos = _prPos pj
|
||||
vel = _pjVel pj
|
||||
& projectiles %~ IM.delete i
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
|
||||
reduceSpinBy :: Float -> Prop -> World -> World
|
||||
reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x
|
||||
|
||||
|
||||
--shellShape :: Shape
|
||||
--shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
|
||||
|
||||
reduceSpinBy :: Float -> Proj -> World -> World
|
||||
reduceSpinBy x pj = projectiles . ix (_prjID pj) . prjSpin *~ x
|
||||
|
||||
pjEffTimeRange
|
||||
:: (Int,Int)
|
||||
-> (Prop -> World -> World)
|
||||
-> Prop
|
||||
-> (Proj -> World -> World)
|
||||
-> Proj
|
||||
-> World
|
||||
-> World
|
||||
pjEffTimeRange (st,et) f pj
|
||||
| t <= et && t >= st = f pj
|
||||
| otherwise = id
|
||||
where
|
||||
t = _pjTimer pj
|
||||
t = _prjTimer pj
|
||||
|
||||
pjEffAtTime
|
||||
:: Int
|
||||
-> (Prop -> World -> World)
|
||||
-> Prop
|
||||
-> (Proj -> World -> World)
|
||||
-> Proj
|
||||
-> World
|
||||
-> World
|
||||
pjEffAtTime t f pj
|
||||
| _pjTimer pj == t = f pj
|
||||
| _prjTimer pj == t = f pj
|
||||
| otherwise = id
|
||||
|
||||
trySpinByCID
|
||||
:: Int -- ^ creature id
|
||||
-> Int -- ^ Spin amount
|
||||
-> Prop
|
||||
-> Proj
|
||||
-> World
|
||||
-> World
|
||||
trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin
|
||||
trySpinByCID cid i pj w = w & projectiles . ix pjid . prjSpin .~ newSpin
|
||||
where
|
||||
pjid = _pjID pj
|
||||
dir = argV $ _pjVel pj
|
||||
pjid = _prjID pj
|
||||
dir = argV $ _prjVel pj
|
||||
newSpin = case w ^? creatures . ix cid of
|
||||
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
|
||||
_ -> 0
|
||||
@@ -252,27 +247,26 @@ remoteLauncher = launcher
|
||||
fireRemoteShell :: Item -> Creature -> World -> World
|
||||
fireRemoteShell it cr w = set (creatures . ix cid . crInv . ix j . itUse . rUse)
|
||||
(\_ _ -> explodeRemoteRocket itid i)
|
||||
-- $ set (creatures . ix cid . crInv . ix j . itName) remoteLauncherName
|
||||
$ addRemRocket w'
|
||||
where
|
||||
(w',itid) = getHeldItemLoc cr w
|
||||
i = IM.newKey $ _props w
|
||||
cid = _crID cr
|
||||
addRemRocket = makeShell it cr $ \pj ->
|
||||
decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
|
||||
decTimMvVel pj . setRemoteScope itid (_prjPos pj) . moveRemoteShell cid itid pj
|
||||
j = crSel cr
|
||||
|
||||
moveRemoteShell :: Int -> Int -> Prop -> World -> World
|
||||
moveRemoteShell :: Int -> Int -> Proj -> World -> World
|
||||
moveRemoteShell cid itid pj w
|
||||
| time > 40 = if circOnSomeWall oldPos 4 w
|
||||
then doExplosion
|
||||
else w
|
||||
| anythingHitCirc 2 oldPos newPos w = doExplosion
|
||||
| time >= 20 = w & props . ix i . pjDir .~ newdir
|
||||
| time >= 20 = w & projectiles . ix i . prjDir .~ newdir
|
||||
| time > -99 = w & set randGen g
|
||||
& props . ix i %~
|
||||
( ( pjVel %~ ( (accel +.+) . (frict *.*) ) )
|
||||
. ( pjDir .~ newdir )
|
||||
& projectiles . ix i %~
|
||||
( ( prjVel %~ ( (accel +.+) . (frict *.*) ) )
|
||||
. ( prjDir .~ newdir )
|
||||
)
|
||||
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
|
||||
& smokeGen
|
||||
@@ -280,16 +274,16 @@ moveRemoteShell cid itid pj w
|
||||
| time > -200 = w
|
||||
| otherwise = doExplosion
|
||||
where
|
||||
time = _pjTimer pj
|
||||
i = _pjID pj
|
||||
oldPos = _prPos pj
|
||||
vel = _pjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
time = _prjTimer pj
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
newdir
|
||||
| SDL.ButtonRight `M.member` _mouseButtons w
|
||||
&& w ^? creatures . ix cid . crInvSel . iselPos == w ^? itemPositions . ix itid . ipInvID
|
||||
= _cameraRot w + argV (_mousePos w)
|
||||
| otherwise = _pjDir pj
|
||||
| otherwise = _prjDir pj
|
||||
accel = rotateV newdir (V2 2 0)
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.5,0.5) $ _randGen w
|
||||
@@ -303,21 +297,20 @@ anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
||||
hitCr = runIdentity $ S.any_ (const True) $ overlap1SegCrs sp ep $ crsNearSeg sp ep w
|
||||
hitWl = collideCircWallsStream sp ep rad $ wlsNearPoint ep w
|
||||
-- this should probably be wallsOnLine or something
|
||||
|
||||
explodeRemoteRocket
|
||||
:: Int -- ^ Item id
|
||||
-> Int -- ^ Projectile id
|
||||
-> World
|
||||
-> World
|
||||
explodeRemoteRocket itid pjid w = w
|
||||
& props . ix pjid . pjUpdate .~ (\_ -> retireRemoteProj fireRemoteShell itid 30 pjid)
|
||||
& props . ix pjid . prDraw .~ const mempty
|
||||
& projectiles . ix pjid . prjUpdate .~ (\_ -> retireRemoteProj fireRemoteShell itid 30 pjid)
|
||||
& projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
& itPoint . itUse . rUse .~ (\_ _ -> id)
|
||||
-- & itPoint . itName .~ "REMOTELAUNCHER"
|
||||
& _pjPayload thepj (_prPos thepj)
|
||||
& usePayload (_prjPayload thepj) (_prjPos thepj)
|
||||
where
|
||||
itPoint = pointToItem $ _itemPositions w IM.! itid
|
||||
thepj = _props w IM.! pjid
|
||||
thepj = _projectiles w IM.! pjid
|
||||
|
||||
fireTrackingShell :: Item -> Creature -> World -> World
|
||||
fireTrackingShell it cr w = addTrackRocket w'
|
||||
@@ -334,20 +327,20 @@ fireTrackingShell it cr w = addTrackRocket w'
|
||||
spindrag = _shellSpinDrag params
|
||||
params = _itParams it
|
||||
|
||||
makeShell :: Item -> Creature -> (Prop -> World -> World) -> World -> World
|
||||
makeShell it cr theupdate w = w & props %~ IM.insert i Shell
|
||||
{ _prPos = pos
|
||||
, _pjZ = 20
|
||||
, _pjStartPos = pos
|
||||
, _pjVel = rotateV dir (V2 1 0)
|
||||
, _prDraw = drawProjectile (_amPjDraw $ _laAmmoType am)
|
||||
, _pjID = i
|
||||
, _pjUpdate = theupdate
|
||||
, _pjAcc = rotateV dir (V2 3 0)
|
||||
, _pjDir = dir
|
||||
, _pjSpin = 0
|
||||
, _pjPayload = usePayload $ _amPayload $ _laAmmoType am
|
||||
, _pjTimer = 50
|
||||
makeShell :: Item -> Creature -> (Proj -> World -> World) -> World -> World
|
||||
makeShell it cr theupdate w = w & projectiles %~ IM.insert i Shell
|
||||
{ _prjPos = pos
|
||||
, _prjZ = 20
|
||||
, _prjStartPos = pos
|
||||
, _prjVel = rotateV dir (V2 1 0)
|
||||
, _prjDraw = DrawShell
|
||||
, _prjID = i
|
||||
, _prjUpdate = theupdate
|
||||
, _prjAcc = rotateV dir (V2 3 0)
|
||||
, _prjDir = dir
|
||||
, _prjSpin = 0
|
||||
, _prjPayload = _amPayload $ _laAmmoType am
|
||||
, _prjTimer = 50
|
||||
}
|
||||
where
|
||||
i = IM.newKey $ _props w
|
||||
|
||||
@@ -40,9 +40,9 @@ setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of
|
||||
.~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5})
|
||||
_ -> w'
|
||||
|
||||
setRemoteScope :: Int -> Prop -> World -> World
|
||||
setRemoteScope itid pj w' = case w' ^? itemPositions . ix itid of
|
||||
setRemoteScope :: Int -> Point2 -> World -> World
|
||||
setRemoteScope itid pos w' = case w' ^? itemPositions . ix itid of
|
||||
Just (InInv cid' invid )
|
||||
-> w' & creatures . ix cid' . crInv . ix invid . itScope
|
||||
. scopePos .~ (_prPos pj -.- _crPos (_creatures w' IM.! cid'))
|
||||
. scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid'))
|
||||
_ -> w'
|
||||
|
||||
@@ -5,13 +5,13 @@ import Dodge.Data
|
||||
import Geometry.Vector
|
||||
|
||||
import Control.Lens
|
||||
decTimMvVel :: Prop -> World -> World
|
||||
decTimMvVel pj = props . ix pjid %~
|
||||
( (pjTimer -~ 1)
|
||||
. (prPos %~ (+.+ vel) )
|
||||
. (pjAcc %~ rotateV rot )
|
||||
decTimMvVel :: Proj -> World -> World
|
||||
decTimMvVel pj = projectiles . ix pjid %~
|
||||
( (prjTimer -~ 1)
|
||||
. (prjPos %~ (+.+ vel) )
|
||||
. (prjAcc %~ rotateV rot )
|
||||
)
|
||||
where
|
||||
rot = _pjSpin pj
|
||||
vel = _pjVel pj
|
||||
pjid = _pjID pj
|
||||
rot = _prjSpin pj
|
||||
vel = _prjVel pj
|
||||
pjid = _prjID pj
|
||||
|
||||
Reference in New Issue
Block a user