aboutsummaryrefslogtreecommitdiff
path: root/src/Update/Update.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update/Update.elm')
-rw-r--r--src/Update/Update.elm41
1 files changed, 24 insertions, 17 deletions
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 =