aboutsummaryrefslogtreecommitdiff
path: root/src/Step.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2014-10-03 16:18:24 +0200
committerJoris Guyonvarch2014-10-03 16:18:24 +0200
commita1a3dbadffaaab290a6b6bb4b61df787d3b8ffdd (patch)
tree039b6b171d9dbdc2c10101a3a5664125a4eddcbf /src/Step.elm
parentb3975b15a16fb22739f2d633caaeed0cb1c39ab7 (diff)
Adding a target to catch
Diffstat (limited to 'src/Step.elm')
-rw-r--r--src/Step.elm32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/Step.elm b/src/Step.elm
index 7894e45..b88740a 100644
--- a/src/Step.elm
+++ b/src/Step.elm
@@ -11,20 +11,23 @@ import Physics (getNewPosAndSpeed, getMove)
import Board (boardSize, boardDiagonal)
import Geometry (..)
import RandomValues (RandomValues)
+import Target(..)
step : Input -> Game -> Game
-step {dir, delta, randomValues} {time, player, enemyState, bestTime} =
+step {dir, delta, randomValues} {time, player, target, enemyState, bestScore} =
if(playerEnemiesCollision time player enemyState.enemies) then
- let newBestTime = if(time > bestTime) then time else bestTime
- in initialGame player.pos newBestTime
+ let newBestScore = if(target.score > bestScore) then target.score else bestScore
+ in initialGame player.pos newBestScore
else
let newTime = time + delta
newPlayer = playerStep delta dir player
+ newTarget = targetStep player randomValues target
newEnemyState = enemyStep time randomValues enemyState
in { time = newTime
, player = newPlayer
+ , target = newTarget
, enemyState = newEnemyState
- , bestTime = bestTime
+ , bestScore = bestScore
}
playerStep : Float -> Vec2 -> Player -> Player
@@ -34,6 +37,15 @@ playerStep dt dir player =
, speed = speed
}
+targetStep : Player -> RandomValues -> Target -> Target
+targetStep player randomValues target =
+ if(targetCollision player target) then
+ { score = target.score + 1
+ , pos = randomBoardPosition (randomValues.targetX, randomValues.targetY) (0.8, 0.8)
+ }
+ else
+ target
+
enemyStep : Float -> RandomValues -> EnemyState -> EnemyState
enemyStep time randomValues {enemies, spawn, lastSpawn} =
let isPresent enemy = (distance (enemyMove enemy time) originVec) < enemyAwayDist
@@ -65,8 +77,12 @@ enemyInitPos randomValues =
enemyDestination : RandomValues -> Vec2
enemyDestination randomValues =
- let destWidth = boardSize.x
- destHeight = boardSize.y
- in { x = destWidth * randomValues.enemyX - destWidth / 2
- , y = destHeight * randomValues.enemyY - destHeight / 2
+ randomBoardPosition (randomValues.enemyX, randomValues.enemyY) (1, 1)
+
+randomBoardPosition : (Float, Float) -> (Float, Float) -> Vec2
+randomBoardPosition (randomX, randomY) (percentX, percentY) =
+ let width = boardSize.x * percentX
+ height = boardSize.y * percentY
+ in { x = width * randomX - width / 2
+ , y = height * randomY - height / 2
}