aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-15 09:40:58 +0100
committerJoris Guyonvarch2015-03-15 09:40:58 +0100
commitce6775641639943a2aee00fa9c2d684aa434bc21 (patch)
treee5c1b37525cf83f588d82fbf8977ae2839b6e41f
parent87386e8b148c2536214fdaf6c3140853c751d7b4 (diff)
Moving boardSize to Game model
-rw-r--r--src/Model/Board.elm10
-rw-r--r--src/Model/Game.elm3
-rw-r--r--src/Model/Point.elm8
-rw-r--r--src/Update/CloudUpdate.elm44
-rw-r--r--src/Update/Update.elm11
-rw-r--r--src/Utils/Geometry.elm5
-rw-r--r--src/View/Game.elm15
7 files changed, 48 insertions, 48 deletions
diff --git a/src/Model/Board.elm b/src/Model/Board.elm
index 1361cfb..05fd036 100644
--- a/src/Model/Board.elm
+++ b/src/Model/Board.elm
@@ -1,17 +1,17 @@
module Model.Board
- ( boardSize
+ ( initBoardSize
, boardDiagonal
) where
import Model.Vec2 (Vec2)
-boardSize : Vec2
-boardSize =
+initBoardSize : Vec2
+initBoardSize =
{ x = 500
, y = 500
}
-boardDiagonal : Float
-boardDiagonal =
+boardDiagonal : Vec2 -> Float
+boardDiagonal boardSize =
boardSize.x ^ 2 + boardSize.y ^ 2
|> sqrt
diff --git a/src/Model/Game.elm b/src/Model/Game.elm
index 6a9020f..9133ba0 100644
--- a/src/Model/Game.elm
+++ b/src/Model/Game.elm
@@ -11,9 +11,11 @@ import Model.Cloud (..)
import Model.Vec2 (Vec2)
import Model.Config (..)
import Model.Round (Round)
+import Model.Board (initBoardSize)
type alias Game =
{ time : Float
+ , boardSize : Vec2
, keysDown : List KeyCode
, currentScore : Int
, player : Player
@@ -25,6 +27,7 @@ type alias Game =
initialGame : Seed -> Game
initialGame seed =
{ time = 0
+ , boardSize = initBoardSize
, keysDown = []
, currentScore = 0
, player = initPlayer
diff --git a/src/Model/Point.elm b/src/Model/Point.elm
index 41967b6..40043a5 100644
--- a/src/Model/Point.elm
+++ b/src/Model/Point.elm
@@ -27,8 +27,8 @@ pointSize = 10
pointSpeed : Float -> Float
pointSpeed dt = dt / 20
-pointSpawnDist : Float
-pointSpawnDist = boardDiagonal * 3 / 5
+pointSpawnDist : Vec2 -> Float
+pointSpawnDist boardSize = (boardDiagonal boardSize) * 3 / 5
-pointAwayDist : Float
-pointAwayDist = boardDiagonal * 3 / 4
+pointAwayDist : Vec2 -> Float
+pointAwayDist boardSize = (boardDiagonal boardSize) * 3 / 4
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm
index ce45beb..9863650 100644
--- a/src/Update/CloudUpdate.elm
+++ b/src/Update/CloudUpdate.elm
@@ -7,7 +7,7 @@ import Random (..)
import Model.Vec2 (..)
import Model.Player (..)
-import Model.Board (boardSize, boardDiagonal)
+import Model.Board (boardDiagonal)
import Model.Point (..)
import Model.Cloud (..)
import Model.Config (..)
@@ -15,16 +15,16 @@ import Model.Config (..)
import Utils.Geometry (..)
import Utils.Physics (getMove, getWaveMove)
-cloudUpdate : Float -> Seed -> Player -> Cloud -> (Cloud, Int, Seed)
-cloudUpdate time seed player {points, spawn, lastSpawn} =
- let pointsToCatch = presentPoints time (points player.config)
+cloudUpdate : Float -> Vec2 -> Seed -> Player -> Cloud -> (Cloud, Int, Seed)
+cloudUpdate time boardSize seed player {points, spawn, lastSpawn} =
+ let pointsToCatch = presentPoints time boardSize (points player.config)
presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch
addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints)
- presentOtherPoints = presentPoints time (points (otherConfig player.config))
+ presentOtherPoints = presentPoints time boardSize (points (otherConfig player.config))
(newCloud, seed''') =
if time > lastSpawn + spawn then
- let (newPoint1, seed') = getNewPoint time seed
- (newPoint2, seed'') = getNewPoint time seed'
+ let (newPoint1, seed') = getNewPoint time boardSize seed
+ (newPoint2, seed'') = getNewPoint time boardSize seed'
in ( { points config =
if(config == player.config)
then
@@ -49,16 +49,16 @@ cloudUpdate time seed player {points, spawn, lastSpawn} =
)
in (newCloud, addScore, seed''')
-presentPoints : Float -> List Point -> List Point
-presentPoints time points =
- let isPresent point = (distance (pointMove point time) originVec) < pointAwayDist
+presentPoints : Float -> Vec2 -> List Point -> List Point
+presentPoints time boardSize points =
+ let isPresent point = (distance (pointMove point time) originVec) < (pointAwayDist boardSize)
in List.filter isPresent points
-getNewPoint : Float -> Seed -> (Point, Seed)
-getNewPoint time seed =
- let (initPos, seed') = pointInitPos seed
- (initDest, seed'') = pointDestination seed'
+getNewPoint : Float -> Vec2 -> Seed -> (Point, Seed)
+getNewPoint time boardSize seed =
+ let (initPos, seed') = pointInitPos boardSize seed
+ (initDest, seed'') = pointDestination boardSize seed'
in ( { initTime = time
, initPos = initPos
, initDest = initDest
@@ -70,17 +70,17 @@ getNewPoint time seed =
, seed''
)
-pointInitPos : Seed -> (Vec2, Seed)
-pointInitPos seed =
+pointInitPos : Vec2 -> Seed -> (Vec2, Seed)
+pointInitPos boardSize seed =
let (rand, seed') = generate floatGen seed
angle = rand * (degrees 360)
- dist = boardDiagonal * 3 / 5
+ dist = (boardDiagonal boardSize) * 3 / 5
in (polarToCartesian angle dist, seed')
-pointDestination : Seed -> (Vec2, Seed)
-pointDestination seed =
+pointDestination : Vec2 -> Seed -> (Vec2, Seed)
+pointDestination boardSize seed =
let ([r1, r2, r3, r4], seed') = generateMany 4 floatGen seed
- in ( randomBoardPosition (r1, r2) (r3, r4)
+ in ( randomBoardPosition boardSize (r1, r2) (r3, r4)
, seed'
)
@@ -97,8 +97,8 @@ generateMany count gen seed =
floatGen : Generator Float
floatGen = float 0 1
-randomBoardPosition : (Float, Float) -> (Float, Float) -> Vec2
-randomBoardPosition (randomX, randomY) (percentX, percentY) =
+randomBoardPosition : Vec2 -> (Float, Float) -> (Float, Float) -> Vec2
+randomBoardPosition boardSize (randomX, randomY) (percentX, percentY) =
let width = boardSize.x * percentX
height = boardSize.y * percentY
in { x = width * randomX - width / 2
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
index ab68d2e..2183d97 100644
--- a/src/Update/Update.elm
+++ b/src/Update/Update.elm
@@ -8,7 +8,6 @@ import Char (fromCode, toCode)
import Maybe
import Model.Player (..)
-import Model.Point (pointSpeed, pointMove, pointAwayDist)
import Model.Vec2 (..)
import Model.Config (otherConfig)
import Model.Cloud (..)
@@ -35,8 +34,8 @@ update input game =
}
else
let newTime = game.time + input.delta
- newPlayer = playerStep input.delta input.dir (newKeyCode game.keysDown input.inputKeysDown) game.player
- (newCloud, addScore, newSeed) = cloudUpdate game.time game.seed newPlayer game.cloud
+ 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
@@ -47,11 +46,11 @@ update input game =
, seed <- newSeed
}
-playerStep : Float -> Vec2 -> (KeyCode -> Bool) -> Player -> Player
-playerStep dt dir newKey player =
+playerStep : Float -> Vec2 -> Vec2 -> (KeyCode -> Bool) -> Player -> Player
+playerStep dt boardSize dir newKey player =
let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed)
newConfig = if (newKey 69) then otherConfig player.config else player.config
- in { pos = inBoard playerSize pos
+ in { pos = inBoard boardSize playerSize pos
, speed = speed
, config = newConfig
}
diff --git a/src/Utils/Geometry.elm b/src/Utils/Geometry.elm
index 085026f..323422b 100644
--- a/src/Utils/Geometry.elm
+++ b/src/Utils/Geometry.elm
@@ -5,7 +5,6 @@ module Utils.Geometry
) where
import Model.Vec2 (..)
-import Model.Board (boardSize)
polarToCartesian : Float -> Float -> Vec2
polarToCartesian angle dist =
@@ -16,8 +15,8 @@ polarToCartesian angle dist =
distance : Vec2 -> Vec2 -> Float
distance v1 v2 = sqrt((v2.x - v1.x)^2 + (v2.y - v1.y)^2)
-inBoard : Float -> Vec2 -> Vec2
-inBoard size pos =
+inBoard : Vec2 -> Float -> Vec2 -> Vec2
+inBoard boardSize size pos =
let leftX = -boardSize.x / 2 + size
rightX = boardSize.x / 2 - size
bottomY = -boardSize.y / 2 + size
diff --git a/src/View/Game.elm b/src/View/Game.elm
index 0bbea00..c9c58ff 100644
--- a/src/View/Game.elm
+++ b/src/View/Game.elm
@@ -14,7 +14,6 @@ import Model.Vec2 (Vec2)
import Model.Player (..)
import Model.Game (Game)
import Model.Point (..)
-import Model.Board (boardSize)
import Model.Config (..)
gameView : Game -> Element
@@ -22,15 +21,15 @@ 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)
forms =
- boardForms
+ boardForms game.boardSize
++ playerForms game.player
++ whitePointForms
++ blackPointForms
- ++ scoreForms game.currentScore
- in collage (truncate boardSize.x) (truncate boardSize.y) forms
+ ++ scoreForms game.boardSize game.currentScore
+ in collage (truncate game.boardSize.x) (truncate game.boardSize.y) forms
-boardForms : List Form
-boardForms = [filled boardColor (rect boardSize.x boardSize.y)]
+boardForms : Vec2 -> List Form
+boardForms boardSize = [filled boardColor (rect boardSize.x boardSize.y)]
boardColor : Color
boardColor = rgb 103 123 244
@@ -66,8 +65,8 @@ circleForm pos size color =
outlineColor : Color
outlineColor = rgb 34 34 34
-scoreForms : Int -> List Form
-scoreForms score =
+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]