1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module Step where
import Vec2 (..)
import Game (..)
import Player (..)
import Cloud (..)
import Geometry (..)
import Player (playerSpeed)
import Point (pointSpeed, pointMove, pointAwayDist)
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, 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 -> (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)
|