a bit of refactoring and clearer naming
This commit is contained in:
@@ -440,6 +440,60 @@ struct
|
||||
PlayerPatch.withPatches (player, patches)
|
||||
end
|
||||
|
||||
fun concatAttackedEnemies (player: player, enemyCollisions) =
|
||||
let
|
||||
val newDefeated = Vector.map (fn id => {angle = 360}) enemyCollisions
|
||||
val oldDefeated = #enemies player
|
||||
val allDefeated = Vector.concat [oldDefeated, newDefeated]
|
||||
in
|
||||
PlayerPatch.withPatch (player, W_ENEMIES allDefeated)
|
||||
end
|
||||
|
||||
fun getEnemyRecoilPatches (player, playerOnRight, acc) =
|
||||
if playerOnRight then
|
||||
let
|
||||
val newRecoil = RECOIL_RIGHT 0
|
||||
val newAttacked = ATTACKED 0
|
||||
in
|
||||
W_RECOIL newRecoil :: W_ATTACKED newAttacked :: W_FACING FACING_LEFT
|
||||
:: W_Y_AXIS FALLING :: W_X_AXIS STAY_STILL :: acc
|
||||
end
|
||||
else
|
||||
let
|
||||
val newRecoil = RECOIL_LEFT 0
|
||||
val newAttacked = ATTACKED 0
|
||||
in
|
||||
W_RECOIL newRecoil :: W_ATTACKED newAttacked :: W_FACING FACING_RIGHT
|
||||
:: W_Y_AXIS FALLING :: W_X_AXIS STAY_STILL :: acc
|
||||
end
|
||||
|
||||
fun enemyCollisionReaction (player: player, enemies: enemy vector, lst, acc) =
|
||||
case lst of
|
||||
id :: tl =>
|
||||
let
|
||||
val playerOnRight =
|
||||
(* check if collision is closer to left side of enemy or right
|
||||
* and then chose appropriate direction to recoil in *)
|
||||
let
|
||||
val {x, ...} = player
|
||||
val pFinishX = x + Constants.playerSize
|
||||
val pHalfW = Constants.playerSize div 2
|
||||
val pCentreX = x + pHalfW
|
||||
|
||||
val {x = ex, y = ey, ...} = Enemy.find (id, enemies)
|
||||
val eFinishX = ex + Constants.enemySize
|
||||
val eHalfW = Constants.enemySize div 2
|
||||
val eCentreX = ex + eHalfW
|
||||
in
|
||||
eCentreX < pCentreX
|
||||
end
|
||||
|
||||
val acc = getEnemyRecoilPatches (player, playerOnRight, acc)
|
||||
in
|
||||
enemyCollisionReaction (player, enemies, tl, acc)
|
||||
end
|
||||
| [] => PlayerPatch.withPatches (player, acc)
|
||||
|
||||
(* block is placeholder asset *)
|
||||
fun helpGetDrawVec (x, y, size, width, height, attacked, mainAttack) =
|
||||
case mainAttack of
|
||||
|
||||
Reference in New Issue
Block a user