From 17a58e0c4c67f27d87635bf1b2ca50fb11795ad3 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 7 Mar 2015 15:12:02 +0100 Subject: Organizing source code with subdirectories --- src/Update/Update.elm | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Update/Update.elm (limited to 'src/Update/Update.elm') diff --git a/src/Update/Update.elm b/src/Update/Update.elm new file mode 100644 index 0000000..0187dcf --- /dev/null +++ b/src/Update/Update.elm @@ -0,0 +1,54 @@ +module Update.Update + ( update + ) where + +import List +import Keyboard (KeyCode) +import Char (fromCode, toCode) + +import Model.Player (..) +import Model.Point (pointSpeed, pointMove, pointAwayDist) +import Model.Vec2 (..) +import Model.Config (otherConfig) +import Model.Cloud (..) +import Model.Game (..) + +import Utils.Geometry (..) +import Utils.Physics (getNewPosAndSpeed) + +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 + } + +playerStep : Float -> Vec2 -> (KeyCode -> Bool) -> Player -> Player +playerStep dt dir newKey player = + let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed) + newConfig = if (newKey 69) then otherConfig player.config else player.config + in { pos = inBoard playerSize pos + , speed = speed + , config = newConfig + } + +newKeyCode : List KeyCode -> List KeyCode -> KeyCode -> Bool +newKeyCode lastKeyCodes newKeyCodes keyCode = + let contains = not << List.isEmpty << List.filter (\kc -> kc == keyCode) + in not (contains lastKeyCodes) && (contains newKeyCodes) -- cgit v1.2.3