done getting player's projectiles to collide with enemies successfully, and tested (although the code of the enemy reacting to the player is not the best)
This commit is contained in:
@@ -181,9 +181,9 @@ struct
|
|||||||
val platforms = Vector.fromList [plat1]
|
val platforms = Vector.fromList [plat1]
|
||||||
val platformTree = Platform.generateTree platforms
|
val platformTree = Platform.generateTree platforms
|
||||||
|
|
||||||
val enemy1 = {id = 1, x = 300, y = 945, health = 2}
|
val enemy1 = {id = 1, x = 300, y = 945, health = 5}
|
||||||
val enemy2 = {id = 2, x = 555, y = 945, health = 2}
|
val enemy2 = {id = 2, x = 555, y = 945, health = 5}
|
||||||
val enemy3 = {id = 3, x = 979, y = 945, health = 2}
|
val enemy3 = {id = 3, x = 979, y = 945, health = 5}
|
||||||
val enemies = Vector.fromList [enemy1, enemy2, enemy3]
|
val enemies = Vector.fromList [enemy1, enemy2, enemy3]
|
||||||
val enemyTree = Enemy.generateTree enemies
|
val enemyTree = Enemy.generateTree enemies
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -7,15 +7,11 @@ struct
|
|||||||
|
|
||||||
val player = Player.runPhysicsAndInput (game, input)
|
val player = Player.runPhysicsAndInput (game, input)
|
||||||
|
|
||||||
(* check and react to enemy collisions with player projectile *)
|
|
||||||
val enemies =
|
|
||||||
ProjectileEnemy.checkCollisions
|
|
||||||
(#projectiles player, enemies, enemyTree)
|
|
||||||
val enemyTree = Enemy.generateTree enemies
|
|
||||||
|
|
||||||
(* check player-enemy collisions and react *)
|
(* check player-enemy collisions and react *)
|
||||||
val (player, enemies, enemyTree) =
|
val (player, enemies, enemyTree) =
|
||||||
PlayerEnemy.checkCollisions (player, enemies, enemyTree)
|
PlayerEnemy.checkCollisions
|
||||||
|
(player, enemies, enemyTree, #projectiles player)
|
||||||
|
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
, walls = walls
|
, walls = walls
|
||||||
|
|||||||
@@ -57,24 +57,71 @@ struct
|
|||||||
|
|
||||||
fun exists (id, collisions) = helpExists (0, id, collisions)
|
fun exists (id, collisions) = helpExists (0, id, collisions)
|
||||||
|
|
||||||
(* removes enemies from `enemies` vector when that enemy is in collisions *)
|
(* removes enemies from `enemies` vector when player is attacking that enemy
|
||||||
fun filterEnemyCollisions (pos, collisions, enemies: enemy vector, acc) =
|
* and also filter enemy (or change enemyh health)
|
||||||
|
* if enemy has collided with projectile *)
|
||||||
|
fun filterEnemyAttacked
|
||||||
|
(pos, collisions, enemies: enemy vector, projectileTree, acc) =
|
||||||
if pos < 0 then
|
if pos < 0 then
|
||||||
Vector.fromList acc
|
Vector.fromList acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val enemy = Vector.sub (enemies, pos)
|
val enemy = Vector.sub (enemies, pos)
|
||||||
val acc =
|
val acc =
|
||||||
if exists (#id enemy, collisions) then (* filter out *) acc
|
if exists (#id enemy, collisions) then
|
||||||
else (* don't filter out *) enemy :: acc
|
(* filter out *)
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {x, y, health, id} = enemy
|
||||||
|
val eSize = Enemy.size
|
||||||
|
val hasCollision = QuadTree.hasCollisionAt
|
||||||
|
(x, y, eSize, eSize, 0, 0, 1920, 1080, ~1, projectileTree)
|
||||||
|
in
|
||||||
|
if hasCollision then
|
||||||
|
if health = 1 then
|
||||||
|
(* filter out if decrementing health by one = 0 *)
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
{health = health - 1, x = x, y = y, id = id} :: acc
|
||||||
|
else
|
||||||
|
enemy :: acc
|
||||||
|
end
|
||||||
in
|
in
|
||||||
filterEnemyCollisions (pos - 1, collisions, enemies, acc)
|
filterEnemyAttacked
|
||||||
|
(pos - 1, collisions, enemies, projectileTree, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun checkCollisions (player, enemies, enemyTree) =
|
(* filter enemy projectiles when player is not attacking *)
|
||||||
|
fun filterEnemyProjectiles (pos, enemies, projectileTree, acc) =
|
||||||
|
if pos < 0 then
|
||||||
|
Vector.fromList acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val enemy = Vector.sub (enemies, pos)
|
||||||
|
val {x, y, health, id} = enemy
|
||||||
|
val eSize = Enemy.size
|
||||||
|
val hasCollision = QuadTree.hasCollisionAt
|
||||||
|
(x, y, eSize, eSize, 0, 0, 1920, 1080, ~1, projectileTree)
|
||||||
|
|
||||||
|
val acc =
|
||||||
|
if hasCollision then
|
||||||
|
if health = 1 then
|
||||||
|
(* filter out if decrementing health by one = 0 *)
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
{health = health - 1, x = x, y = y, id = id} :: acc
|
||||||
|
else
|
||||||
|
enemy :: acc
|
||||||
|
in
|
||||||
|
filterEnemyProjectiles (pos - 1, enemies, projectileTree, acc)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun checkCollisions (player, enemies, enemyTree, projectiles) =
|
||||||
let
|
let
|
||||||
val {x, y, mainAttack, attacked, ...} = player
|
val {x, y, mainAttack, attacked, ...} = player
|
||||||
val size = Player.size
|
val size = Player.size
|
||||||
|
val projectileTree = Projectile.generateTree projectiles
|
||||||
in
|
in
|
||||||
case mainAttack of
|
case mainAttack of
|
||||||
MAIN_ATTACKING =>
|
MAIN_ATTACKING =>
|
||||||
@@ -90,8 +137,13 @@ struct
|
|||||||
|
|
||||||
(* filter enemies based on collisions *)
|
(* filter enemies based on collisions *)
|
||||||
val enemyCollisions = Vector.fromList enemyCollisions
|
val enemyCollisions = Vector.fromList enemyCollisions
|
||||||
val enemies = filterEnemyCollisions
|
val enemies = filterEnemyAttacked
|
||||||
(Vector.length enemies - 1, enemyCollisions, enemies, [])
|
( Vector.length enemies - 1
|
||||||
|
, enemyCollisions
|
||||||
|
, enemies
|
||||||
|
, projectileTree
|
||||||
|
, []
|
||||||
|
)
|
||||||
val enemyTree = Enemy.generateTree enemies
|
val enemyTree = Enemy.generateTree enemies
|
||||||
|
|
||||||
(* add collided enemies to player record,
|
(* add collided enemies to player record,
|
||||||
@@ -114,6 +166,9 @@ struct
|
|||||||
val patches =
|
val patches =
|
||||||
checkEnemies (player, enemies, enemyCollisions, [])
|
checkEnemies (player, enemies, enemyCollisions, [])
|
||||||
val player = Player.withPatches (player, patches)
|
val player = Player.withPatches (player, patches)
|
||||||
|
|
||||||
|
val enemies = filterEnemyProjectiles
|
||||||
|
(Vector.length enemies - 1, enemies, projectileTree, [])
|
||||||
in
|
in
|
||||||
(player, enemies, enemyTree)
|
(player, enemies, enemyTree)
|
||||||
end
|
end
|
||||||
@@ -127,6 +182,9 @@ struct
|
|||||||
val patches =
|
val patches =
|
||||||
checkEnemies (player, enemies, enemyCollisions, lst)
|
checkEnemies (player, enemies, enemyCollisions, lst)
|
||||||
val player = Player.withPatches (player, patches)
|
val player = Player.withPatches (player, patches)
|
||||||
|
|
||||||
|
val enemies = filterEnemyProjectiles
|
||||||
|
(Vector.length enemies - 1, enemies, projectileTree, [])
|
||||||
in
|
in
|
||||||
(player, enemies, enemyTree)
|
(player, enemies, enemyTree)
|
||||||
end
|
end
|
||||||
@@ -139,6 +197,9 @@ struct
|
|||||||
val attacked = ATTACKED amt
|
val attacked = ATTACKED amt
|
||||||
val player = Player.withPatches
|
val player = Player.withPatches
|
||||||
(player, [W_ATTACKED attacked])
|
(player, [W_ATTACKED attacked])
|
||||||
|
|
||||||
|
val enemies = filterEnemyProjectiles
|
||||||
|
(Vector.length enemies - 1, enemies, projectileTree, [])
|
||||||
in
|
in
|
||||||
(player, enemies, enemyTree)
|
(player, enemies, enemyTree)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
structure ProjectileEnemy =
|
|
||||||
struct
|
|
||||||
open GameType
|
|
||||||
|
|
||||||
fun helpCheckColisions (pos, projectileTree, enemies, acc) =
|
|
||||||
if pos < 0 then
|
|
||||||
Vector.fromList acc
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val enemy = Vector.sub (enemies, pos)
|
|
||||||
|
|
||||||
val {id, health, x, y} = enemy
|
|
||||||
val size = Enemy.size
|
|
||||||
|
|
||||||
val collisions = QuadTree.helpGetCollisions
|
|
||||||
(x, y, size, size, 0, 0, 1920, 1080, 0, [], projectileTree)
|
|
||||||
|
|
||||||
(* react to collisions here, possibly removing enemy from acc *)
|
|
||||||
val acc =
|
|
||||||
case collisions of
|
|
||||||
_ :: _ =>
|
|
||||||
if health = 1 then
|
|
||||||
(* filter enemy out if decrementing their health by 1
|
|
||||||
* leads to a health of 0 *)
|
|
||||||
acc
|
|
||||||
else
|
|
||||||
let
|
|
||||||
(* decrement health by 1 and add to acc *)
|
|
||||||
val enemy = {id = id, health = health - 1, x = x, y = y}
|
|
||||||
in
|
|
||||||
enemy :: acc
|
|
||||||
end
|
|
||||||
| [] => enemy :: acc
|
|
||||||
in
|
|
||||||
helpCheckColisions (pos - 1, projectileTree, enemies, acc)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun helpGenerateTree (pos, projectiles, acc) =
|
|
||||||
if pos = Vector.length projectiles then
|
|
||||||
acc
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val size = Player.defeatedSizeInt
|
|
||||||
|
|
||||||
val {x, y, facing = _} = Vector.sub (projectiles, pos)
|
|
||||||
val acc = QuadTree.insert (x, y, size, size, 0, 0, 1920, 1080, pos, acc)
|
|
||||||
in
|
|
||||||
helpGenerateTree (pos + 1, projectiles, acc)
|
|
||||||
end
|
|
||||||
|
|
||||||
fun generateTree projectiles =
|
|
||||||
helpGenerateTree (0, projectiles, QuadTree.empty)
|
|
||||||
|
|
||||||
fun checkCollisions (projectiles, enemies, enemyTree) =
|
|
||||||
let
|
|
||||||
val projectileTree = generateTree projectiles
|
|
||||||
in
|
|
||||||
helpCheckColisions
|
|
||||||
(Vector.length enemies - 1, projectileTree, enemies, [])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
18
fcore/projectile.sml
Normal file
18
fcore/projectile.sml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
structure Projectile =
|
||||||
|
struct
|
||||||
|
fun helpGenerateTree (pos, projectiles, acc) =
|
||||||
|
if pos = Vector.length projectiles then
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val size = Player.defeatedSizeInt
|
||||||
|
|
||||||
|
val {x, y, facing = _} = Vector.sub (projectiles, pos)
|
||||||
|
val acc = QuadTree.insert (x, y, size, size, 0, 0, 1920, 1080, pos, acc)
|
||||||
|
in
|
||||||
|
helpGenerateTree (pos + 1, projectiles, acc)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun generateTree projectiles =
|
||||||
|
helpGenerateTree (0, projectiles, QuadTree.empty)
|
||||||
|
end
|
||||||
@@ -30,6 +30,10 @@ sig
|
|||||||
|
|
||||||
val getCollisionsBelow: int * int * int * int * int * int * int * int * int * t
|
val getCollisionsBelow: int * int * int * int * int * int * int * int * int * t
|
||||||
-> int list
|
-> int list
|
||||||
|
|
||||||
|
val hasCollisionAt: int * int * int * int *
|
||||||
|
int * int * int * int *
|
||||||
|
int * t -> bool
|
||||||
end
|
end
|
||||||
|
|
||||||
structure QuadTree: QUAD_TREE =
|
structure QuadTree: QUAD_TREE =
|
||||||
@@ -180,9 +184,16 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun insert
|
fun insert
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, tree: t
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, tree: t
|
||||||
) =
|
) =
|
||||||
case tree of
|
case tree of
|
||||||
NODE {topLeft, topRight, bottomLeft, bottomRight, elements} =>
|
NODE {topLeft, topRight, bottomLeft, bottomRight, elements} =>
|
||||||
@@ -627,14 +638,29 @@ struct
|
|||||||
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
||||||
|
|
||||||
fun getCollisions
|
fun getCollisions
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, tree
|
||||||
) =
|
) =
|
||||||
helpGetCollisions
|
helpGetCollisions
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, [], tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, []
|
||||||
|
, tree
|
||||||
)
|
)
|
||||||
|
|
||||||
(* no variant to represent 'no collision' case
|
(* no variant to represent 'no collision' case
|
||||||
@@ -881,14 +907,29 @@ struct
|
|||||||
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
||||||
|
|
||||||
fun getCollisionSides
|
fun getCollisionSides
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, tree
|
||||||
) =
|
) =
|
||||||
helpGetCollisionSides
|
helpGetCollisionSides
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, [], tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, []
|
||||||
|
, tree
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getCollisionsBelowVec (iX, iY, iW, iH, itemID, pos, elements, acc) =
|
fun getCollisionsBelowVec (iX, iY, iW, iH, itemID, pos, elements, acc) =
|
||||||
@@ -903,19 +944,12 @@ struct
|
|||||||
case getCollisionSide (iX, iY, iW, iH, item) of
|
case getCollisionSide (iX, iY, iW, iH, item) of
|
||||||
QUERY_ON_BOTTOM_SIDE =>
|
QUERY_ON_BOTTOM_SIDE =>
|
||||||
getCollisionsBelowVec
|
getCollisionsBelowVec
|
||||||
( iX, iY, iW, iH, itemID
|
(iX, iY, iW, iH, itemID, pos + 1, elements, curID :: acc)
|
||||||
, pos + 1, elements, curID :: acc
|
|
||||||
)
|
|
||||||
| _ =>
|
| _ =>
|
||||||
getCollisionsBelowVec
|
getCollisionsBelowVec
|
||||||
( iX, iY, iW, iH, itemID
|
(iX, iY, iW, iH, itemID, pos + 1, elements, acc)
|
||||||
, pos + 1, elements, acc
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
getCollisionsBelowVec
|
getCollisionsBelowVec (iX, iY, iW, iH, itemID, pos + 1, elements, acc)
|
||||||
( iX, iY, iW, iH, itemID
|
|
||||||
, pos + 1, elements, acc
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getCollisionsBelowAll (iX, iY, iW, iH, qW, qH, itemID, acc, tree) =
|
fun getCollisionsBelowAll (iX, iY, iW, iH, qW, qH, itemID, acc, tree) =
|
||||||
@@ -943,9 +977,17 @@ struct
|
|||||||
getCollisionsBelowVec (iX, iY, iW, iH, itemID, 0, elements, acc)
|
getCollisionsBelowVec (iX, iY, iW, iH, itemID, 0, elements, acc)
|
||||||
|
|
||||||
fun helpGetCollisionsBelow
|
fun helpGetCollisionsBelow
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, acc, tree: t
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, acc
|
||||||
|
, tree: t
|
||||||
) =
|
) =
|
||||||
case tree of
|
case tree of
|
||||||
NODE {topLeft, topRight, bottomLeft, bottomRight, elements} =>
|
NODE {topLeft, topRight, bottomLeft, bottomRight, elements} =>
|
||||||
@@ -1086,13 +1128,149 @@ struct
|
|||||||
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements, acc)
|
||||||
|
|
||||||
fun getCollisionsBelow
|
fun getCollisionsBelow
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, tree
|
||||||
) =
|
) =
|
||||||
helpGetCollisionsBelow
|
helpGetCollisionsBelow
|
||||||
( itemX, itemY, itemWidth, itemHeight
|
( itemX
|
||||||
, quadX, quadY, quadWidth, quadHeight
|
, itemY
|
||||||
, itemID, [], tree
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, []
|
||||||
|
, tree
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun hasCollisionAtVec (iX, iY, iW, iH, itemID, pos, elements) =
|
||||||
|
if pos = Vector.length elements then
|
||||||
|
false
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val item = Vector.sub (elements, pos)
|
||||||
|
in
|
||||||
|
isColliding (iX, iY, iW, iH, itemID, item)
|
||||||
|
orelse hasCollisionAtVec (iX, iY, iW, iH, itemID, pos + 1, elements)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun hasCollisionAt
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
, itemID
|
||||||
|
, tree
|
||||||
|
) =
|
||||||
|
case tree of
|
||||||
|
NODE {topLeft, topRight, bottomLeft, bottomRight, elements} =>
|
||||||
|
hasCollisionAtVec
|
||||||
|
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements)
|
||||||
|
orelse
|
||||||
|
(case
|
||||||
|
whichQuadrant
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, quadWidth
|
||||||
|
, quadHeight
|
||||||
|
)
|
||||||
|
of
|
||||||
|
TOP_LEFT =>
|
||||||
|
let
|
||||||
|
val halfWidth = quadWidth div 2
|
||||||
|
val halfHeight = quadHeight div 2
|
||||||
|
in
|
||||||
|
hasCollisionAt
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, quadY
|
||||||
|
, halfWidth
|
||||||
|
, halfHeight
|
||||||
|
, itemID
|
||||||
|
, topLeft
|
||||||
|
)
|
||||||
|
end
|
||||||
|
| TOP_RIGHT =>
|
||||||
|
let
|
||||||
|
val halfWidth = quadWidth div 2
|
||||||
|
val halfHeight = quadHeight div 2
|
||||||
|
val middleX = quadX + halfWidth
|
||||||
|
in
|
||||||
|
hasCollisionAt
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, middleX
|
||||||
|
, quadY
|
||||||
|
, halfWidth
|
||||||
|
, halfHeight
|
||||||
|
, itemID
|
||||||
|
, topRight
|
||||||
|
)
|
||||||
|
end
|
||||||
|
| BOTTOM_LEFT =>
|
||||||
|
let
|
||||||
|
val halfWidth = quadWidth div 2
|
||||||
|
val halfHeight = quadHeight div 2
|
||||||
|
val middleY = quadY + halfHeight
|
||||||
|
in
|
||||||
|
hasCollisionAt
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, quadX
|
||||||
|
, middleY
|
||||||
|
, halfWidth
|
||||||
|
, halfHeight
|
||||||
|
, itemID
|
||||||
|
, bottomLeft
|
||||||
|
)
|
||||||
|
end
|
||||||
|
| BOTTOM_RIGHT =>
|
||||||
|
let
|
||||||
|
val halfWidth = quadWidth div 2
|
||||||
|
val halfHeight = quadHeight div 2
|
||||||
|
val middleX = quadX + halfWidth
|
||||||
|
val middleY = quadY + halfHeight
|
||||||
|
in
|
||||||
|
hasCollisionAt
|
||||||
|
( itemX
|
||||||
|
, itemY
|
||||||
|
, itemWidth
|
||||||
|
, itemHeight
|
||||||
|
, middleX
|
||||||
|
, middleY
|
||||||
|
, halfWidth
|
||||||
|
, halfHeight
|
||||||
|
, itemID
|
||||||
|
, bottomRight
|
||||||
|
)
|
||||||
|
end
|
||||||
|
| PARENT_QUADRANT => false)
|
||||||
|
| LEAF elements =>
|
||||||
|
hasCollisionAtVec
|
||||||
|
(itemX, itemY, itemWidth, itemHeight, itemID, 0, elements)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user