Tweak shell spin

This commit is contained in:
2025-01-08 22:07:04 +00:00
parent d952bd48cc
commit c355fe4f5f
9 changed files with 179 additions and 173 deletions
+1
View File
@@ -20,6 +20,7 @@ data Projectile
, _pjVel :: Point2
, _pjDir :: Float
, _pjSpin :: Float
, _pjSpinFactor :: Float
, _pjID :: Int
, _pjPayload :: Payload
, _pjTimer :: Int
+11 -18
View File
@@ -1,33 +1,26 @@
module Dodge.Movement.Turn where
module Dodge.Movement.Turn (
turnTo,
vecTurnTo,
) where
import Geometry
turnTo :: Float -> Point2 -> Point2 -> Float -> Float
turnTo turnSpeed sp tp a
| vToTarg == V2 0 0 = a
| angleVV vToTarg vdir <= turnSpeed
= argV vToTarg
| angleVV vToTarg vdir <= turnSpeed =
argV vToTarg
| isLHS (sp +.+ vdir) sp tp = a - turnSpeed
| otherwise = a + turnSpeed
where
vdir = unitVectorAtAngle a
vToTarg = tp -.- sp
turnToAmount :: Float -> Point2 -> Point2 -> Float -> Float
turnToAmount turnSpeed sp tp a
| vToTarg == V2 0 0 = 0
| angleVV vToTarg vdir <= turnSpeed
= diffAngles a (argV vToTarg) -- TODO check correctness
| isLHS (sp +.+ vdir) sp tp = negate turnSpeed
| otherwise = turnSpeed
| otherwise = a + turnSpeed
where
vdir = unitVectorAtAngle a
vToTarg = tp -.- sp
vecTurnTo :: Float -> Point2 -> Point2 -> Point2 -> Point2
vecTurnTo turnSpeed sp tp vdir
| angleVV vToTarg vdir <= turnSpeed
= magV vdir *.* normalizeV vToTarg
| angleVV vToTarg vdir <= turnSpeed =
magV vdir *.* normalizeV vToTarg
| isLHS (sp +.+ vdir) sp tp = rotateV (negate turnSpeed) vdir
| otherwise = rotateV turnSpeed vdir
| otherwise = rotateV turnSpeed vdir
where
vToTarg = tp -.- sp
+5
View File
@@ -42,6 +42,7 @@ createShell mdetonator mscreen stab pjtype payload muz cr w =
, _pjID = i
, _pjDir = dir
, _pjSpin = 0
, _pjSpinFactor = spinfactor
, _pjPayload = payload
, _pjTimer = lifespan
, _pjUpdates =
@@ -61,6 +62,10 @@ createShell mdetonator mscreen stab pjtype payload muz cr w =
Just StabOrthReduce -> []
Just StabSpinIncrease -> [StartSpinPU (lifespan - 15) (_crID cr) 4]
_ -> [StartSpinPU (lifespan - 15) (_crID cr) 2]
spinfactor = case stab of
Just StabOrthReduce -> 0
Just StabSpinIncrease -> 2
_ -> 1
speed = case pjtype of
Grenade{} -> 4
Rocket{} -> 1
+13 -6
View File
@@ -28,7 +28,7 @@ updateProjectile :: Projectile -> World -> World
updateProjectile pj w =
(cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjTimer -~ 1)
. shellCollisionCheck pj
. pjMovement pj
. moveProjectile pj
. doGravityPU pj
$ foldl' (flip $ upProjectile pj) w (_pjUpdates pj)
@@ -202,18 +202,24 @@ pjRemoteSetDirection ph pj w = case ph of
Just (HomeUsingRemoteScreen screenid)
| lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
== lw ^? itemLocations . ix (_unNInt screenid) . ilInvID ->
w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir
.~ (w ^. wCam . camRot) + argV (w ^. input . mousePos)
w
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir
.~ (w ^. wCam . camRot) + argV (w ^. input . mousePos)
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjSpin
.~ 0.5 * diffAngles ((w ^. wCam . camRot) + argV (w ^. input . mousePos)) (_pjDir pj)
Just (HomeUsingTargeting itid)
| Just tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just ->
w & cWorld . lWorld . projectiles . ix (_pjID pj) . pjDir
%~ turnTo 0.2 (_pjPos pj) tp
& cWorld . lWorld . projectiles . ix (_pjID pj) . pjSpin
.~ 0.5 * diffAngles (turnTo 0.2 (_pjPos pj) tp (_pjDir pj)) (_pjDir pj)
_ -> w
where
lw = w ^. cWorld . lWorld
pjMovement :: Projectile -> World -> World
pjMovement pj w
moveProjectile :: Projectile -> World -> World
moveProjectile pj w
| Just GStuckWall{} <- pj ^? pjType . gnHitEffect = w
| Just (GStuckCreature crid p d) <- pj ^? pjType . gnHitEffect
, Just cr <- w ^? cWorld . lWorld . creatures . ix crid =
@@ -233,7 +239,8 @@ pjMovement pj w
w
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjSpin *~ 0.99
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjPos +~ _pjVel pj
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~ _pjSpin pj
& cWorld . lWorld . projectiles . ix (pj ^. pjID) . pjDir +~
(_pjSpin pj * _pjSpinFactor pj)
explodeShell ::
Projectile ->
+3 -3
View File
@@ -1,6 +1,6 @@
module Dodge.Room.LasTurret where
import Dodge.Item.Held.Cane
--import Dodge.Item.Held.Cane
import qualified Data.Set as S
import Dodge.Cleat
import Dodge.Data.GenWorld
@@ -24,8 +24,8 @@ import RandomHelp
cenLasTur :: Room
cenLasTur =
roomNgon 8 200 & rmPmnts
-- .~ [ putLasTurret 0.02
.~ [ putTurret autoRifle 0.02
.~ [ putLasTurret 0.02
-- .~ [ putTurret autoRifle 0.02
, heightWallPS (resetPLUse $ rprBoolShift (const . isInLnk) (shiftInBy 100)) 30 covershape
, mntLightLnkCond $ rprBool $ const . isInLnk
]
+15 -27
View File
@@ -6,8 +6,8 @@ Description : Geometry helpers
This module provides geometry functions that manipulate pairs of floats.
Conventions:
Seg refers to a segment, typically defined by two points, and will typically not extend beyond either of these points.
Line refers to a line defined by two points, and extends beyond the two points.
Seg refers to a segment between two points and does not extend beyond either of these points.
Line is also defined by two points but does extend beyond the two points.
-}
module Geometry (
module Geometry,
@@ -33,9 +33,6 @@ import Geometry.Vector
import Geometry.Vector3D
import ListHelp
--import Data.Maybe
--import Data.List
{- | Return a point a distance away from a first point towards a second point.
Does not go past the second point.
No check is made for a negative distance, so can go past the first point.
@@ -93,9 +90,9 @@ midPoint !a !b = 0.5 *.* (a +.+ b)
-}
circOnSegNoEndpoints :: Point2 -> Point2 -> Point2 -> Float -> Bool
{-# INLINE circOnSegNoEndpoints #-}
circOnSegNoEndpoints !p1 !p2 !c !rad = intersectSegSegTest p1 p2 (c -.- thenormal) (c +.+ thenormal)
circOnSegNoEndpoints !p1 !p2 !c !rad = intersectSegSegTest p1 p2 (c -.- norm) (c +.+ norm)
where
thenormal = rad *.* vNormal (normalizeV $ p1 -.- p2)
norm = rad *.* vNormal (normalizeV $ p1 -.- p2)
{- | Test whether a circle is on a segment by intersecting a normal and testing
the distance to the endpoints of the segment.
@@ -106,9 +103,9 @@ circOnSeg :: Point2 -> Float -> Point2 -> Point2 -> Bool
circOnSeg !c !rad !p1 !p2 =
magV (p1 -.- c) <= rad
|| magV (p2 -.- c) <= rad
|| intersectSegSegTest p1 p2 (c -.- thenormal) (c +.+ thenormal)
|| intersectSegSegTest p1 p2 (c -.- norm) (c +.+ norm)
where
thenormal = rad *.* vNormal (normalizeV $ p1 -.- p2)
norm = rad *.* vNormal (normalizeV $ p1 -.- p2)
{- | Test whether a segment intersects a circle by intersecting a normal and testing
the distance to the endpoints of the segment.
@@ -118,13 +115,13 @@ segOnCirc :: Point2 -> Point2 -> Point2 -> Float -> Bool
segOnCirc !p1 !p2 !c !rad =
magV (p1 -.- c) <= rad
|| magV (p2 -.- c) <= rad
|| intersectSegSegTest p1 p2 (c -.- thenormal) (c +.+ thenormal)
|| intersectSegSegTest p1 p2 (c -.- norm) (c +.+ norm)
where
thenormal = rad *.* vNormal (normalizeV $ p1 -.- p2)
norm = rad *.* vNormal (normalizeV $ p1 -.- p2)
cylinderOnSeg :: Point3 -> Point3 -> Point3 -> Float -> Bool
{-# INLINE cylinderOnSeg #-}
cylinderOnSeg = undefined
cylinderOnSeg = undefined -- TODO
-- | Find the difference between two Nums.
difference :: (Ord a, Num a) => a -> a -> a
@@ -144,14 +141,15 @@ reflectIn line vec = rotateV (2 * angleBetween line vec) vec
reflectAngle :: Float -> Point2 -> Point2 -> Float
reflectAngle a x y = 2 * argV (x - y) - a
{- | Find the representation (by applying +-pi) of an angle
- that is nearest to another given angle -}
{- | Find the representation (by applying +-pi) of an angle
- that is nearest to another given angle
-}
nearestAngleRep :: Float -> Float -> Float
nearestAngleRep a b
| b >= a && b - a <= pi = b
| b >= a = nearestAngleRep a (b - 2*pi)
| b >= a = nearestAngleRep a (b - 2 * pi)
| a - b <= pi = b
| otherwise = nearestAngleRep a (b + 2*pi)
| otherwise = nearestAngleRep a (b + 2 * pi)
{- | Find angle between two points.
Not normalised, ranges from -2*pi to 2*pi.
@@ -170,7 +168,6 @@ doublePairSet (x, y) = S.fromList [(x, y), (y, x)]
doubleV2 :: V2 a -> [V2 a]
doubleV2 (V2 x y) = [V2 x y, V2 y x]
polyToTris' :: [s] -> [s]
{-# INLINE polyToTris' #-}
polyToTris' [] = []
@@ -193,8 +190,6 @@ nRaysRad n x = take n $ iterate (rotateV (2 * pi / fromIntegral n)) (V2 x 0)
This appears to sometimes fail if the angles are not normalized.
-}
isLeftOfA :: Float -> Float -> Bool
--isLeftOfA angle1 angle2 = (angle1 - angle2 < pi && angle1 > angle2)
-- || (angle2 - angle1 > pi && angle2 > angle1)
isLeftOfA angle1 angle2 = normalizeAngle (angle1 - angle2) < pi
{- | Test whether a vector is to the left of another, according to the smallest
@@ -204,17 +199,10 @@ isLeftOf :: Point2 -> Point2 -> Bool
isLeftOf x y = isLeftOfA (argV x) (argV y)
{- | Find the difference between two angles.
Possibly not correct...
TODO write tests
-}
diffAngles :: Float -> Float -> Float
diffAngles x y
| diff > pi = diffAngles (x - 2 * pi) y
| diff >= 0 = diff
| diff > - pi = - diff
| otherwise = diffAngles (x + 2 * pi) y
where
diff = x - y
diffAngles x y = nearZeroAngle $ x - y
mixAngles :: Float -> Float -> Float -> Float
mixAngles frac a1 a2
+11
View File
@@ -133,6 +133,17 @@ normalizeAngle f
floor' :: Float -> Float
floor' x = fromIntegral (floor x :: Int)
-- | Normalize an angle to be between -pi and pi radians
nearZeroAngle :: Float -> Float
{-# INLINE nearZeroAngle #-}
nearZeroAngle a
| a >= -pi && a < pi = a
| otherwise = a - 2 * pi * floor' ((a +pi) / (2 * pi))
where
floor' :: Float -> Float
floor' x = fromIntegral (floor x :: Int)
-- | Rotate vector by pi/2 clockwise.
vNormal :: Point2 -> Point2
{-# INLINE vNormal #-}