aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2015-11-15 19:20:42 +0100
committerJoris2015-11-15 19:20:42 +0100
commit4710e5ac30c44ca8b48a0b2b60ea74b1573b084b (patch)
treedb2c1700de3352e2ec73b5f1e41e7d0452489291
parent1beb59f73bc18b2477cf1eb918ff75b8d6282c5a (diff)
downloadcatchvoid-4710e5ac30c44ca8b48a0b2b60ea74b1573b084b.tar.gz
catchvoid-4710e5ac30c44ca8b48a0b2b60ea74b1573b084b.tar.bz2
catchvoid-4710e5ac30c44ca8b48a0b2b60ea74b1573b084b.zip
Add levels which only change the board color every 20 points
-rw-r--r--src/Model/Color.elm22
-rw-r--r--src/Model/Level.elm67
-rw-r--r--src/Model/Point.elm4
-rw-r--r--src/Update/CloudUpdate.elm2
-rw-r--r--src/View/Game.elm12
5 files changed, 101 insertions, 6 deletions
diff --git a/src/Model/Color.elm b/src/Model/Color.elm
new file mode 100644
index 0000000..8452efa
--- /dev/null
+++ b/src/Model/Color.elm
@@ -0,0 +1,22 @@
+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
+ }
diff --git a/src/Model/Level.elm b/src/Model/Level.elm
new file mode 100644
index 0000000..8b28ad3
--- /dev/null
+++ b/src/Model/Level.elm
@@ -0,0 +1,67 @@
+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 }
+ }
diff --git a/src/Model/Point.elm b/src/Model/Point.elm
index a465e40..c0daeaf 100644
--- a/src/Model/Point.elm
+++ b/src/Model/Point.elm
@@ -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
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm
index 6f0005a..cd4ff52 100644
--- a/src/Update/CloudUpdate.elm
+++ b/src/Update/CloudUpdate.elm
@@ -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)
diff --git a/src/View/Game.elm b/src/View/Game.elm
index af7c8de..f99369d 100644
--- a/src/View/Game.elm
+++ b/src/View/Game.elm
@@ -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
[]