aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-15 09:40:58 +0100
committerJoris Guyonvarch2015-03-15 09:40:58 +0100
commitce6775641639943a2aee00fa9c2d684aa434bc21 (patch)
treee5c1b37525cf83f588d82fbf8977ae2839b6e41f /src/Update
parent87386e8b148c2536214fdaf6c3140853c751d7b4 (diff)
Moving boardSize to Game model
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/CloudUpdate.elm44
-rw-r--r--src/Update/Update.elm11
2 files changed, 27 insertions, 28 deletions
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
}