1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
module Step where
import Vec2 (..)
import Game (..)
import Player (..)
import EnemyState (..)
import Player (playerSpeed)
import Enemy (enemySpeed, enemyMove, enemyAwayDist)
import Input (Input)
import Physics (getNewPosAndSpeed, getMove)
import Board (boardSize, boardDiagonal)
import Geometry (..)
import RandomValues (RandomValues)
step : Input -> Game -> Game
step {dir, delta, randomValues} {time, player, enemyState, bestTime} =
if(playerEnemiesCollision time player enemyState.enemies) then
let newBestTime = if(time > bestTime) then time else bestTime
in initialGame player.pos newBestTime
else
let newTime = time + delta
newPlayer = playerStep delta dir player
newEnemyState = enemyStep time randomValues enemyState
in { time = newTime
, player = newPlayer
, enemyState = newEnemyState
, bestTime = bestTime
}
playerStep : Float -> Vec2 -> Player -> Player
playerStep dt dir player =
let (pos, speed) = getNewPosAndSpeed dt dir playerSpeed (player.pos, player.speed)
in { pos = inBoard playerSize pos
, speed = speed
}
enemyStep : Float -> RandomValues -> EnemyState -> EnemyState
enemyStep time randomValues {enemies, spawn, lastSpawn} =
let isPresent enemy = (distance (enemyMove enemy time) originVec) < enemyAwayDist
presentEnemies = filter isPresent enemies
in if time > lastSpawn + spawn then
let newEnemy =
{ initTime = time
, initPos = enemyInitPos randomValues
, initDest = enemyDestination randomValues
, move initTime initPos initDest time =
let delta = time - initTime
move = getMove (enemySpeed delta) (initDest `sub` initPos)
in initPos `add` move
}
in { enemies = newEnemy :: presentEnemies
, spawn = spawn - sqrt(spawn) / 50
, lastSpawn = time
}
else { enemies = presentEnemies
, spawn = spawn
, lastSpawn = lastSpawn
}
enemyInitPos : RandomValues -> Vec2
enemyInitPos randomValues =
let angle = randomValues.enemyAngle * (degrees 360)
dist = boardDiagonal * 3 / 5
in polarToCartesian angle dist
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
}
|