walking animation

This commit is contained in:
nek0 2018-05-30 22:15:49 +02:00
parent f6db4f5e5c
commit fbcc1b0e45
4 changed files with 79 additions and 16 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -81,17 +81,24 @@ load = do
-- (zipWith (\a b -> (a, [b])) [0..] $ [ImgIntrE .. ImgIntrN] ++ [ImgIntrNE])
let imgs = zipWith (\a b -> (a, fromJust b)) [ImgWallAsc ..] mimgs
directions = [E .. N] ++ [NE]
animIds = map (AnimId 0 "standing") directions
animConfigs = map
standIds = map (AnimId 0 "standing") directions
walkIds = map (AnimId 0 "walking") directions
standConfigs = map
(\i -> AnimationConfig (0, i * 74) (64, 74) 1 0 APLoop)
[0 .. length animIds]
animations <- loadAnimationSprites "assets/intruder.png" nvg
(zip animIds animConfigs)
[0 .. length standIds - 1]
walkConfigs = map
(\i -> AnimationConfig (64, i * 74) (64, 74) 6 1 APLoop)
[0 .. length walkIds - 1]
playerStanding <- loadAnimationSprites "assets/intruder.png" nvg
(zip standIds standConfigs)
playerWalking <- loadAnimationSprites "assets/intruder.png" nvg
(zip walkIds walkConfigs)
return UserData
{ state = Menu
, subsystems = subs
, assetImages = M.fromList imgs
, assetAnimations = M.fromList animations
, assetAnimations = M.fromList
(playerStanding ++ playerWalking)
, assetFonts = M.fromList
[ (FontBedstead, "bedstead")
]

View file

@ -320,14 +320,42 @@ updateMap dt = do
stat <- query anim
let npos = pos' + fmap (* (dt * fact')) vel'
aId = asId stat
nstat = case aiName aId of
"walking"
| sqrt (vel' `dot` vel') > 0 ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
| otherwise ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
, aiName = "standing"
}
, asCurrentFrame = 0
}
"standing"
| sqrt (vel' `dot` vel') > 0 ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
, aiName = "walking"
}
, asCurrentFrame = 0
}
| otherwise ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
x -> error ("unknown animation name" ++ x)
ent = unchanged
{ pos = Set npos
, rot = Set $ direction vel' rot'
, anim = Set stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
, anim = Set nstat
}
return ent
emap allEnts $ do
@ -343,6 +371,38 @@ updateMap dt = do
let npos = pos' + fmap (* dt) vel'
dpos@(V2 dpr dpc) = npos - pos'
aId = asId stat
nstat = case aiName aId of
"walking"
| sqrt (vel' `dot` vel') > 0 ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
| otherwise ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
, aiName = "standing"
}
, asCurrentFrame = 0
}
"standing"
| sqrt (vel' `dot` vel') > 0 ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
, aiName = "walking"
}
, asCurrentFrame = 0
}
| otherwise ->
stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
x -> error ("unknown animation name" ++ x)
len = sqrt (dpos `dot` dpos)
lll = (,)
<$> (
@ -374,11 +434,7 @@ updateMap dt = do
(A.log A.Verbose (show lll ++ " " ++ show len) lll)
)
, rot = Set (direction vel' rot')
, anim = Set stat
{ asId = aId
{ aiDirection = direction vel' rot'
}
}
, anim = Set nstat
}
return ent
updateNPCs