aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
authorJoris2016-09-04 15:52:17 +0200
committerJoris2016-09-04 15:53:32 +0200
commit8714c3befcf3f9923cf72e8d992ba6d963c0e6e7 (patch)
treee5ab35a918a95cbfee2f90dc34f3fe57fac42593 /src/Update
parentcda08750ac7cdd83e73c1110800bea39928ffed9 (diff)
Upgrade to elm 0.17.1
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/CloudUpdate.elm23
-rw-r--r--src/Update/Update.elm61
2 files changed, 5 insertions, 79 deletions
diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm
index 359f02c..559acc9 100644
--- a/src/Update/CloudUpdate.elm
+++ b/src/Update/CloudUpdate.elm
@@ -1,9 +1,9 @@
-module Update.CloudUpdate
+module Update.CloudUpdate exposing
( cloudUpdate
- ) where
+ )
import List
-import Random exposing (..)
+import Random.Pcg as Random exposing (Seed, Generator)
import Model.Vec2 exposing (..)
import Model.Player exposing (..)
@@ -71,14 +71,14 @@ getNewPoint elapsedTime boardSize seed currentScore =
pointInitPos : Vec2 -> Seed -> (Vec2, Seed)
pointInitPos boardSize seed =
- let (rand, seed') = generate floatGen seed
+ let (rand, seed') = Random.step (Random.float 0 1) seed
angle = rand * (degrees 360)
dist = pointSpawnDist boardSize
in (polarToCartesian angle dist, seed')
pointDestination : Vec2 -> Seed -> (Vec2, Seed)
pointDestination boardSize seed =
- case generateMany 4 floatGen seed of
+ case Random.step (Random.list 4 (Random.float 0 1)) seed of
([r1, r2, r3, r4], seed') ->
( randomBoardPosition boardSize (r1, r2) (r3, r4)
, seed'
@@ -88,19 +88,6 @@ pointDestination boardSize seed =
, seed
)
-generateMany : Int -> Generator a -> Seed -> (List a, Seed)
-generateMany count gen seed =
- if count == 0
- then
- ([], seed)
- else
- let (rand, seed') = generate gen seed
- (randList, seed'') = generateMany (count - 1) gen seed'
- in (rand :: randList, seed'')
-
-floatGen : Generator Float
-floatGen = float 0 1
-
randomBoardPosition : Vec2 -> (Float, Float) -> (Float, Float) -> Vec2
randomBoardPosition boardSize (randomX, randomY) (percentX, percentY) =
let width = boardSize.x * percentX
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
deleted file mode 100644
index 2514aac..0000000
--- a/src/Update/Update.elm
+++ /dev/null
@@ -1,61 +0,0 @@
-module Update.Update
- ( update
- ) where
-
-import List
-import Char exposing (fromCode, toCode, KeyCode)
-import Maybe
-import Set
-import Set exposing (Set)
-
-import Model.Player exposing (..)
-import Model.Vec2 exposing (..)
-import Model.Config exposing (otherConfig)
-import Model.Cloud exposing (..)
-import Model.Game exposing (..)
-import Model.Round exposing (Round)
-
-import Utils.Geometry exposing (..)
-import Utils.Physics exposing (getNewPosAndSpeed)
-
-import Update.CloudUpdate exposing (cloudUpdate)
-
-import Input exposing (Input)
-
-update : Input -> Game -> Game
-update input game =
- let hostilePoints = game.cloud.points (otherConfig game.player.config)
- in if(playerPointsCollision game.elapsedTime game.player (getPlayerSize game.currentScore) hostilePoints)
- then
- { game
- | elapsedTime = 0
- , currentScore = 0
- , cloud = initCloud
- , rounds = (Round game.elapsedTime game.currentScore) :: game.rounds
- }
- else
- let newPlayer = playerStep input.delta game.boardSize input.dir (newKeyCode game.keysDown input.inputKeysDown) game.player (getPlayerSize game.currentScore)
- (newCloud, addScore, newSeed) = cloudUpdate game.elapsedTime game.boardSize game.seed newPlayer (getPlayerSize game.currentScore) game.cloud game.currentScore
- in
- { game
- | elapsedTime = game.elapsedTime + input.delta
- , keysDown = input.inputKeysDown
- , currentScore = game.currentScore + addScore
- , player = newPlayer
- , cloud = newCloud
- , seed = newSeed
- }
-
-playerStep : Float -> Vec2 -> Vec2 -> (KeyCode -> Bool) -> Player -> Float -> Player
-playerStep dt boardSize dir newKey player playerSize =
- 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 boardSize playerSize pos
- , speed = speed
- , config = newConfig
- }
-
-newKeyCode : Set KeyCode -> Set KeyCode -> KeyCode -> Bool
-newKeyCode lastKeyCodes newKeyCodes keyCode =
- let contains = not << List.isEmpty << List.filter (\kc -> kc == keyCode) << Set.toList
- in not (contains lastKeyCodes) && (contains newKeyCodes)