trying to prepare animations

This commit is contained in:
nek0 2018-05-27 16:03:31 +02:00
parent 2761777ff9
commit 81abbaf91e
3 changed files with 61 additions and 28 deletions

View file

@ -78,7 +78,7 @@ load = do
logIO Error "Failed to load image assets"
exitFailure
playerImgs <- loadPlayerSprite "assets/intruder.png" 64 74 nvg
(zipWith (\a b -> (a, [b])) [0..] [ImgIntrE .. ImgIntrNE])
(zipWith (\a b -> (a, [b])) [0..] $ [ImgIntrE .. ImgIntrN] ++ [ImgIntrNE])
let imgs = zipWith (\a b -> (a, fromJust b)) [ImgWallAsc ..] mimgs
return UserData
{ state = Menu

View file

@ -56,14 +56,20 @@ loadMap = do
(inter, rps) <- liftIO $ placeInteriorIO mat imgmat exits gr
liftIO $ logIO A.Debug ("number of reachpoints: " ++ show (length rps))
let nnex = Prelude.filter (\p -> pointType p /= RoomExit) rps
playerAnim = Animations
{ animStand = Map.fromList
(zip [NE .. N] [ImgIntrNE .. ImgIntrN])
}
npcposs <- placeNPCs inter mat rps gr 50 -- (length nnex)
liftIO $ A.logIO A.Debug $ "number of placed NPCs: " ++ show (length npcposs)
(nws, _) <- liftIO $ yieldSystemT (worldState ud) $ do
void $ createEntity $ newEntity
{ pos = Just (V2 20.5 20.5)
, vel = Just (V2 0 0)
, player = Just ()
, rot = Just SE
createEntity $ newEntity
{ pos = Just (V2 20.5 20.5)
, vel = Just (V2 0 0)
, player = Just ()
, rot = Just SE
, anim = Just playerAnim
, animCurrFrame = Just (0, 0)
}
void $ mapM_ (\npcpos@(V2 nr nc) -> do
-- ttl <- liftIO $ randomRIO (5, 30)
@ -71,11 +77,13 @@ loadMap = do
future <- liftIO $ newEmptyMVar
_ <- liftIO $ forkOS $ getPath (fmap floor npcpos) future nnex inter
createEntity $ newEntity
{ pos = Just (V2 (nr + 0.5) (nc + 0.5))
, vel = Just (V2 0 0)
, velFact = Just fact
, rot = Just SE
, npcState = Just (NPCStanding 0 future)
{ pos = Just (V2 (nr + 0.5) (nc + 0.5))
, vel = Just (V2 0 0)
, velFact = Just fact
, rot = Just SE
, npcState = Just (NPCStanding 0 future)
, anim = Just playerAnim
, animCurrFrame = Just (0, 0)
}
) npcposs
uu <- partSubscribe m movePlayer

View file

@ -20,14 +20,15 @@ import Types.Map
import Types.ReachPoint
data UserData = UserData
{ state :: State
, subsystems :: Subsystems
, assetImages :: M.Map ImgId Image
, assetFonts :: M.Map FontId T.Text
, nano :: Context
, uuid :: [UUID]
, worldState :: SystemState Entity IO
, stateData :: StateData
{ state :: State
, subsystems :: Subsystems
, assetImages :: M.Map ImgId Image
, assetFonts :: M.Map FontId T.Text
, assetAnimations :: M.Map AnimId Animation
, nano :: Context
, uuid :: [UUID]
, worldState :: SystemState Entity IO
, stateData :: StateData
}
data State
@ -62,6 +63,7 @@ data ImgId
| ImgMiscTable3
| ImgMiscTable4
| ImgMiscTableCorner
| ImgIntrNE
| ImgIntrE
| ImgIntrSE
| ImgIntrS
@ -69,7 +71,6 @@ data ImgId
| ImgIntrW
| ImgIntrNW
| ImgIntrN
| ImgIntrNE
deriving (Show, Eq, Ord, Enum)
isWall :: ImgId -> Bool
@ -165,14 +166,15 @@ dirToImgId N = ImgIntrN
dirToImgId NE = ImgIntrNE
data Entity f = Entity
{ pos :: Component f 'Field (V2 Double)
, gridPos :: Component f 'Field (V2 Int)
, vel :: Component f 'Field (V2 Double)
, velFact :: Component f 'Field Double
, rot :: Component f 'Field Direction
, obstacle :: Component f 'Field (Boundaries Double)
, player :: Component f 'Unique ()
, npcState :: Component f 'Field NPCState
{ pos :: Component f 'Field (V2 Double)
, gridPos :: Component f 'Field (V2 Int)
, vel :: Component f 'Field (V2 Double)
, velFact :: Component f 'Field Double
, rot :: Component f 'Field Direction
, obstacle :: Component f 'Field (Boundaries Double)
, player :: Component f 'Unique ()
, npcState :: Component f 'Field NPCState
, anim :: Component f 'Field AnimState
}
deriving (Generic)
@ -241,3 +243,26 @@ generalUnSubscribe t uu =
liftIO $ atomically $ modifyTVar' t (filter (`filterMsg` uu))
where
filterMsg (u, _) p = u /= p
-- ANIMATIONS
data AnimId = AnimId
{ aiVariation :: Int
, aiDirection :: Direction
}
data AnimState = AnimState
{ asId :: AnimId
, asCurrentFrame :: Int
, asElapsedTime :: Double
}
data AnimPlayback
= APLoop
| APOnce
data Animation = Animation
{ animDuration :: Double
, animSprites :: [Image]
, animPLay :: AnimPlayback
}