Commit 4710e5ac authored by Joris's avatar Joris

Add levels which only change the board color every 20 points

parent 1beb59f7
module Model.Color
( Color
, htmlOutput
, mergeColors
) where
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
}
module Model.Level
( currentLevel
, progressiveColor
) where
import Time exposing (Time)
import Debug
import Model.Color exposing (..)
levelScoreDuration : Int
levelScoreDuration = 20
type alias Level =
{ color : Color
}
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 }
}
, { color = { red = 190, green = 156, blue = 233 }
}
, { color = { red = 233, green = 156, blue = 232 }
}
, { color = { red = 233, green = 156, blue = 187 }
}
, { color = { red = 233, green = 171, blue = 156 }
}
, { color = { red = 233, green = 215, blue = 156 }
}
, { color = { red = 206, green = 233, blue = 156 }
}
, { color = { red = 162, green = 233, blue = 156 }
}
, { color = { red = 156, green = 233, blue = 196 }
}
, { color = { red = 156, green = 225, blue = 233 }
}
]
lastLevel : Level
lastLevel =
{ color = { red = 156, green = 225, blue = 233 }
}
......@@ -4,6 +4,7 @@ module Model.Point
, pointSize
, pointSpeed
, pointSpawnDist
, pointAwayDist
) where
import Model.Vec2 exposing (..)
......@@ -28,3 +29,6 @@ pointSpeed dt = dt / 20
pointSpawnDist : Vec2 -> Float
pointSpawnDist boardSize = (boardDiagonal boardSize) * 2.5 / 5 + pointSize
pointAwayDist : Vec2 -> Float
pointAwayDist boardSize = (boardDiagonal boardSize) * 3 / 5 + pointSize
......@@ -51,7 +51,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} =
presentPoints : Float -> Vec2 -> List Point -> List Point
presentPoints time boardSize points =
let isPresent point = (distance (pointMove point time) originVec) < (pointSpawnDist boardSize)
let isPresent point = (distance (pointMove point time) originVec) < (pointAwayDist boardSize)
in List.filter isPresent points
getNewPoint : Float -> Vec2 -> Seed -> (Point, Seed)
......
......@@ -15,6 +15,8 @@ import Model.Game exposing (Game)
import Model.Point exposing (..)
import Model.Config exposing (..)
import Model.Round exposing (..)
import Model.Level exposing (..)
import Model.Color exposing (htmlOutput)
import View.Round exposing (roundView)
......@@ -27,7 +29,7 @@ renderGame game =
, Svg.Attributes.style ("background-color: " ++ backgroundColor ++ ";")
, viewBox ("0 0 " ++ (toString game.boardSize.x) ++ " " ++ (toString (game.boardSize.y + headerHeight)))
]
[ renderBoard
[ renderBoard game.currentScore
, renderPlayer game.boardSize game.player
, g [] (renderPoints White)
, g [] (renderPoints Black)
......@@ -95,13 +97,13 @@ renderHeader game =
backgroundColor : String
backgroundColor = "#1B203F"
renderBoard : Svg
renderBoard =
renderBoard : Int -> Svg
renderBoard currentScore =
rect
[ y (toString headerHeight)
, width "100%"
, height "100%"
, fill "#677BF4"
, fill (htmlOutput (progressiveColor currentScore))
]
[]
......@@ -170,7 +172,7 @@ renderText boardSize pos content =
hideNewPoints : Vec2 -> Svg
hideNewPoints boardSize =
let size =
(pointSpawnDist boardSize) + pointSize - (Basics.max boardSize.x boardSize.y) / 2
(pointAwayDist boardSize) + pointSize - (Basics.max boardSize.x boardSize.y) / 2
|> toString
in g
[]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment