Initial movement set to none.
This commit is contained in:
parent
716d59e15c
commit
6ce1e7c15b
3 changed files with 26 additions and 21 deletions
|
@ -7,4 +7,5 @@ init : PlayerModel
|
||||||
init =
|
init =
|
||||||
{ direction = Right
|
{ direction = Right
|
||||||
, location = ( 250, 450 )
|
, location = ( 250, 450 )
|
||||||
|
, moving = False
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ type Msg
|
||||||
type alias PlayerModel =
|
type alias PlayerModel =
|
||||||
{ direction : Direction
|
{ direction : Direction
|
||||||
, location : ( Float, Float )
|
, location : ( Float, Float )
|
||||||
|
, moving : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,27 +18,30 @@ update msg model =
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
Tock timeDiff ->
|
Tock timeDiff ->
|
||||||
let
|
if model.moving then
|
||||||
direction =
|
let
|
||||||
case model.direction of
|
direction =
|
||||||
Right ->
|
case model.direction of
|
||||||
0
|
Right ->
|
||||||
|
0
|
||||||
|
|
||||||
Up ->
|
Up ->
|
||||||
270
|
270
|
||||||
|
|
||||||
Left ->
|
Left ->
|
||||||
180
|
180
|
||||||
|
|
||||||
Down ->
|
Down ->
|
||||||
90
|
90
|
||||||
|
|
||||||
distance =
|
distance =
|
||||||
distanceFromSpeed player_move_speed timeDiff
|
distanceFromSpeed player_move_speed timeDiff
|
||||||
in
|
in
|
||||||
( { model | location = movePosition model.location direction distance }
|
( { model | location = movePosition model.location direction distance }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
Press keyCode ->
|
Press keyCode ->
|
||||||
let
|
let
|
||||||
|
@ -62,16 +65,16 @@ update msg model =
|
||||||
in
|
in
|
||||||
case direction of
|
case direction of
|
||||||
MoveUp ->
|
MoveUp ->
|
||||||
( { model | direction = Up }, Cmd.none )
|
( { model | direction = Up, moving = True }, Cmd.none )
|
||||||
|
|
||||||
MoveDown ->
|
MoveDown ->
|
||||||
( { model | direction = Down }, Cmd.none )
|
( { model | direction = Down, moving = True }, Cmd.none )
|
||||||
|
|
||||||
MoveLeft ->
|
MoveLeft ->
|
||||||
( { model | direction = Left }, Cmd.none )
|
( { model | direction = Left, moving = True }, Cmd.none )
|
||||||
|
|
||||||
MoveRight ->
|
MoveRight ->
|
||||||
( { model | direction = Right }, Cmd.none )
|
( { model | direction = Right, moving = True }, Cmd.none )
|
||||||
|
|
||||||
NoKeyAction ->
|
NoKeyAction ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
Loading…
Reference in a new issue