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" logIO Error "Failed to load image assets"
exitFailure exitFailure
playerImgs <- loadPlayerSprite "assets/intruder.png" 64 74 nvg 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 let imgs = zipWith (\a b -> (a, fromJust b)) [ImgWallAsc ..] mimgs
return UserData return UserData
{ state = Menu { state = Menu

View file

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

View file

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