Added rotating player icon on movement change

This commit is contained in:
John Shaver 2017-06-28 16:55:15 -07:00
parent 1e5616257f
commit 8a2936010a

View file

@ -6,6 +6,7 @@ import Svg.Attributes
exposing exposing
( fill ( fill
, d , d
, transform
) )
import Svg.Path import Svg.Path
exposing exposing
@ -20,7 +21,7 @@ import Svg.Path
, largestArc , largestArc
) )
import AnimationHelpers exposing (calculateAnimation) import AnimationHelpers exposing (calculateAnimation)
import Types exposing (Model) import Types exposing (Model, Direction(Up, Down, Left, Right))
import GLOBALS exposing (character_radius) import GLOBALS exposing (character_radius)
@ -39,6 +40,20 @@ render model =
maxOpen = maxOpen =
90 90
rotate =
case model.player.direction of
Up ->
270
Down ->
90
Left ->
180
Right ->
0
frameCount = frameCount =
calculateAnimation (model.time |> inMilliseconds |> round) cycleTime ( 0, maxOpen * 2 ) calculateAnimation (model.time |> inMilliseconds |> round) cycleTime ( 0, maxOpen * 2 )
@ -48,11 +63,11 @@ render model =
else else
frameCount frameCount
in in
pacman ( x, y ) (degrees openness) pacman ( x, y ) (degrees openness) rotate
pacman : Point -> Float -> Svg msg pacman : Point -> Float -> Float -> Svg msg
pacman position openness = pacman position openness rotate =
let let
opp = opp =
character_radius * sin (openness / 2) character_radius * sin (openness / 2)
@ -62,6 +77,12 @@ pacman position openness =
radiuses = radiuses =
( character_radius, character_radius ) ( character_radius, character_radius )
( centerX, centerY ) =
position
transformValue =
"rotate(" ++ (toString rotate) ++ " " ++ (toString centerX) ++ " " ++ (toString centerY) ++ ")"
in in
g [] g []
[ path [ path
@ -76,6 +97,7 @@ pacman position openness =
) )
] ]
, fill "#ffff00" , fill "#ffff00"
, transform transformValue
] ]
[] []
] ]