aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-15 20:15:19 +0100
committerJoris Guyonvarch2015-03-15 20:16:14 +0100
commitd5ec91d4d01db6f4d476522d5b14e116435ebb7d (patch)
tree76154fddf12254db1488e17752c41530ef8f6095
parentce6775641639943a2aee00fa9c2d684aa434bc21 (diff)
Displaying the last score in elm graphics instead of in helm html
-rw-r--r--src/Model/Game.elm1
-rw-r--r--src/Update/CloudUpdate.elm4
-rw-r--r--src/Update/Update.elm7
-rw-r--r--src/View/Game.elm57
-rw-r--r--src/View/Page.elm15
-rw-r--r--src/View/Round.elm14
-rw-r--r--style.css51
7 files changed, 57 insertions, 92 deletions
diff --git a/src/Model/Game.elm b/src/Model/Game.elm
index 9133ba0..3520c64 100644
--- a/src/Model/Game.elm
+++ b/src/Model/Game.elm
@@ -5,6 +5,7 @@ module Model.Game
import Random (..)
import Keyboard (KeyCode)
+import Time (Time)
import Model.Player (..)
import Model.Cloud (..)
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm
index 9863650..1988b7f 100644
--- a/src/Update/CloudUpdate.elm
+++ b/src/Update/CloudUpdate.elm
@@ -21,7 +21,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} =
presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch
addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints)
presentOtherPoints = presentPoints time boardSize (points (otherConfig player.config))
- (newCloud, seed''') =
+ (newCloud, seed') =
if time > lastSpawn + spawn then
let (newPoint1, seed') = getNewPoint time boardSize seed
(newPoint2, seed'') = getNewPoint time boardSize seed'
@@ -47,7 +47,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} =
}
, seed
)
- in (newCloud, addScore, seed''')
+ in (newCloud, addScore, seed')
presentPoints : Float -> Vec2 -> List Point -> List Point
presentPoints time boardSize points =
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
index 2183d97..2be00b0 100644
--- a/src/Update/Update.elm
+++ b/src/Update/Update.elm
@@ -30,15 +30,14 @@ update input game =
| time <- 0
, currentScore <- 0
, cloud <- initCloud
- , rounds <- game.rounds `List.append` [Round game.time game.currentScore]
+ , rounds <- (Round game.time game.currentScore) :: game.rounds
}
else
- let newTime = game.time + input.delta
- newPlayer = playerStep input.delta game.boardSize input.dir (newKeyCode game.keysDown input.inputKeysDown) game.player
+ let newPlayer = playerStep input.delta game.boardSize input.dir (newKeyCode game.keysDown input.inputKeysDown) game.player
(newCloud, addScore, newSeed) = cloudUpdate game.time game.boardSize game.seed newPlayer game.cloud
in
{ game
- | time <- newTime
+ | time <- game.time + input.delta
, keysDown <- input.inputKeysDown
, currentScore <- game.currentScore + addScore
, player <- newPlayer
diff --git a/src/View/Game.elm b/src/View/Game.elm
index c9c58ff..ad0e9ea 100644
--- a/src/View/Game.elm
+++ b/src/View/Game.elm
@@ -9,35 +9,42 @@ import Graphics.Element (Element)
import Color (..)
import Text (..)
import Text
+import Time (Time)
import Model.Vec2 (Vec2)
import Model.Player (..)
import Model.Game (Game)
import Model.Point (..)
import Model.Config (..)
+import Model.Round (..)
+
+import View.Round (roundView)
gameView : Game -> Element
gameView game =
- let whitePointForms = List.map (pointForm game.time (configColor White)) (game.cloud.points White)
- blackPointForms = List.map (pointForm game.time (configColor Black)) (game.cloud.points Black)
+ let pointsForm color =
+ List.map (pointForm game.time (configColor color)) (game.cloud.points color)
+ |> group
forms =
- boardForms game.boardSize
- ++ playerForms game.player
- ++ whitePointForms
- ++ blackPointForms
- ++ scoreForms game.boardSize game.currentScore
+ [ boardForm game.boardSize
+ , playerForm game.player
+ , pointsForm White
+ , pointsForm Black
+ , scoreForm game.boardSize game.time game.rounds game.currentScore
+ ]
in collage (truncate game.boardSize.x) (truncate game.boardSize.y) forms
-boardForms : Vec2 -> List Form
-boardForms boardSize = [filled boardColor (rect boardSize.x boardSize.y)]
+boardForm : Vec2 -> Form
+boardForm boardSize =
+ filled boardColor (rect boardSize.x boardSize.y)
boardColor : Color
boardColor = rgb 103 123 244
-playerForms : Player -> List Form
-playerForms player =
+playerForm : Player -> Form
+playerForm player =
let playerColor = configColor player.config
- in [circleForm player.pos playerSize playerColor]
+ in circleForm player.pos playerSize playerColor
playerColor : Color
playerColor = rgb 224 224 224
@@ -65,20 +72,28 @@ circleForm pos size color =
outlineColor : Color
outlineColor = rgb 34 34 34
-scoreForms : Vec2 -> Int -> List Form
-scoreForms boardSize score =
- let text = (toString score)
- scorePos = { x = 0.0, y = boardSize.y / 2 - 35 }
- in [textForm text scorePos centered]
+scoreForm : Vec2 -> Time -> List Round -> Int -> Form
+scoreForm boardSize currentRoundTime rounds score =
+ let scorePos =
+ { x = 0.0
+ , y = boardSize.y / 2 - 35
+ }
+ in if currentRoundTime < 5000 && (not (List.isEmpty rounds))
+ then
+ List.head rounds
+ |> roundView
+ |> textForm scorePos
+ else
+ textForm scorePos (toString score)
-textForm : String -> Vec2 -> (Text -> Element) -> Form
-textForm content pos alignment =
+textForm : Vec2 -> String -> Form
+textForm pos content =
let textElement = fromString content
- |> Text.height 30
+ |> Text.height 24
|> typeface ["calibri", "arial"]
|> Text.color textColor
|> bold
- |> alignment
+ |> centered
in textElement
|> toForm
|> move (pos.x, pos.y)
diff --git a/src/View/Page.elm b/src/View/Page.elm
index c85cf91..88b641e 100644
--- a/src/View/Page.elm
+++ b/src/View/Page.elm
@@ -14,7 +14,7 @@ import Model.Game (Game)
import Model.Round (..)
import View.Game (gameView)
-import View.Time (timeView)
+import View.Round (roundView)
pageView : Game -> Html
pageView game =
@@ -41,12 +41,6 @@ pageView game =
|> text
]
)
- , ul
- [ class "rounds" ]
- ( List.map
- (\round -> li [] [ text (roundView round) ])
- game.rounds
- )
, a
[ href "https://github.com/guyonvarch/catchvoid" ]
[ img
@@ -63,10 +57,3 @@ pageView game =
[]
]
]
-
-roundView : Round -> String
-roundView round =
- let score = toString round.score
- hits = "hit" ++ (if round.score > 1 then "s" else "")
- duration = timeView round.duration
- in score ++ " " ++ hits ++ " within " ++ duration
diff --git a/src/View/Round.elm b/src/View/Round.elm
new file mode 100644
index 0000000..81f4f8c
--- /dev/null
+++ b/src/View/Round.elm
@@ -0,0 +1,14 @@
+module View.Round
+ ( roundView
+ ) where
+
+import Model.Round (..)
+
+import View.Time (timeView)
+
+roundView : Round -> String
+roundView round =
+ let score = toString round.score
+ hits = "hit" ++ (if round.score > 1 then "s" else "")
+ duration = timeView round.duration
+ in score ++ " " ++ hits ++ " within " ++ duration
diff --git a/style.css b/style.css
index 763cb22..6499535 100644
--- a/style.css
+++ b/style.css
@@ -67,54 +67,3 @@ p {
color: white;
}
}
-
-ul.rounds {
- padding-left: 0;
- color: white;
- list-style-type: none;
- position: absolute;
- width: 300px;
- left: 50%;
- margin-left: -150px;
- top: 110px;
-}
-
-ul.rounds > li {
- background-color: #333333;
- text-align: center;
- border-radius: 2px;
- animation: hide 5s ease;
-
- opacity: 0;
- height: 0px;
- line-height: 0px;
- margin-bottom: 0px;
-}
-
-@keyframes hide {
- 0% {
- opacity: 1;
- height: 40px;
- line-height: 40px;
- margin-bottom: 10px;
- }
- 90% {
- opacity: 1;
- height: 40px;
- line-height: 40px;
- margin-bottom: 10px;
- }
- 95% {
- opacity: 0;
- height: 40px;
- line-height: 40px;
- margin-bottom: 10px;
- }
- 100% {
- opacity: 0;
- height: 0px;
- line-height: 0px;
- margin-bottom: 0px;
- }
-}
-