aboutsummaryrefslogtreecommitdiff
path: root/src/EnemyState.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2014-09-02 21:35:58 +0200
committerJoris Guyonvarch2014-09-02 21:35:58 +0200
commitc4ae3b0ee4bd338995cfecf34e0aeb49f05fa70e (patch)
tree71530e9e2cfcbe888cb086593ea1e4d0bcc269a6 /src/EnemyState.elm
Initial commit
Diffstat (limited to 'src/EnemyState.elm')
-rw-r--r--src/EnemyState.elm29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/EnemyState.elm b/src/EnemyState.elm
new file mode 100644
index 0000000..81766bf
--- /dev/null
+++ b/src/EnemyState.elm
@@ -0,0 +1,29 @@
+module EnemyState where
+
+import Enemy (..)
+import Player (..)
+import Geometry (distance)
+
+type EnemyState =
+ { enemies : [Enemy]
+ , spawn : Float
+ , lastSpawn : Float
+ }
+
+initEnemyState : EnemyState
+initEnemyState =
+ let spawn = 200
+ in { enemies = []
+ , spawn = spawn
+ , lastSpawn = -spawn
+ }
+
+playerEnemyCollision : Float -> Player -> Enemy -> Bool
+playerEnemyCollision time player enemy =
+ let enemyPos = enemyMove enemy time
+ in (distance enemyPos player.pos) < enemySize + playerSize
+
+playerEnemiesCollision : Float -> Player -> [Enemy] -> Bool
+playerEnemiesCollision time player enemies =
+ let collision = playerEnemyCollision time player
+ in length (filter collision enemies) > 0