Commit d5ec91d4 authored by Joris Guyonvarch's avatar Joris Guyonvarch

Displaying the last score in elm graphics instead of in helm html

parent ce677564
......@@ -5,6 +5,7 @@ module Model.Game
import Random (..)
import Keyboard (KeyCode)
import Time (Time)
import Model.Player (..)
import Model.Cloud (..)
......
......@@ -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 =
......
......@@ -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
......
......@@ -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)
......
......@@ -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
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
......@@ -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;
}
}
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