Commit 2258ef98 authored by Joris's avatar Joris

Make the player bigger with each point

parent 1cf6bc1a
module Main where module Main where
import Signal
import Random import Random
import Graphics.Element exposing (Element)
import Html exposing (Html) import Html exposing (Html)
import Model.Game exposing (Game, initialGame) import Model.Game exposing (Game, initialGame)
import Model.Vec2 exposing (originVec)
import Model.Config exposing (Config(White))
import Update.Update exposing (update) import Update.Update exposing (update)
......
...@@ -30,12 +30,12 @@ initCloud = ...@@ -30,12 +30,12 @@ initCloud =
, lastSpawn = -spawn , lastSpawn = -spawn
} }
playerPointsCollision : Float -> Player -> List Point -> Bool playerPointsCollision : Float -> Player -> Float -> List Point -> Bool
playerPointsCollision time player points = playerPointsCollision elapsedTime player playerSize points =
let collision = playerPointCollision time player let collision = playerPointCollision elapsedTime player playerSize
in List.length (List.filter collision points) > 0 in List.length (List.filter collision points) > 0
playerPointCollision : Float -> Player -> Point -> Bool playerPointCollision : Float -> Player -> Float -> Point -> Bool
playerPointCollision time player point = playerPointCollision elapsedTime player playerSize point =
let pointPos = pointMove point time let pointPos = pointMove point elapsedTime
in (distance pointPos player.pos) < pointSize + playerSize in (distance pointPos player.pos) < pointSize + playerSize
...@@ -17,7 +17,7 @@ import Model.Round exposing (Round) ...@@ -17,7 +17,7 @@ import Model.Round exposing (Round)
import Model.Board exposing (initBoardSize) import Model.Board exposing (initBoardSize)
type alias Game = type alias Game =
{ time : Float { elapsedTime : Float
, boardSize : Vec2 , boardSize : Vec2
, keysDown : Set KeyCode , keysDown : Set KeyCode
, currentScore : Int , currentScore : Int
...@@ -29,7 +29,7 @@ type alias Game = ...@@ -29,7 +29,7 @@ type alias Game =
initialGame : Seed -> Game initialGame : Seed -> Game
initialGame seed = initialGame seed =
{ time = 0 { elapsedTime = 0
, boardSize = initBoardSize , boardSize = initBoardSize
, keysDown = Set.empty , keysDown = Set.empty
, currentScore = 0 , currentScore = 0
......
module Model.Level module Model.Level
( currentLevel ( currentLevel
, currentLevelScore
, currentLevelNumber , currentLevelNumber
, progressiveColor , progressiveColor
, levelScoreDuration
) where ) where
import Time exposing (Time) import Time exposing (Time)
...@@ -14,13 +16,17 @@ import Model.Point exposing (pointSpeed) ...@@ -14,13 +16,17 @@ import Model.Point exposing (pointSpeed)
import Utils.Physics exposing (getMove, getWaveMove) import Utils.Physics exposing (getMove, getWaveMove)
levelScoreDuration : Int levelScoreDuration : Int
levelScoreDuration = 15 levelScoreDuration = 20
type alias Level = type alias Level =
{ color : Color { color : Color
, move : Vec2 -> Vec2 -> Time -> Vec2 , move : Vec2 -> Vec2 -> Time -> Vec2
} }
currentLevelScore : Int -> Int
currentLevelScore currentScore =
currentScore - (currentLevelNumber currentScore - 1) * levelScoreDuration
currentLevelNumber : Int -> Int currentLevelNumber : Int -> Int
currentLevelNumber currentScore = currentLevelNumber currentScore =
min min
......
module Model.Player module Model.Player
( Player ( Player
, initPlayer , initPlayer
, playerSize , getPlayerSize
, playerSpeed , playerSpeed
) where ) where
import Model.Vec2 exposing (..) import Model.Vec2 exposing (..)
import Model.Config exposing (..) import Model.Config exposing (..)
import Model.Level as Level
type alias Player = type alias Player =
{ pos : Vec2 { pos : Vec2
...@@ -21,8 +22,16 @@ initPlayer = ...@@ -21,8 +22,16 @@ initPlayer =
, config = White , config = White
} }
playerSize : Float getPlayerSize : Int -> Float
playerSize = 15 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 : Float -> Float
playerSpeed dt = dt / 200 playerSpeed dt = dt / 200
...@@ -15,16 +15,16 @@ import Model.Level exposing (..) ...@@ -15,16 +15,16 @@ import Model.Level exposing (..)
import Utils.Geometry exposing (..) import Utils.Geometry exposing (..)
cloudUpdate : Float -> Vec2 -> Seed -> Player -> Cloud -> Int -> (Cloud, Int, Seed) cloudUpdate : Float -> Vec2 -> Seed -> Player -> Float -> Cloud -> Int -> (Cloud, Int, Seed)
cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = cloudUpdate elapsedTime boardSize seed player playerSize {points, spawn, lastSpawn} currentScore =
let pointsToCatch = presentPoints time boardSize (points player.config) let pointsToCatch = presentPoints elapsedTime boardSize (points player.config)
presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch presentAndNotCaughtPoints = List.filter (not << (playerPointCollision elapsedTime player playerSize)) pointsToCatch
addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints) 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') = (newCloud, seed') =
if time > lastSpawn + spawn then if elapsedTime > lastSpawn + spawn then
let (newPoint1, seed') = getNewPoint time boardSize seed currentScore let (newPoint1, seed') = getNewPoint elapsedTime boardSize seed currentScore
(newPoint2, seed'') = getNewPoint time boardSize seed' currentScore (newPoint2, seed'') = getNewPoint elapsedTime boardSize seed' currentScore
in ( { points = \config -> in ( { points = \config ->
if(config == player.config) if(config == player.config)
then then
...@@ -32,7 +32,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = ...@@ -32,7 +32,7 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore =
else else
newPoint2 :: presentOtherPoints newPoint2 :: presentOtherPoints
, spawn = spawn - sqrt(spawn) / 50 , spawn = spawn - sqrt(spawn) / 50
, lastSpawn = time , lastSpawn = elapsedTime
} }
, seed'' , seed''
) )
...@@ -50,19 +50,19 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore = ...@@ -50,19 +50,19 @@ cloudUpdate time boardSize seed player {points, spawn, lastSpawn} currentScore =
in (newCloud, addScore, seed') in (newCloud, addScore, seed')
presentPoints : Float -> Vec2 -> List Point -> List Point presentPoints : Float -> Vec2 -> List Point -> List Point
presentPoints time boardSize points = presentPoints elapsedTime boardSize points =
let isPresent point = (distance (pointMove point time) originVec) < (pointAwayDist boardSize) let isPresent point = (distance (pointMove point elapsedTime) originVec) < (pointAwayDist boardSize)
in List.filter isPresent points in List.filter isPresent points
getNewPoint : Float -> Vec2 -> Seed -> Int -> (Point, Seed) getNewPoint : Float -> Vec2 -> Seed -> Int -> (Point, Seed)
getNewPoint time boardSize seed currentScore = getNewPoint elapsedTime boardSize seed currentScore =
let (initPos, seed') = pointInitPos boardSize seed let (initPos, seed') = pointInitPos boardSize seed
(initDest, seed'') = pointDestination boardSize seed' (initDest, seed'') = pointDestination boardSize seed'
in ( { initTime = time in ( { initTime = elapsedTime
, initPos = initPos , initPos = initPos
, initDest = initDest , initDest = initDest
, move = \initTime initPos initDest time -> , move = \initTime initPos initDest elapsedTime ->
let delta = time - initTime let delta = elapsedTime - initTime
move = (currentLevel currentScore).move initPos initDest delta move = (currentLevel currentScore).move initPos initDest delta
in initPos `add` move in initPos `add` move
} }
......
...@@ -25,20 +25,20 @@ import Input exposing (Input) ...@@ -25,20 +25,20 @@ import Input exposing (Input)
update : Input -> Game -> Game update : Input -> Game -> Game
update input game = update input game =
let hostilePoints = game.cloud.points (otherConfig game.player.config) 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 then
{ game { game
| time = 0 | elapsedTime = 0
, currentScore = 0 , currentScore = 0
, cloud = initCloud , cloud = initCloud
, rounds = (Round game.time game.currentScore) :: game.rounds , rounds = (Round game.elapsedTime game.currentScore) :: game.rounds
} }
else else
let 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 (getPlayerSize game.currentScore)
(newCloud, addScore, newSeed) = cloudUpdate game.time game.boardSize game.seed newPlayer game.cloud game.currentScore (newCloud, addScore, newSeed) = cloudUpdate game.elapsedTime game.boardSize game.seed newPlayer (getPlayerSize game.currentScore) game.cloud game.currentScore
in in
{ game { game
| time = game.time + input.delta | elapsedTime = game.elapsedTime + input.delta
, keysDown = input.inputKeysDown , keysDown = input.inputKeysDown
, currentScore = game.currentScore + addScore , currentScore = game.currentScore + addScore
, player = newPlayer , player = newPlayer
...@@ -46,8 +46,8 @@ update input game = ...@@ -46,8 +46,8 @@ update input game =
, seed = newSeed , seed = newSeed
} }
playerStep : Float -> Vec2 -> Vec2 -> (KeyCode -> Bool) -> Player -> Player playerStep : Float -> Vec2 -> Vec2 -> (KeyCode -> Bool) -> Player -> Float -> Player
playerStep dt boardSize dir newKey player = playerStep dt boardSize dir newKey player playerSize =
let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed) let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed)
newConfig = if (newKey 69) then otherConfig player.config else player.config newConfig = if (newKey 69) then otherConfig player.config else player.config
in { pos = inBoard boardSize playerSize pos in { pos = inBoard boardSize playerSize pos
......
...@@ -22,7 +22,7 @@ import View.Round exposing (roundView) ...@@ -22,7 +22,7 @@ import View.Round exposing (roundView)
renderGame : Game -> Html renderGame : Game -> Html
renderGame game = 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 in svg
[ width "100%" [ width "100%"
, height "100%" , height "100%"
...@@ -30,10 +30,10 @@ renderGame game = ...@@ -30,10 +30,10 @@ renderGame game =
, viewBox ("0 0 " ++ (toString game.boardSize.x) ++ " " ++ (toString (game.boardSize.y + headerHeight))) , viewBox ("0 0 " ++ (toString game.boardSize.x) ++ " " ++ (toString (game.boardSize.y + headerHeight)))
] ]
[ renderBoard game.currentScore [ renderBoard game.currentScore
, renderPlayer game.boardSize game.player , renderPlayer game.boardSize game.player (getPlayerSize game.currentScore)
, g [] (renderPoints White) , g [] (renderPoints White)
, g [] (renderPoints Black) , g [] (renderPoints Black)
, renderScore game.boardSize game.time game.rounds game.currentScore , renderScore game.boardSize game.elapsedTime game.rounds game.currentScore
, hideNewPoints game.boardSize , hideNewPoints game.boardSize
, renderHeader game , renderHeader game
] ]
...@@ -107,8 +107,8 @@ renderBoard currentScore = ...@@ -107,8 +107,8 @@ renderBoard currentScore =
] ]
[] []
renderPlayer : Vec2 -> Player -> Svg renderPlayer : Vec2 -> Player -> Float -> Svg
renderPlayer boardSize player = renderPlayer boardSize player playerSize =
renderCircle boardSize player.pos playerSize (playerColor player.config) renderCircle boardSize player.pos playerSize (playerColor player.config)
playerColor : Config -> String playerColor : Config -> String
...@@ -118,8 +118,8 @@ playerColor config = ...@@ -118,8 +118,8 @@ playerColor config =
Black -> "#0E1121" Black -> "#0E1121"
renderPoint : Vec2 -> Float -> Config -> Point -> Svg renderPoint : Vec2 -> Float -> Config -> Point -> Svg
renderPoint boardSize time config point = renderPoint boardSize elapsedTime config point =
let pos = pointMove point time let pos = pointMove point elapsedTime
in renderCircle boardSize pos pointSize (playerColor config) in renderCircle boardSize pos pointSize (playerColor config)
pointColor : Config -> String pointColor : Config -> String
...@@ -139,13 +139,13 @@ renderCircle boardSize pos size color = ...@@ -139,13 +139,13 @@ renderCircle boardSize pos size color =
[] []
renderScore : Vec2 -> Time -> List Round -> Int -> Svg renderScore : Vec2 -> Time -> List Round -> Int -> Svg
renderScore boardSize currentRoundTime rounds score = renderScore boardSize elapsedTime rounds score =
let scorePos = let scorePos =
{ x = 0.0 { x = 0.0
, y = boardSize.y / 2 - 35 , y = boardSize.y / 2 - 35
} }
scoreText = "L" ++ (toString << currentLevelNumber <| score) ++ " - " ++ (toString score) scoreText = "L" ++ (toString << currentLevelNumber <| score) ++ " - " ++ (toString score)
in if currentRoundTime < 5000 in if elapsedTime < 5000
then then
case List.head rounds of case List.head rounds of
Just round -> Just round ->
......
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