diff options
Diffstat (limited to 'src/Update')
-rw-r--r-- | src/Update/CloudUpdate.elm | 2 | ||||
-rw-r--r-- | src/Update/Update.elm | 41 |
2 files changed, 25 insertions, 18 deletions
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm index 86f7e13..ce45beb 100644 --- a/src/Update/CloudUpdate.elm +++ b/src/Update/CloudUpdate.elm @@ -64,7 +64,7 @@ getNewPoint time seed = , initDest = initDest , move initTime initPos initDest time = let delta = time - initTime - move = getWaveMove (pointSpeed delta) (initDest `sub` initPos) 10 10 + move = getMove (pointSpeed delta) (initDest `sub` initPos) in initPos `add` move } , seed'' diff --git a/src/Update/Update.elm b/src/Update/Update.elm index 0187dcf..ef85670 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -5,6 +5,7 @@ module Update.Update import List import Keyboard (KeyCode) import Char (fromCode, toCode) +import Maybe import Model.Player (..) import Model.Point (pointSpeed, pointMove, pointAwayDist) @@ -21,23 +22,29 @@ import Update.CloudUpdate (cloudUpdate) import Input (Input) update : Input -> Game -> Game -update {dir, inputKeysDown, delta} {time, keysDown, score, player, cloud, bestScore, seed} = - let hostilePoints = cloud.points (otherConfig player.config) - in if(playerPointsCollision time player hostilePoints) then - let newBestScore = if(score > bestScore) then score else bestScore - in initialGame seed player.pos player.config newBestScore - else - let newTime = time + delta - newPlayer = playerStep delta dir (newKeyCode keysDown inputKeysDown) player - (newCloud, addScore, newSeed) = cloudUpdate time seed newPlayer cloud - in { time = newTime - , keysDown = inputKeysDown - , score = score + addScore - , player = newPlayer - , cloud = newCloud - , bestScore = bestScore - , seed = newSeed - } +update input game = + let hostilePoints = game.cloud.points (otherConfig game.player.config) + in if(playerPointsCollision game.time game.player hostilePoints) + then + { game + | time <- 0 + , currentScore <- 0 + , cloud <- initCloud + , scores <- game.currentScore :: game.scores + } + else + let newTime = game.time + input.delta + newPlayer = playerStep input.delta input.dir (newKeyCode game.keysDown input.inputKeysDown) game.player + (newCloud, addScore, newSeed) = cloudUpdate game.time game.seed newPlayer game.cloud + in + { game + | time <- newTime + , keysDown <- input.inputKeysDown + , currentScore <- game.currentScore + addScore + , player <- newPlayer + , cloud <- newCloud + , seed <- newSeed + } playerStep : Float -> Vec2 -> (KeyCode -> Bool) -> Player -> Player playerStep dt dir newKey player = |