diff --git a/fcore/player-enemy.sml b/fcore/player-enemy.sml index ffae80b..40fc2c1 100644 --- a/fcore/player-enemy.sml +++ b/fcore/player-enemy.sml @@ -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 diff --git a/fcore/player.sml b/fcore/player.sml index 0ea1595..5b97f29 100644 --- a/fcore/player.sml +++ b/fcore/player.sml @@ -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