aboutsummaryrefslogtreecommitdiff
path: root/src/Step.elm
diff options
context:
space:
mode:
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
}