From 3a1cbfe23a3d06c3c30828c623a089868cff0670 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 2 Oct 2016 15:34:27 +0200 Subject: Add saw-tooth move and multiple moves per level --- src/Model/Color.elm | 22 ----------- src/Model/Level.elm | 105 ++++++++++++++++++++++----------------------------- src/Model/Player.elm | 2 +- 3 files changed, 46 insertions(+), 83 deletions(-) delete mode 100644 src/Model/Color.elm (limited to 'src/Model') diff --git a/src/Model/Color.elm b/src/Model/Color.elm deleted file mode 100644 index 49ece2b..0000000 --- a/src/Model/Color.elm +++ /dev/null @@ -1,22 +0,0 @@ -module Model.Color exposing - ( Color - , htmlOutput - , mergeColors - ) - -type alias Color = - { red : Int - , green : Int - , blue : Int - } - -htmlOutput : Color -> String -htmlOutput color = "rgb(" ++ (toString color.red) ++ ", " ++ (toString color.green) ++ ", " ++ (toString color.blue) ++ ")" - -mergeColors : Float -> Color -> Color -> Color -mergeColors ratio c1 c2 = - let mergePart x y = truncate (ratio * (toFloat x) + (1 - ratio) * (toFloat y)) - in { red = mergePart c1.red c2.red - , green = mergePart c1.green c2.green - , blue = mergePart c1.blue c2.blue - } 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 ] } + ] diff --git a/src/Model/Player.elm b/src/Model/Player.elm index 37a1a7f..50efb4b 100644 --- a/src/Model/Player.elm +++ b/src/Model/Player.elm @@ -24,7 +24,7 @@ initPlayer = getPlayerSize : Int -> Float getPlayerSize score = - (levelCurve Level.levelScoreDuration 15 (Level.currentLevelScore score)) + 15 + 15 + (levelCurve Level.levelScoreDuration 15 (Level.currentLevelScore score)) levelCurve : Int -> Int -> Int -> Float levelCurve maxAbs maxOrd x = -- cgit v1.2.3