diff options
author | Joris | 2015-12-30 13:35:01 +0100 |
---|---|---|
committer | Joris | 2015-12-30 13:35:01 +0100 |
commit | 2258ef984fefde41711d4c883baf582b7e581155 (patch) | |
tree | a15cdae0c8a77a628ee49959037a1000687f3a2c /src | |
parent | 1cf6bc1ad9209e4f3f2fcbc129f2577e74e94c99 (diff) |
Make the player bigger with each point
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.elm | 4 | ||||
-rw-r--r-- | src/Model/Cloud.elm | 12 | ||||
-rw-r--r-- | src/Model/Game.elm | 4 | ||||
-rw-r--r-- | src/Model/Level.elm | 8 | ||||
-rw-r--r-- | src/Model/Player.elm | 15 | ||||
-rw-r--r-- | src/Update/CloudUpdate.elm | 30 | ||||
-rw-r--r-- | src/Update/Update.elm | 16 | ||||
-rw-r--r-- | src/View/Game.elm | 18 |
8 files changed, 59 insertions, 48 deletions
diff --git a/src/Main.elm b/src/Main.elm index f141fcc..d257b81 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -1,13 +1,9 @@ module Main where -import Signal import Random -import Graphics.Element exposing (Element) import Html exposing (Html) import Model.Game exposing (Game, initialGame) -import Model.Vec2 exposing (originVec) -import Model.Config exposing (Config(White)) import Update.Update exposing (update) diff --git a/src/Model/Cloud.elm b/src/Model/Cloud.elm index 603477b..26b4104 100644 --- a/src/Model/Cloud.elm +++ b/src/Model/Cloud.elm @@ -30,12 +30,12 @@ initCloud = , lastSpawn = -spawn } -playerPointsCollision : Float -> Player -> List Point -> Bool -playerPointsCollision time player points = - let collision = playerPointCollision time player +playerPointsCollision : Float -> Player -> Float -> List Point -> Bool +playerPointsCollision elapsedTime player playerSize points = + let collision = playerPointCollision elapsedTime player playerSize in List.length (List.filter collision points) > 0 -playerPointCollision : Float -> Player -> Point -> Bool -playerPointCollision time player point = - let pointPos = pointMove point time +playerPointCollision : Float -> Player -> Float -> Point -> Bool +playerPointCollision elapsedTime player playerSize point = + let pointPos = pointMove point elapsedTime in (distance pointPos player.pos) < pointSize + playerSize diff --git a/src/Model/Game.elm b/src/Model/Game.elm index 24fd400..97fbc4c 100644 --- a/src/Model/Game.elm +++ b/src/Model/Game.elm @@ -17,7 +17,7 @@ import Model.Round exposing (Round) import Model.Board exposing (initBoardSize) type alias Game = - { time : Float + { elapsedTime : Float , boardSize : Vec2 , keysDown : Set KeyCode , currentScore : Int @@ -29,7 +29,7 @@ type alias Game = initialGame : Seed -> Game initialGame seed = - { time = 0 + { elapsedTime = 0 , boardSize = initBoardSize , keysDown = Set.empty , currentScore = 0 diff --git a/src/Model/Level.elm b/src/Model/Level.elm index 3fc4258..d058d53 100644 --- a/src/Model/Level.elm +++ b/src/Model/Level.elm @@ -1,7 +1,9 @@ module Model.Level ( currentLevel + , currentLevelScore , currentLevelNumber , progressiveColor + , levelScoreDuration ) where import Time exposing (Time) @@ -14,13 +16,17 @@ import Model.Point exposing (pointSpeed) import Utils.Physics exposing (getMove, getWaveMove) levelScoreDuration : Int -levelScoreDuration = 15 +levelScoreDuration = 20 type alias Level = { color : Color , move : Vec2 -> Vec2 -> Time -> Vec2 } +currentLevelScore : Int -> Int +currentLevelScore currentScore = + currentScore - (currentLevelNumber currentScore - 1) * levelScoreDuration + currentLevelNumber : Int -> Int currentLevelNumber currentScore = min diff --git a/src/Model/Player.elm b/src/Model/Player.elm index 2085aac..6858893 100644 --- a/src/Model/Player.elm +++ b/src/Model/Player.elm @@ -1,12 +1,13 @@ module Model.Player ( Player , initPlayer - , playerSize + , getPlayerSize , playerSpeed ) where import Model.Vec2 exposing (..) import Model.Config exposing (..) +import Model.Level as Level type alias Player = { pos : Vec2 @@ -21,8 +22,16 @@ initPlayer = , config = White } -playerSize : Float -playerSize = 15 +getPlayerSize : Int -> Float +getPlayerSize score = + (levelCurve Level.levelScoreDuration 15 (Level.currentLevelScore score)) + 15 + +levelCurve : Int -> Int -> Int -> Float +levelCurve maxAbs maxOrd x = + let linear = toFloat x * toFloat maxOrd / toFloat maxAbs + n = 4 + exp = toFloat x^n * toFloat maxOrd / toFloat maxAbs^n + in linear - exp playerSpeed : Float -> Float playerSpeed dt = dt / 200 diff --git a/src/Update/CloudUpdate.elm b/src/Update/CloudUpdate.elm index 1fbb9d3..359f02c 100644 --- a/src/Update/CloudUpdate.elm +++ b/src/Update/CloudUpdate.elm @@ -15,16 +15,16 @@ import Model.Level exposing (..) import Utils.Geometry exposing (..) -cloudUpdate : Float -> Vec2 -> Seed -> Player -> Cloud -> Int -> (Cloud, Int, Seed) -cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = - let pointsToCatch = presentPoints time boardSize (points player.config) - presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch +cloudUpdate : Float -> Vec2 -> Seed -> Player -> Float -> Cloud -> Int -> (Cloud, Int, Seed) +cloudUpdate elapsedTime boardSize seed player playerSize {points, spawn, lastSpawn} currentScore = + let pointsToCatch = presentPoints elapsedTime boardSize (points player.config) + presentAndNotCaughtPoints = List.filter (not << (playerPointCollision elapsedTime player playerSize)) pointsToCatch addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints) - presentOtherPoints = presentPoints time boardSize (points (otherConfig player.config)) + presentOtherPoints = presentPoints elapsedTime boardSize (points (otherConfig player.config)) (newCloud, seed') = - if time > lastSpawn + spawn then - let (newPoint1, seed') = getNewPoint time boardSize seed currentScore - (newPoint2, seed'') = getNewPoint time boardSize seed' currentScore + if elapsedTime > lastSpawn + spawn then + let (newPoint1, seed') = getNewPoint elapsedTime boardSize seed currentScore + (newPoint2, seed'') = getNewPoint elapsedTime boardSize seed' currentScore in ( { points = \config -> if(config == player.config) then @@ -32,7 +32,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = else newPoint2 :: presentOtherPoints , spawn = spawn - sqrt(spawn) / 50 - , lastSpawn = time + , lastSpawn = elapsedTime } , seed'' ) @@ -50,19 +50,19 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = in (newCloud, addScore, seed') presentPoints : Float -> Vec2 -> List Point -> List Point -presentPoints time boardSize points = - let isPresent point = (distance (pointMove point time) originVec) < (pointAwayDist boardSize) +presentPoints elapsedTime boardSize points = + let isPresent point = (distance (pointMove point elapsedTime) originVec) < (pointAwayDist boardSize) in List.filter isPresent points getNewPoint : Float -> Vec2 -> Seed -> Int -> (Point, Seed) -getNewPoint time boardSize seed currentScore = +getNewPoint elapsedTime boardSize seed currentScore = let (initPos, seed') = pointInitPos boardSize seed (initDest, seed'') = pointDestination boardSize seed' - in ( { initTime = time + in ( { initTime = elapsedTime , initPos = initPos , initDest = initDest - , move = \initTime initPos initDest time -> - let delta = time - initTime + , move = \initTime initPos initDest elapsedTime -> + let delta = elapsedTime - initTime move = (currentLevel currentScore).move initPos initDest delta in initPos `add` move } diff --git a/src/Update/Update.elm b/src/Update/Update.elm index 9dc737f..2514aac 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -25,20 +25,20 @@ import Input exposing (Input) update : Input -> Game -> Game update input game = let hostilePoints = game.cloud.points (otherConfig game.player.config) - in if(playerPointsCollision game.time game.player hostilePoints) + in if(playerPointsCollision game.elapsedTime game.player (getPlayerSize game.currentScore) hostilePoints) then { game - | time = 0 + | elapsedTime = 0 , currentScore = 0 , cloud = initCloud - , rounds = (Round game.time game.currentScore) :: game.rounds + , 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 - (newCloud, addScore, newSeed) = cloudUpdate game.time game.boardSize game.seed newPlayer game.cloud game.currentScore + 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 - | time = game.time + input.delta + | elapsedTime = game.elapsedTime + input.delta , keysDown = input.inputKeysDown , currentScore = game.currentScore + addScore , player = newPlayer @@ -46,8 +46,8 @@ update input game = , seed = newSeed } -playerStep : Float -> Vec2 -> Vec2 -> (KeyCode -> Bool) -> Player -> Player -playerStep dt boardSize dir newKey player = +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 diff --git a/src/View/Game.elm b/src/View/Game.elm index 2651f8d..2bef2ae 100644 --- a/src/View/Game.elm +++ b/src/View/Game.elm @@ -22,7 +22,7 @@ import View.Round exposing (roundView) renderGame : Game -> Html renderGame game = - let renderPoints config = List.map (renderPoint game.boardSize game.time config) (game.cloud.points config) + let renderPoints config = List.map (renderPoint game.boardSize game.elapsedTime config) (game.cloud.points config) in svg [ width "100%" , height "100%" @@ -30,10 +30,10 @@ renderGame game = , viewBox ("0 0 " ++ (toString game.boardSize.x) ++ " " ++ (toString (game.boardSize.y + headerHeight))) ] [ renderBoard game.currentScore - , renderPlayer game.boardSize game.player + , renderPlayer game.boardSize game.player (getPlayerSize game.currentScore) , g [] (renderPoints White) , g [] (renderPoints Black) - , renderScore game.boardSize game.time game.rounds game.currentScore + , renderScore game.boardSize game.elapsedTime game.rounds game.currentScore , hideNewPoints game.boardSize , renderHeader game ] @@ -107,8 +107,8 @@ renderBoard currentScore = ] [] -renderPlayer : Vec2 -> Player -> Svg -renderPlayer boardSize player = +renderPlayer : Vec2 -> Player -> Float -> Svg +renderPlayer boardSize player playerSize = renderCircle boardSize player.pos playerSize (playerColor player.config) playerColor : Config -> String @@ -118,8 +118,8 @@ playerColor config = Black -> "#0E1121" renderPoint : Vec2 -> Float -> Config -> Point -> Svg -renderPoint boardSize time config point = - let pos = pointMove point time +renderPoint boardSize elapsedTime config point = + let pos = pointMove point elapsedTime in renderCircle boardSize pos pointSize (playerColor config) pointColor : Config -> String @@ -139,13 +139,13 @@ renderCircle boardSize pos size color = [] renderScore : Vec2 -> Time -> List Round -> Int -> Svg -renderScore boardSize currentRoundTime rounds score = +renderScore boardSize elapsedTime rounds score = let scorePos = { x = 0.0 , y = boardSize.y / 2 - 35 } scoreText = "L" ++ (toString << currentLevelNumber <| score) ++ " - " ++ (toString score) - in if currentRoundTime < 5000 + in if elapsedTime < 5000 then case List.head rounds of Just round -> |