aboutsummaryrefslogtreecommitdiff
path: root/src/Display.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2014-09-02 21:35:58 +0200
committerJoris Guyonvarch2014-09-02 21:35:58 +0200
commitc4ae3b0ee4bd338995cfecf34e0aeb49f05fa70e (patch)
tree71530e9e2cfcbe888cb086593ea1e4d0bcc269a6 /src/Display.elm
Initial commit
Diffstat (limited to 'src/Display.elm')
-rw-r--r--src/Display.elm79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/Display.elm b/src/Display.elm
new file mode 100644
index 0000000..cb9fb86
--- /dev/null
+++ b/src/Display.elm
@@ -0,0 +1,79 @@
+module Display where
+
+import Vec2 (..)
+import Player (..)
+import Game (Game)
+import Enemy (..)
+import Board (boardSize)
+
+display : Game -> Element
+display {time, player, enemyState, bestTime} =
+ let enemyForms = map (enemyForm time) enemyState.enemies
+ forms = boardForms
+ ++ playerForms player
+ ++ enemyForms
+ ++ bestTimeForms bestTime
+ ++ timeForms time
+ in collage (truncate boardSize.x) (truncate boardSize.y) forms
+
+boardForms : [Form]
+boardForms = [filled boardColor (rect boardSize.x boardSize.y)]
+
+boardColor : Color
+boardColor = rgb 34 122 34
+
+playerForms : Player -> [Form]
+playerForms player = [circleForm player.pos playerSize playerColor]
+
+playerColor : Color
+playerColor = rgb 224 224 224
+
+enemyForm : Float -> Enemy -> Form
+enemyForm time enemy =
+ let pos = enemyMove enemy time
+ in circleForm pos enemySize enemyColor
+
+enemyColor : Color
+enemyColor = rgb 170 0 0
+
+circleForm : Vec2 -> Float -> Color -> Form
+circleForm pos size color =
+ let outline = circle size
+ |> filled black
+ inside = circle (size - 2)
+ |> filled color
+ in group [outline, inside]
+ |> move (pos.x, pos.y)
+
+bestTimeForms : Float -> [Form]
+bestTimeForms bestTime =
+ if(bestTime > 0) then
+ let seconds = truncate (bestTime / 1000)
+ text = "Record: " ++ (show seconds)
+ pos =
+ { x = boardSize.x / 2 - 65
+ , y = -boardSize.y / 2 + 30
+ }
+ in [textForm text pos rightAligned]
+ else []
+
+timeForms : Float -> [Form]
+timeForms time =
+ let seconds = truncate (time / 1000)
+ text = (show seconds)
+ pos = { x = 0.0, y = boardSize.y / 2 - 30 }
+ in [textForm text pos centered]
+
+textForm : String -> Vec2 -> (Text -> Element) -> Form
+textForm content pos alignment =
+ let textElement = toText content
+ |> typeface ["calibri", "arial"]
+ |> Text.color textColor
+ |> bold
+ |> alignment
+ in textElement
+ |> toForm
+ |> move (pos.x, pos.y)
+
+textColor : Color
+textColor = rgb 224 224 224