|
|
|
@ -41,6 +41,7 @@ data Pituicat = Pituicat
|
|
|
|
|
, pcMoveState :: Maybe Action
|
|
|
|
|
, pcViewDirection :: ViewDirection
|
|
|
|
|
, pcEffects :: [EffectHolder]
|
|
|
|
|
, pcXColl :: Bool
|
|
|
|
|
}
|
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ data ViewDirection = ViewLeft | ViewRight
|
|
|
|
|
|
|
|
|
|
instance Drawable Pituicat where
|
|
|
|
|
|
|
|
|
|
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _ vd _) =
|
|
|
|
|
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _ vd _ _) =
|
|
|
|
|
( V.fromList [0, 1, 2, 2, 3, 0]
|
|
|
|
|
, V.fromList
|
|
|
|
|
[ newVertex
|
|
|
|
@ -116,6 +117,9 @@ instance Actor Pituicat where
|
|
|
|
|
{ pcMoveVel =
|
|
|
|
|
lerp (min 0.95 (60 * dt)) (pcMoveVel physCat) (pcTMoveVel physCat)
|
|
|
|
|
, pcGrounded = pcGrounded physCat && abs dy * dt <= 2
|
|
|
|
|
, pcPos = pcPos physCat + if not (pcXColl physCat)
|
|
|
|
|
then ((dt *) <$> pcMoveVel physCat)
|
|
|
|
|
else V2 0 0
|
|
|
|
|
, pcEffects =
|
|
|
|
|
foldl
|
|
|
|
|
(\acc eff ->
|
|
|
|
@ -155,29 +159,13 @@ instance Mass Pituicat where
|
|
|
|
|
{ pcAcc = accel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
velocity cat =
|
|
|
|
|
let mvel@(V2 mx _) = pcMoveVel cat
|
|
|
|
|
nvel@(V2 x y) = pcVel cat + mvel
|
|
|
|
|
in
|
|
|
|
|
if abs x > abs mx then V2 (signum x * abs mx) y else nvel
|
|
|
|
|
velocity =
|
|
|
|
|
pcVel
|
|
|
|
|
|
|
|
|
|
velocityUpdater cat =
|
|
|
|
|
\(V2 vx vy) ->
|
|
|
|
|
let
|
|
|
|
|
(V2 mx my) = pcMoveVel cat
|
|
|
|
|
nvel = V2
|
|
|
|
|
(if abs mx > abs vx
|
|
|
|
|
then 0
|
|
|
|
|
else signum vx * (abs vx - abs mx)
|
|
|
|
|
)
|
|
|
|
|
(if abs my > abs vy
|
|
|
|
|
then 0
|
|
|
|
|
else signum vy * (abs vy - abs my)
|
|
|
|
|
)
|
|
|
|
|
in
|
|
|
|
|
cat
|
|
|
|
|
{ pcVel = nvel
|
|
|
|
|
}
|
|
|
|
|
\vel -> cat
|
|
|
|
|
{ pcVel = vel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
position = pcPos
|
|
|
|
|
|
|
|
|
@ -199,41 +187,43 @@ instance Collidible Pituicat where
|
|
|
|
|
, V2 18 15
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
collide cat _ NoCollision = cat
|
|
|
|
|
collide cat other collr@(Collision ddt (V2 dirx diry)) =
|
|
|
|
|
let ncat = elasticCollision 0.3 cat other collr
|
|
|
|
|
nvel@(V2 _ vy) = pcVel ncat
|
|
|
|
|
grounded = diry == -1 && abs (vy * ddt) < 2
|
|
|
|
|
fact = fromIntegral <$> V2
|
|
|
|
|
(1 - abs dirx)
|
|
|
|
|
(if diry /= -1 && quadrance nvel > bounceThreshold then 1 else 0)
|
|
|
|
|
in
|
|
|
|
|
ncat
|
|
|
|
|
{ pcVel = nvel * fact
|
|
|
|
|
, pcMoveVel = pcMoveVel ncat * fact
|
|
|
|
|
, pcTMoveVel = pcTMoveVel ncat * fact
|
|
|
|
|
, pcGrounded = grounded
|
|
|
|
|
}
|
|
|
|
|
-- let ncat = (elasticCollision 0.3 cat other collr)
|
|
|
|
|
-- vel@(V2 vx vy) = velocity ncat
|
|
|
|
|
-- moveVel@(V2 mx my) = pcMoveVel cat
|
|
|
|
|
-- nvel = V2
|
|
|
|
|
-- (if abs mx > abs vx
|
|
|
|
|
-- then 0
|
|
|
|
|
-- else (signum vx) * (abs vx - abs mx)
|
|
|
|
|
-- )
|
|
|
|
|
-- ((\(V2 _ y) -> y) (if diry /= 0 then pcVel ncat else pcVel cat))
|
|
|
|
|
-- grounded =
|
|
|
|
|
-- diry == -1 && abs (vy * ddt) < 2
|
|
|
|
|
collide cat [] _ = cat
|
|
|
|
|
{ pcXColl = False
|
|
|
|
|
}
|
|
|
|
|
collide cat collrs@((_, NoCollision):_) _ = cat
|
|
|
|
|
{ pcXColl = any
|
|
|
|
|
(\(_, Collision _ (V2 cx _)) -> cx /= 0)
|
|
|
|
|
(filter ((NoCollision /= ) . snd) collrs)
|
|
|
|
|
}
|
|
|
|
|
collide cat collrs@(collr@((other, Collision ddt (V2 dirx diry))):_) dt =
|
|
|
|
|
-- let ncat = elasticCollision 0.3 cat other collr
|
|
|
|
|
-- nvel@(V2 _ vy) = pcVel ncat
|
|
|
|
|
-- grounded = diry == -1 && abs (vy * ddt) < 2
|
|
|
|
|
-- fact = fromIntegral <$> V2
|
|
|
|
|
-- (1 - abs dirx)
|
|
|
|
|
-- (if diry /= -1 && quadrance nvel > bounceThreshold then 1 else 0)
|
|
|
|
|
-- in
|
|
|
|
|
-- ncat
|
|
|
|
|
-- { pcGrounded = grounded
|
|
|
|
|
-- , pcMoveVel = pcMoveVel ncat *
|
|
|
|
|
-- if dirx /= 0
|
|
|
|
|
-- then V2 0 1
|
|
|
|
|
-- else V2 1 1
|
|
|
|
|
-- , pcVel = nvel *
|
|
|
|
|
-- if dirx /= 0
|
|
|
|
|
-- then V2 0 1
|
|
|
|
|
-- else V2 1 1
|
|
|
|
|
-- { pcVel = nvel * fact
|
|
|
|
|
-- , pcMoveVel = pcMoveVel ncat * fact
|
|
|
|
|
-- , pcTMoveVel = pcTMoveVel ncat * fact
|
|
|
|
|
-- , pcGrounded = grounded
|
|
|
|
|
-- }
|
|
|
|
|
let ncat = elasticCollision 0.3 cat collr dt
|
|
|
|
|
vel@(V2 vx vy) = velocity ncat
|
|
|
|
|
moveVel@(V2 mx my) = pcMoveVel cat
|
|
|
|
|
nvel = V2
|
|
|
|
|
(if abs mx > abs vx
|
|
|
|
|
then 0
|
|
|
|
|
else signum vx * (abs vx - abs mx)
|
|
|
|
|
)
|
|
|
|
|
((\(V2 _ y) -> y) (if diry /= 0 then pcVel ncat else pcVel cat))
|
|
|
|
|
grounded =
|
|
|
|
|
diry == -1 && abs (vy * ddt) < 2
|
|
|
|
|
in
|
|
|
|
|
ncat
|
|
|
|
|
{ pcGrounded = grounded
|
|
|
|
|
, pcXColl = any
|
|
|
|
|
(\(_, Collision _ (V2 cx _)) -> cx /= 0)
|
|
|
|
|
(filter ((NoCollision /=) . snd) collrs) || dirx /= 0
|
|
|
|
|
}
|
|
|
|
|