aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Level.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Level.elm')
-rw-r--r--src/Model/Level.elm105
1 files changed, 45 insertions, 60 deletions
diff --git a/src/Model/Level.elm b/src/Model/Level.elm
index 9a60b9a..9daa60a 100644
--- a/src/Model/Level.elm
+++ b/src/Model/Level.elm
@@ -1,26 +1,27 @@
module Model.Level exposing
- ( currentLevel
+ ( levelScoreDuration
+ , currentLevel
, currentLevelScore
, currentLevelNumber
, progressiveColor
- , levelScoreDuration
)
import Time exposing (Time)
-import Debug
+import Color as Color exposing (Color)
+import List.Nonempty as NE exposing (Nonempty(..), (:::))
-import Model.Color exposing (..)
-import Model.Vec2 exposing (..)
-import Model.Point exposing (pointSpeed)
+import Model.Vec2 as Vec2 exposing (Vec2)
-import Utils.Physics exposing (getMove, getWaveMove)
+import Utils.Physics as Physics
+import Utils.Color as Color
levelScoreDuration : Int
levelScoreDuration = 20
+type alias Move = Vec2 -> Vec2 -> Time -> Vec2
+
type alias Level =
- { color : Color
- , move : Vec2 -> Vec2 -> Time -> Vec2
+ { moves : Nonempty Move
}
currentLevelScore : Int -> Int
@@ -28,17 +29,10 @@ currentLevelScore currentScore =
currentScore - (currentLevelNumber currentScore - 1) * levelScoreDuration
currentLevelNumber : Int -> Int
-currentLevelNumber currentScore =
- min
- (List.length levels + 1)
- (currentScore // levelScoreDuration + 1)
+currentLevelNumber currentScore = currentScore // levelScoreDuration + 1
currentLevel : Int -> Level
-currentLevel currentScore =
- levels
- |> List.drop (currentScore // levelScoreDuration)
- |> List.head
- |> Maybe.withDefault lastLevel
+currentLevel currentScore = NE.get (currentScore // levelScoreDuration) levels
nextLevel : Int -> Level
nextLevel currentScore = currentLevel (currentScore + levelScoreDuration)
@@ -47,50 +41,41 @@ progressiveColor : Int -> Color
progressiveColor currentScore =
let reminder = currentScore `rem` levelScoreDuration
ratio = progressiveRatio reminder levelScoreDuration
- currentColor = (currentLevel currentScore).color
- nextColor = (nextLevel currentScore).color
- in mergeColors ratio nextColor currentColor
+ currentColor = color currentScore
+ nextColor = color (currentScore + levelScoreDuration)
+ in Color.merge ratio nextColor currentColor
progressiveRatio : Int -> Int -> Float
progressiveRatio a b = (toFloat a ^ 7) / (toFloat b ^ 7)
--- Hue + 35 with gimp each time from the first color
-levels : List Level
-levels =
- [ { color = { red = 156, green = 168, blue = 233 }
- , move = \initPos initDest delta -> getMove (delta / 20) (initDest `sub` initPos)
- }
- , { color = { red = 190, green = 156, blue = 233 }
- , move = \initPos initDest delta -> getWaveMove (delta / 20) (initDest `sub` initPos) 10 10
- }
- , { color = { red = 233, green = 156, blue = 232 }
- , move = \initPos initDest delta -> getMove (delta / 18) (initDest `sub` initPos)
- }
- , { color = { red = 233, green = 156, blue = 187 }
- , move = \initPos initDest delta -> getWaveMove (delta / 18) (initDest `sub` initPos) 20 20
- }
- , { color = { red = 233, green = 171, blue = 156 }
- , move = \initPos initDest delta -> getMove (delta / 13) (initDest `sub` initPos)
- }
- , { color = { red = 233, green = 215, blue = 156 }
- , move = \initPos initDest delta -> getWaveMove (delta / 16) (initDest `sub` initPos) 10 50
- }
- , { color = { red = 206, green = 233, blue = 156 }
- , move = \initPos initDest delta -> getMove (delta / 11) (initDest `sub` initPos)
- }
- , { color = { red = 162, green = 233, blue = 156 }
- , move = \initPos initDest delta -> getWaveMove (delta / 14) (initDest `sub` initPos) 30 15
- }
- , { color = { red = 156, green = 233, blue = 196 }
- , move = \initPos initDest delta -> getMove (delta / 8) (initDest `sub` initPos)
- }
- , { color = { red = 156, green = 225, blue = 233 }
- , move = \initPos initDest delta -> getWaveMove (delta / 12) (initDest `sub` initPos) 30 30
- }
- ]
+initialColor : Color
+initialColor = Color.rgb 156 168 233
-lastLevel : Level
-lastLevel =
- { color = { red = 156, green = 225, blue = 233 }
- , move = \initPos initDest delta -> getWaveMove (delta / 5) (initDest `sub` initPos) 30 30
- }
+color : Int -> Color
+color score = Color.spin (toFloat <| 20 * (score // levelScoreDuration)) initialColor
+
+levels : Nonempty Level
+levels =
+ let ma1 = \initPos initDest delta -> Physics.getMove (delta / 20) (initDest `Vec2.sub` initPos)
+ ma2 = \initPos initDest delta -> Physics.getWaveMove (delta / 20) (initDest `Vec2.sub` initPos) 10 10
+ ma3 = \initPos initDest delta -> Physics.getSawToothMove (delta / 25) (initDest `Vec2.sub` initPos) 30 10
+ mb1 = \initPos initDest delta -> Physics.getMove (delta / 18) (initDest `Vec2.sub` initPos)
+ mb2 = \initPos initDest delta -> Physics.getWaveMove (delta / 18) (initDest `Vec2.sub` initPos) 20 20
+ mb3 = \initPos initDest delta -> Physics.getSawToothMove (delta / 20) (initDest `Vec2.sub` initPos) 30 15
+ mc1 = \initPos initDest delta -> Physics.getMove (delta / 13) (initDest `Vec2.sub` initPos)
+ mc2 = \initPos initDest delta -> Physics.getWaveMove (delta / 16) (initDest `Vec2.sub` initPos) 10 50
+ mc3 = \initPos initDest delta -> Physics.getSawToothMove (delta / 25) (initDest `Vec2.sub` initPos) 100 15
+ in Nonempty
+ { moves = NE.fromElement ma1 }
+ [ { moves = NE.fromElement ma2 }
+ , { moves = NE.fromElement ma3 }
+ , { moves = Nonempty ma1 [ ma2, ma3 ] }
+ , { moves = NE.fromElement mb1 }
+ , { moves = NE.fromElement mb2 }
+ , { moves = NE.fromElement mb3 }
+ , { moves = Nonempty mb1 [ mb2, mb3 ] }
+ , { moves = NE.fromElement mc1 }
+ , { moves = NE.fromElement mc2 }
+ , { moves = NE.fromElement mc3 }
+ , { moves = Nonempty mc1 [ mc2, mc3 ] }
+ ]