From 6ce1e7c15b17491957212f8cba0f833a1fbc8d4f Mon Sep 17 00:00:00 2001 From: John Shaver Date: Wed, 28 Jun 2017 14:12:11 -0700 Subject: [PATCH] Initial movement set to none. --- src/Init/Player.elm | 1 + src/Types.elm | 1 + src/Updates/Player.elm | 45 ++++++++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Init/Player.elm b/src/Init/Player.elm index 8dc3512..f1acddf 100644 --- a/src/Init/Player.elm +++ b/src/Init/Player.elm @@ -7,4 +7,5 @@ init : PlayerModel init = { direction = Right , location = ( 250, 450 ) + , moving = False } diff --git a/src/Types.elm b/src/Types.elm index 1bb89bb..7af9858 100644 --- a/src/Types.elm +++ b/src/Types.elm @@ -34,6 +34,7 @@ type Msg type alias PlayerModel = { direction : Direction , location : ( Float, Float ) + , moving : Bool } diff --git a/src/Updates/Player.elm b/src/Updates/Player.elm index a2c4d3f..f9cdc5a 100644 --- a/src/Updates/Player.elm +++ b/src/Updates/Player.elm @@ -18,27 +18,30 @@ update msg model = ( model, Cmd.none ) Tock timeDiff -> - let - direction = - case model.direction of - Right -> - 0 + if model.moving then + let + direction = + case model.direction of + Right -> + 0 - Up -> - 270 + Up -> + 270 - Left -> - 180 + Left -> + 180 - Down -> - 90 + Down -> + 90 - distance = - distanceFromSpeed player_move_speed timeDiff - in - ( { model | location = movePosition model.location direction distance } - , Cmd.none - ) + distance = + distanceFromSpeed player_move_speed timeDiff + in + ( { model | location = movePosition model.location direction distance } + , Cmd.none + ) + else + ( model, Cmd.none ) Press keyCode -> let @@ -62,16 +65,16 @@ update msg model = in case direction of MoveUp -> - ( { model | direction = Up }, Cmd.none ) + ( { model | direction = Up, moving = True }, Cmd.none ) MoveDown -> - ( { model | direction = Down }, Cmd.none ) + ( { model | direction = Down, moving = True }, Cmd.none ) MoveLeft -> - ( { model | direction = Left }, Cmd.none ) + ( { model | direction = Left, moving = True }, Cmd.none ) MoveRight -> - ( { model | direction = Right }, Cmd.none ) + ( { model | direction = Right, moving = True }, Cmd.none ) NoKeyAction -> ( model, Cmd.none )