aboutsummaryrefslogtreecommitdiff
path: root/src/Step.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Step.elm')
-rw-r--r--src/Step.elm44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/Step.elm b/src/Step.elm
index 72d3ae1..08a5f49 100644
--- a/src/Step.elm
+++ b/src/Step.elm
@@ -11,26 +11,38 @@ import Input (Input)
import Physics (getNewPosAndSpeed)
import RandomValues (..)
import CloudStep (cloudStep)
+import Config (otherConfig)
+import Keyboard (KeyCode)
+import Char (fromCode, toCode)
step : Input -> Game -> Game
-step {dir, delta, randomValues} {time, score, player, cloud, bestScore} =
- if(playerPointsCollision time player cloud.redPoints) then
- let newBestScore = if(score > bestScore) then score else bestScore
- in initialGame player.pos newBestScore
- else
- let newTime = time + delta
- newPlayer = playerStep delta dir player
- (newCloud, addScore) = cloudStep time randomValues player cloud
- in { time = newTime
- , score = score + addScore
- , player = newPlayer
- , cloud = newCloud
- , bestScore = bestScore
- }
+step {dir, inputKeysDown, delta, randomValues} {time, keysDown, score, player, cloud, bestScore} =
+ 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 player.pos newBestScore
+ else
+ let newTime = time + delta
+ newPlayer = playerStep delta dir (newKeyCode keysDown inputKeysDown) player
+ (newCloud, addScore) = cloudStep time randomValues newPlayer cloud
+ in { time = newTime
+ , keysDown = inputKeysDown
+ , score = score + addScore
+ , player = newPlayer
+ , cloud = newCloud
+ , bestScore = bestScore
+ }
-playerStep : Float -> Vec2 -> Player -> Player
-playerStep dt dir player =
+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 (toCode 'e')) then otherConfig player.config else player.config
in { pos = inBoard playerSize pos
, speed = speed
+ , config = newConfig
}
+
+newKeyCode : [KeyCode] -> [KeyCode] -> KeyCode -> Bool
+newKeyCode lastKeyCodes newKeyCodes keyCode =
+ let contains = (\l -> l > 0) . length . filter (\kc -> kc == keyCode)
+ in not (contains lastKeyCodes) && (contains newKeyCodes)