diff --git a/fcore/game-type.sml b/fcore/game-type.sml index 98bd00b..b3009ab 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -55,6 +55,7 @@ sig | W_JUMP_PRESSED of bool | W_ENEMIES of defeated_enemies vector | W_CHARGE of int + | W_PROJECTILES of player_projectile vector type enemy = {id: int, health: int, x: int, y: int} @@ -129,6 +130,7 @@ struct | W_JUMP_PRESSED of bool | W_ENEMIES of defeated_enemies vector | W_CHARGE of int + | W_PROJECTILES of player_projectile vector type enemy = {id: int, health: int, x: int, y: int} diff --git a/fcore/game-update.sml b/fcore/game-update.sml index ee60bf5..eab845e 100644 --- a/fcore/game-update.sml +++ b/fcore/game-update.sml @@ -150,15 +150,8 @@ struct fun update (game, input) = let - val - { player - , walls - , wallTree - , platforms - , platformTree - , enemies - , enemyTree - } = game + val {player, walls, wallTree, platforms, platformTree, enemies, enemyTree} = + game val player = Player.runPhysicsAndInput (game, input) diff --git a/fcore/player.sml b/fcore/player.sml index 5fead1a..e293f28 100644 --- a/fcore/player.sml +++ b/fcore/player.sml @@ -495,11 +495,28 @@ struct end end - fun getMainAttackPatches (attackHeld, chargeHeld, charge) = + fun prevWasNotAttacking prevAttack = prevAttack <> MAIN_ATTACKING + + (* called only when player has no projectiles or was not previously attacking *) + fun helpGetMainAttackPatches (attackHeld, chargeHeld, charge) = if attackHeld andalso charge > 0 then MAIN_ATTACKING else if chargeHeld andalso not attackHeld then MAIN_CHARGING else MAIN_NOT_ATTACKING + fun getMainAttackPatches + (prevAttack, defeteadEnemies, projectiles, attackHeld, chargeHeld, charge) = + if attackHeld then + if + prevWasNotAttacking prevAttack andalso Vector.length defeteadEnemies > 0 + then + (* shoot projectiles if player was not attacking previously, + * and there is more than one enemy *) + raise Match + else + helpGetMainAttackPatches (attackHeld, chargeHeld, charge) + else + helpGetMainAttackPatches (attackHeld, chargeHeld, charge) + fun getInputPatches (player: player, input) = let val @@ -511,6 +528,8 @@ struct , mainAttack , mainAttackPressed , charge + , enemies + , projectiles , ... } = player @@ -519,7 +538,9 @@ struct val xAxis = getXAxis (leftHeld, rightHeld) val facing = getFacing (facing, xAxis) - val mainAttack = getMainAttackPatches (attackHeld, chargeHeld, charge) + + val mainAttack = getMainAttackPatches + (mainAttack, enemies, projectiles, attackHeld, chargeHeld, charge) val charge = case mainAttack of @@ -613,12 +634,9 @@ struct val player = let val e = #enemies player - val e = Vector.map (fn {angle} => - { - angle = - if angle < 360 then angle + 5 else 0 - }) - e + val e = + Vector.map + (fn {angle} => {angle = if angle < 360 then angle + 5 else 0}) e val patches = [W_ENEMIES e] in withPatches (player, patches) @@ -831,7 +849,7 @@ struct if height > scale then (height - scale) / 2.0 else if height < scale then (scale - height) / 2.0 else 0.0 - in + in helpGetPelletVec (x, y, 0, enemies, width, height, wratio, 0.0, yOffset, []) end