aboutsummaryrefslogtreecommitdiff
path: root/src/Step.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2014-10-08 22:13:41 +0200
committerJoris Guyonvarch2014-10-08 22:27:11 +0200
commitd37a301ed39bac823e0f2223b8d229b417e128c7 (patch)
treee7e1155e8678bfb32908452993234078527d6664 /src/Step.elm
parent4521cdf1bb5725c9d497e5fb0c03943ad03a052f (diff)
Adding a power to change the player color that reverse points to catch and points to avoid
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)