Add gimbal and gyroscope, allowing more fine tuned projectile control

This commit is contained in:
2024-12-30 11:41:20 +00:00
parent 4c9632b3f3
commit 87f068f01a
11 changed files with 308 additions and 239 deletions
+18 -8
View File
@@ -1,5 +1,6 @@
module Dodge.Projectile.Create (
createShell,
PJStabiliser (..),
) where
import NewInt
@@ -12,12 +13,18 @@ import Geometry
import qualified IntMapHelp as IM
import LensHelp
data PJStabiliser
= StabOrthReduce
| StabSpinIncrease
-- assumes the mscreen is in your inventory
createShell ::Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Maybe PJStabiliser
-> ProjectileType
-> Payload -> Muzzle -> Creature -> World -> World
createShell mdetonator mscreen pjtype payload muz cr w = w
createShell mdetonator mscreen stab pjtype payload muz cr w = w
& updatescreen
& updatedetonator
& cWorld . lWorld . projectiles . at i
@@ -25,23 +32,28 @@ createShell mdetonator mscreen pjtype payload muz cr w = w
{ _pjPos = pos
, _pjZ = 20
, _pjZVel = 5
, _pjVel = rotateV dir (V2 speed 0) + cr ^. crPos - cr ^. crOldPos
, _pjVel = rotateV dir (V2 speed 0) + crvelcomponent
, _pjID = i
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = payload
, _pjTimer = lifespan
, _pjUpdates =
[-- TimePU
StartSpinPU (lifespan - 15) (_crID cr) spinamount
, RemoteDirectionPU (lifespan - thrustdelay) 0
-- , ReduceSpinPU (1 - spindrag * 2 / 200)
anyspin <>
[ RemoteDirectionPU (lifespan - thrustdelay) 0
] <> thrustorgrav
, _pjType = pjtype
, _pjDetonatorID = mdetonator
, _pjScreenID = mscreen
}
where
crvelcomponent = case stab of
Just StabOrthReduce -> projV (cr ^. crPos - cr ^. crOldPos) (unitVectorAtAngle dir)
_ -> cr ^. crPos - cr ^. crOldPos
anyspin = case stab of
Just StabOrthReduce -> []
Just StabSpinIncrease -> [StartSpinPU (lifespan - 15) (_crID cr) 4]
_ -> [StartSpinPU (lifespan - 15) (_crID cr) 2]
speed = case pjtype of
Grenade {} -> 4
Rocket{} -> 1
@@ -51,8 +63,6 @@ createShell mdetonator mscreen pjtype payload muz cr w = w
Grenade {}-> [ApplyGravityPU]
Rocket{} -> [ThrustPU (lifespan - thrustdelay) 0]
RetiredProjectile -> []
-- spindrag = 1
spinamount = 2
thrustdelay = 20
updatedetonator = fromMaybe id $ do
screenid <- mdetonator