diff options
author | Joris | 2016-09-04 15:52:17 +0200 |
---|---|---|
committer | Joris | 2016-09-04 15:53:32 +0200 |
commit | 8714c3befcf3f9923cf72e8d992ba6d963c0e6e7 (patch) | |
tree | e5ab35a918a95cbfee2f90dc34f3fe57fac42593 /src/Update.elm | |
parent | cda08750ac7cdd83e73c1110800bea39928ffed9 (diff) |
Upgrade to elm 0.17.1
Diffstat (limited to 'src/Update.elm')
-rw-r--r-- | src/Update.elm | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/Update.elm b/src/Update.elm new file mode 100644 index 0000000..8aea214 --- /dev/null +++ b/src/Update.elm @@ -0,0 +1,79 @@ +module Update exposing + ( update + ) + +import List +import Char exposing (fromCode, toCode, KeyCode) +import Maybe +import Set +import Set exposing (Set) +import Time exposing (Time) +import Keyboard.Extra as Keyboard + +import Msg exposing (Msg(..)) +import Model.Player exposing (..) +import Model.Vec2 exposing (..) +import Model.Config exposing (otherConfig) +import Model.Cloud exposing (..) +import Model exposing (..) +import Model.Round exposing (Round) + +import Utils.Geometry exposing (..) +import Utils.Physics exposing (getNewPosAndSpeed) + +import Update.CloudUpdate exposing (cloudUpdate) + +update : Msg -> Model -> (Model, Cmd Msg) +update msg model = + case msg of + NoOp -> + (model, Cmd.none) + + Time time -> + (updateTime time model, Cmd.none) + + Keyboard keyboardMsg -> + let (keyboard, keyboardCmd) = Keyboard.update keyboardMsg model.keyboard + in ( { model | keyboard = keyboard } + , Cmd.map Keyboard keyboardCmd + ) + + Transform -> + ({ model | transform = True }, Cmd.none) + +updateTime : Time -> Model -> Model +updateTime time model = + let delta = time - model.time + dir = case Keyboard.arrows model.keyboard of {x, y} -> {x = toFloat x, y = toFloat y} + hostilePoints = model.cloud.points (otherConfig model.player.config) + in if(playerPointsCollision model.elapsedTime model.player (getPlayerSize model.currentScore) hostilePoints) + then + { model + | time = time + , elapsedTime = 0 + , currentScore = 0 + , cloud = initCloud + , rounds = (Round model.elapsedTime model.currentScore) :: model.rounds + } + else + let newPlayer = updatePlayer delta model.boardSize dir (Debug.log "transform" model.transform) model.player (getPlayerSize model.currentScore) + (newCloud, addScore, newSeed) = cloudUpdate model.elapsedTime model.boardSize model.seed newPlayer (getPlayerSize model.currentScore) model.cloud model.currentScore + in + { model + | time = time + , elapsedTime = model.elapsedTime + delta + , currentScore = model.currentScore + addScore + , player = newPlayer + , cloud = newCloud + , seed = newSeed + , transform = False + } + +updatePlayer : Float -> Vec2 -> Vec2 -> Bool -> Player -> Float -> Player +updatePlayer dt boardSize dir transform player playerSize = + let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed) + newConfig = if transform then otherConfig player.config else player.config + in { pos = inBoard boardSize playerSize pos + , speed = speed + , config = newConfig + } |