aboutsummaryrefslogtreecommitdiff
path: root/src/View/Game.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/Game.elm')
-rw-r--r--src/View/Game.elm153
1 files changed, 126 insertions, 27 deletions
diff --git a/src/View/Game.elm b/src/View/Game.elm
index abe7a15..af7c8de 100644
--- a/src/View/Game.elm
+++ b/src/View/Game.elm
@@ -1,5 +1,5 @@
module View.Game
- ( render
+ ( renderGame
) where
import Html exposing (Html)
@@ -18,32 +18,96 @@ import Model.Round exposing (..)
import View.Round exposing (roundView)
-render : Game -> Html
-render game =
- let renderPoints config = List.map (renderPoint game.time config) (game.cloud.points config)
+renderGame : Game -> Html
+renderGame game =
+ let renderPoints config = List.map (renderPoint game.boardSize game.time config) (game.cloud.points config)
in svg
- [ width (toString game.boardSize.x)
- , height (toString game.boardSize.y)
+ [ width "100%"
+ , height "100%"
+ , Svg.Attributes.style ("background-color: " ++ backgroundColor ++ ";")
+ , viewBox ("0 0 " ++ (toString game.boardSize.x) ++ " " ++ (toString (game.boardSize.y + headerHeight)))
]
[ renderBoard
- , renderPlayer game.player
+ , renderPlayer game.boardSize game.player
, g [] (renderPoints White)
, g [] (renderPoints Black)
, renderScore game.boardSize game.time game.rounds game.currentScore
+ , hideNewPoints game.boardSize
+ , renderHeader game
]
+headerHeight : Float
+headerHeight = 115
+
+renderHeader : Game -> Svg
+renderHeader game =
+ g
+ []
+ [ rect
+ [ width "100%"
+ , height (toString headerHeight)
+ , fill "#1B203F"
+ ]
+ []
+ , text'
+ [ x "10"
+ , y "45"
+ , fontSize "36"
+ , fill "white"
+ , fontWeight "bold"
+ ]
+ [ text "cAtchVoid" ]
+ , text'
+ [ fill "white"
+ , fontSize "12"
+ , fontStyle "italic"
+ ]
+ [ tspan
+ [ x (toString (game.boardSize.x / 2))
+ , y "75"
+ , textAnchor "middle"
+ ]
+ [ text "Catch the points of your color, avoid the other points." ]
+ , tspan
+ [ x (toString (game.boardSize.x / 2))
+ , y "92"
+ , textAnchor "middle"
+ ]
+ [ text "Use the arrow keys to move and 'e' to change your color." ]
+ ]
+ , ( case maybeBestRound game.rounds of
+ Nothing ->
+ text ""
+ Just bestRound ->
+ text'
+ [ fill "yellow"
+ , x "355"
+ , y "38"
+ , fontSize "13"
+ ]
+ [ tspan
+ [ textAnchor "middle" ]
+ [ text ("Top: " ++ roundView bestRound) ]
+ ]
+ )
+ ]
+
+backgroundColor : String
+backgroundColor = "#1B203F"
+
renderBoard : Svg
renderBoard =
rect
- [ width "100%"
+ [ y (toString headerHeight)
+ , width "100%"
, height "100%"
, fill "#677BF4"
]
[]
-renderPlayer : Player -> Svg
-renderPlayer player =
- renderCircle player.pos playerSize (playerColor player.config)
+renderPlayer : Vec2 -> Player -> Svg
+renderPlayer boardSize player =
+ renderCircle boardSize player.pos playerSize (playerColor player.config)
playerColor : Config -> String
playerColor config =
@@ -51,10 +115,10 @@ playerColor config =
White -> "#F0F0F0"
Black -> "#0E1121"
-renderPoint : Float -> Config -> Point -> Svg
-renderPoint time config point =
+renderPoint : Vec2 -> Float -> Config -> Point -> Svg
+renderPoint boardSize time config point =
let pos = pointMove point time
- in renderCircle pos pointSize (playerColor config)
+ in renderCircle boardSize pos pointSize (playerColor config)
pointColor : Config -> String
pointColor config =
@@ -62,15 +126,13 @@ pointColor config =
White -> "white"
Black -> "black"
-renderCircle : Vec2 -> Float -> String -> Svg
-renderCircle pos size color =
+renderCircle : Vec2 -> Vec2 -> Float -> String -> Svg
+renderCircle boardSize pos size color =
circle
- [ cx (toString (pos.x + 250))
- , cy (toString (-1 * pos.y + 250))
+ [ cx (toString (pos.x + boardSize.x / 2))
+ , cy (toString (-1 * pos.y + boardSize.y / 2 + headerHeight))
, r (toString size)
, fill color
- , stroke "#222222"
- , strokeWidth "1"
]
[]
@@ -84,17 +146,17 @@ renderScore boardSize currentRoundTime rounds score =
then
case List.head rounds of
Just round ->
- renderText scorePos (roundView round)
+ renderText boardSize scorePos (roundView round)
Nothing ->
- renderText scorePos (toString score)
+ renderText boardSize scorePos (toString score)
else
- renderText scorePos (toString score)
+ renderText boardSize scorePos (toString score)
-renderText : Vec2 -> String -> Svg
-renderText pos content =
+renderText : Vec2 -> Vec2 -> String -> Svg
+renderText boardSize pos content =
text'
- [ x (toString (250 + pos.x))
- , y (toString (-1 * pos.y + 250))
+ [ x (toString (pos.x + boardSize.x / 2))
+ , y (toString (-1 * pos.y + boardSize.y / 2 + headerHeight))
, fontFamily "calibri"
, fontSize "24"
, color "#0E1121"
@@ -104,3 +166,40 @@ renderText pos content =
[ textAnchor "middle" ]
[ text content ]
]
+
+hideNewPoints : Vec2 -> Svg
+hideNewPoints boardSize =
+ let size =
+ (pointSpawnDist boardSize) + pointSize - (Basics.max boardSize.x boardSize.y) / 2
+ |> toString
+ in g
+ []
+ [ rect
+ [ x ("-" ++ size)
+ , width size
+ , height "100%"
+ , fill backgroundColor
+ ]
+ []
+ , rect
+ [ x (toString boardSize.x)
+ , width size
+ , height "100%"
+ , fill backgroundColor
+ ]
+ []
+ , rect
+ [ y ("-" ++ size)
+ , width "100%"
+ , height size
+ , fill backgroundColor
+ ]
+ []
+ , rect
+ [ y (toString (boardSize.y + headerHeight))
+ , width "100%"
+ , height size
+ , fill backgroundColor
+ ]
+ []
+ ]