Level.elm 3.15 KB
Newer Older
1 2
module Model.Level
  ( currentLevel
3
  , currentLevelScore
4
  , currentLevelNumber
5
  , progressiveColor
6
  , levelScoreDuration
7 8 9 10 11 12
  ) where

import Time exposing (Time)
import Debug

import Model.Color exposing (..)
13 14 15 16
import Model.Vec2 exposing (..)
import Model.Point exposing (pointSpeed)

import Utils.Physics exposing (getMove, getWaveMove)
17 18

levelScoreDuration : Int
19
levelScoreDuration = 20
20 21 22

type alias Level =
  { color : Color
23
  , move : Vec2 -> Vec2 -> Time -> Vec2
24 25
  }

26 27 28 29
currentLevelScore : Int -> Int
currentLevelScore currentScore =
  currentScore - (currentLevelNumber currentScore - 1) * levelScoreDuration

30 31 32 33 34 35
currentLevelNumber : Int -> Int
currentLevelNumber currentScore =
  min
    (List.length levels + 1)
    (currentScore // levelScoreDuration + 1)

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
currentLevel : Int -> Level
currentLevel currentScore =
  levels
    |> List.drop (currentScore // levelScoreDuration)
    |> List.head
    |> Maybe.withDefault lastLevel

nextLevel : Int -> Level
nextLevel currentScore = currentLevel (currentScore + levelScoreDuration)

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

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 }
Joris's avatar
Joris committed
61
    , move = \initPos initDest delta -> getMove (delta / 20) (initDest `sub` initPos)
62 63
    }
  , { color = { red = 190, green = 156, blue = 233 }
Joris's avatar
Joris committed
64
    , move = \initPos initDest delta -> getWaveMove (delta / 20) (initDest `sub` initPos) 10 10
65 66
    }
  , { color = { red = 233, green = 156, blue = 232 }
Joris's avatar
Joris committed
67
    , move = \initPos initDest delta -> getMove (delta / 18) (initDest `sub` initPos)
68 69
    }
  , { color = { red = 233, green = 156, blue = 187 }
Joris's avatar
Joris committed
70
    , move = \initPos initDest delta -> getWaveMove (delta / 18) (initDest `sub` initPos) 20 20
71 72
    }
  , { color = { red = 233, green = 171, blue = 156 }
Joris's avatar
Joris committed
73
    , move = \initPos initDest delta -> getMove (delta / 13) (initDest `sub` initPos)
74 75
    }
  , { color = { red = 233, green = 215, blue = 156 }
Joris's avatar
Joris committed
76
    , move = \initPos initDest delta -> getWaveMove (delta / 16) (initDest `sub` initPos) 10 50
77 78
    }
  , { color = { red = 206, green = 233, blue = 156 }
Joris's avatar
Joris committed
79
    , move = \initPos initDest delta -> getMove (delta / 11) (initDest `sub` initPos)
80 81
    }
  , { color = { red = 162, green = 233, blue = 156 }
Joris's avatar
Joris committed
82
    , move = \initPos initDest delta -> getWaveMove (delta / 14) (initDest `sub` initPos) 30 15
83 84
    }
  , { color = { red = 156, green = 233, blue = 196 }
Joris's avatar
Joris committed
85
    , move = \initPos initDest delta -> getMove (delta / 8) (initDest `sub` initPos)
86 87
    }
  , { color = { red = 156, green = 225, blue = 233 }
Joris's avatar
Joris committed
88
    , move = \initPos initDest delta -> getWaveMove (delta / 12) (initDest `sub` initPos) 30 30
89 90 91 92 93 94
    }
  ]

lastLevel : Level
lastLevel =
  { color = { red = 156, green = 225, blue = 233 }
Joris's avatar
Joris committed
95
  , move = \initPos initDest delta -> getWaveMove (delta / 5) (initDest `sub` initPos) 30 30
96
  }