a bit of additional refactoring

This commit is contained in:
2025-01-12 22:10:58 +00:00
parent 8052ad53f7
commit 3dddd096f7
2 changed files with 27 additions and 7 deletions

View File

@@ -59,10 +59,10 @@ struct
let
val enemyCollisions = QuadTree.getCollisions
(x, y, size, size, 0, 0, 1920, 1080, 0, enemyTree)
val lst = [W_ATTACKED NOT_ATTACKED]
val player =
Player.enemyCollisionReaction
(player, enemies, enemyCollisions, lst)
Player.exitAttackedAndCheckEnemies
(player, enemies, enemyCollisions)
val enemies = Enemy.filterProjectileCollisions
(Vector.length enemies - 1, enemies, projectileTree, [])
@@ -74,10 +74,7 @@ struct
* allowing a brief invincibility period as is common in many games
* *)
let
val amt = amt + 1
val attacked = ATTACKED amt
val player = Player.withPatch (player, W_ATTACKED attacked)
val player = Player.incrementAttacked (player, amt)
val enemies = Enemy.filterProjectileCollisions
(Vector.length enemies - 1, enemies, projectileTree, [])
in

View File

@@ -494,6 +494,29 @@ struct
end
| [] => PlayerPatch.withPatches (player, acc)
fun incrementAttacked (player, amt) =
let val patch = ATTACKED (amt + 1)
in PlayerPatch.withPatch (player, W_ATTACKED patch)
end
fun exitAttackedAndCheckEnemies (player, enemies, enemyCollisions) =
enemyCollisionReaction
(player, enemies, enemyCollisions, [W_ATTACKED NOT_ATTACKED])
fun getEnemyCollisionsWhenAttacking (x, y, enemyTree) =
let
val x = x - Constants.halfPlayerSize
val y = y - Constants.halfPlayerSize
val size = Constants.playerSize * 2
val ww = Constants.worldWidth
val wh = Constants.worldHeight
val enemyCollisions = QuadTree.getCollisions
(x, y, size, size, 0, 0, ww, wh, 0, enemyTree)
in
Vector.fromList enemyCollisions
end
(* block is placeholder asset *)
fun helpGetDrawVec (x, y, size, width, height, attacked, mainAttack) =
case mainAttack of