first powerup including effects works
This commit is contained in:
parent
03a577fd18
commit
61451a4a10
5 changed files with 68 additions and 12 deletions
|
@ -11,14 +11,14 @@ data Effect
|
|||
| Antidote
|
||||
| StopTime
|
||||
| Invisibility
|
||||
deriving (Show)
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | The Effect holder type definition
|
||||
data EffectHolder = EffectHolder
|
||||
{ effectDuration :: Double -- ^ Duration of stored effect
|
||||
, effectReleased :: Effect -- ^ The actual effect released
|
||||
}
|
||||
deriving (Show)
|
||||
deriving (Eq, Show)
|
||||
|
||||
class Collidible c => Collectable c where
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ load level progress = do
|
|||
tex
|
||||
False
|
||||
Nothing
|
||||
[]
|
||||
oil = PowerUp
|
||||
(realToFrac <$> (startpos + V2 200 0))
|
||||
(V2 0 0)
|
||||
|
|
|
@ -32,11 +32,6 @@ update level dt = liftIO $ do
|
|||
atomically $ do
|
||||
lmap <- readTMVar (testMap level)
|
||||
let layer = mapLayers lmap V.! fromIntegral (mapWalkLayer lmap)
|
||||
modifyTVar (testPowerups level) $ \pus ->
|
||||
let played = V.map (perform dt) pus
|
||||
collided = V.map (\pu -> performWorldCollision pu layer dt) played
|
||||
in
|
||||
V.map (move dt) collided
|
||||
modifyTVar
|
||||
(testCast level) $ \cast ->
|
||||
let playedCast =
|
||||
|
@ -77,6 +72,42 @@ update level dt = liftIO $ do
|
|||
)
|
||||
walledCast
|
||||
updatedCast <- readTVar (testCast level)
|
||||
oldCat <- fromJust <$> readTVar (testPlayer level)
|
||||
releasedEffects <- stateTVar (testPowerups level) $ \pus ->
|
||||
let living = V.foldl
|
||||
(\acc pu ->
|
||||
let npu = perform dt pu
|
||||
in
|
||||
if puTTL npu > 0
|
||||
then npu `V.cons` acc
|
||||
else acc
|
||||
)
|
||||
V.empty
|
||||
pus
|
||||
indexCollected = V.filter ((/= NoCollision) . snd) $
|
||||
V.zip (V.fromList [0..length living])
|
||||
(V.map
|
||||
(collisionCheck dt oldCat)
|
||||
living
|
||||
)
|
||||
collected = V.foldl
|
||||
(\acc (ind, _) ->
|
||||
(living V.! ind) `V.cons` acc
|
||||
)
|
||||
V.empty
|
||||
indexCollected
|
||||
differ = V.foldl
|
||||
(\acc life -> if life `V.elem` collected
|
||||
then acc
|
||||
else life `V.cons` acc
|
||||
)
|
||||
V.empty
|
||||
living
|
||||
fin = V.map
|
||||
(\pu -> move dt $ performWorldCollision pu layer dt)
|
||||
differ
|
||||
in
|
||||
(collected, fin)
|
||||
modifyTVar
|
||||
(testPlayer level) $ \(Just pituicat) ->
|
||||
let playedCat = perform dt pituicat
|
||||
|
@ -99,7 +130,11 @@ update level dt = liftIO $ do
|
|||
(\(Cast c) cr -> collide playedCat c cr)
|
||||
(updatedCast V.! fst partner, snd partner)
|
||||
walledCat = performWorldCollision castCat layer dt
|
||||
in Just $ move dt walledCat
|
||||
affectedCat = walledCat
|
||||
{ pcEffects = pcEffects walledCat ++
|
||||
map puEffect (V.toList releasedEffects)
|
||||
}
|
||||
in Just $ move dt affectedCat
|
||||
|
||||
performWorldCollision
|
||||
:: (Collidible c)
|
||||
|
|
|
@ -18,6 +18,7 @@ import Classes.Graphics.Bindable
|
|||
import Classes.Prop
|
||||
import Classes.Actor
|
||||
import Classes.Physics
|
||||
import Classes.Collectable
|
||||
|
||||
import Types.Graphics.VertexBuffer
|
||||
import Types.Texture
|
||||
|
@ -36,12 +37,13 @@ data Pituicat = Pituicat
|
|||
, pcTexture :: Texture
|
||||
, pcGrounded :: Bool
|
||||
, pcMoveState :: Maybe Action
|
||||
, pcEffects :: [EffectHolder]
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Drawable Pituicat where
|
||||
|
||||
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _) =
|
||||
toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _ _ _) =
|
||||
( V.fromList [0, 1, 2, 2, 3, 0]
|
||||
, V.fromList
|
||||
[ newVertex
|
||||
|
@ -77,13 +79,18 @@ instance Actor Pituicat where
|
|||
|
||||
perform dt p =
|
||||
let (V2 _ dy) = velocity physCat
|
||||
moveFact =
|
||||
if
|
||||
null (filter ((SpeedUp ==) . effectReleased) (pcEffects p))
|
||||
then 1
|
||||
else 2
|
||||
physCat = (accelerate dt . gravitate constG)
|
||||
(p
|
||||
{ pcAcc = V2 0 0
|
||||
, pcTMoveVel =
|
||||
case pcMoveState p of
|
||||
Just MoveRight -> V2 catMoveVelocity 0
|
||||
Just MoveLeft -> V2 (-catMoveVelocity) 0
|
||||
Just MoveRight -> V2 (catMoveVelocity * moveFact) 0
|
||||
Just MoveLeft -> V2 ((-catMoveVelocity) * moveFact) 0
|
||||
_ -> V2 0 0
|
||||
}
|
||||
)
|
||||
|
@ -93,6 +100,19 @@ instance Actor Pituicat where
|
|||
, pcGrounded = if pcGrounded physCat
|
||||
then not (abs dy * dt > 2)
|
||||
else False
|
||||
, pcEffects =
|
||||
foldl
|
||||
(\acc eff ->
|
||||
let nduration = effectDuration eff - dt
|
||||
in
|
||||
if nduration > 0
|
||||
then
|
||||
eff { effectDuration = nduration} : acc
|
||||
else
|
||||
acc
|
||||
)
|
||||
[]
|
||||
(pcEffects p)
|
||||
}
|
||||
in
|
||||
A.log A.Debug ("*meow* am at: " <> (fromString $ show $ pcPos finalCat)) finalCat
|
||||
|
|
|
@ -26,7 +26,7 @@ data PowerUp = PowerUp
|
|||
, puTexture :: Texture
|
||||
, puEffect :: EffectHolder
|
||||
}
|
||||
deriving (Show)
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Drawable PowerUp where
|
||||
|
||||
|
|
Loading…
Reference in a new issue