diff --git a/fcore/game-type.sml b/fcore/game-type.sml index b3009ab..59488e4 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -19,7 +19,11 @@ sig datatype facing = FACING_LEFT | FACING_RIGHT - datatype main_attack = MAIN_NOT_ATTACKING | MAIN_ATTACKING | MAIN_CHARGING + datatype main_attack = + MAIN_NOT_ATTACKING + | MAIN_ATTACKING + | MAIN_CHARGING + | MAIN_THROWING type defeated_enemies = {angle: int} @@ -94,7 +98,11 @@ struct datatype facing = FACING_LEFT | FACING_RIGHT - datatype main_attack = MAIN_NOT_ATTACKING | MAIN_ATTACKING | MAIN_CHARGING + datatype main_attack = + MAIN_NOT_ATTACKING + | MAIN_ATTACKING + | MAIN_CHARGING + | MAIN_THROWING type defeated_enemies = {angle: int} diff --git a/fcore/player.sml b/fcore/player.sml index 1c3d94f..f37958a 100644 --- a/fcore/player.sml +++ b/fcore/player.sml @@ -546,6 +546,21 @@ struct defeatedEnemiesToProjectiles (pos + 1, defeteadEnemies, player, acc) end + fun getThrowPatches (defeteadEnemies, projectiles, player, acc) = + let + val newProjectiles = + defeatedEnemiesToProjectiles (0, defeteadEnemies, player, []) + + (* concatenate new projectiles with previous projectiles *) + val allProjectiles = Vector.concat [newProjectiles, projectiles] + + (* remove defeated enemies from player record *) + val enemies = Vector.fromList [] + in + W_MAIN_ATTACK MAIN_THROWING :: W_PROJECTILES allProjectiles + :: W_ENEMIES enemies :: acc + end + fun getMainAttackPatches ( prevAttack , defeteadEnemies @@ -556,38 +571,46 @@ struct , player , acc ) = - 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 *) - let - val newProjectiles = - defeatedEnemiesToProjectiles (0, defeteadEnemies, player, []) - - (* concatenate new projectiles with previous projectiles *) - val allProjectiles = Vector.concat [newProjectiles, projectiles] - - (* remove defeated enemies from player record *) - val enemies = Vector.fromList [] - in - W_PROJECTILES allProjectiles :: W_ENEMIES enemies :: acc - end - else + case prevAttack of + MAIN_NOT_ATTACKING => + if attackHeld andalso Vector.length defeteadEnemies > 0 then + (* shoot projectiles if player was not attacking previously, + * and there is more than one enemy *) + getThrowPatches (defeteadEnemies, projectiles, player, acc) + else + let + val mainAttack = + helpGetMainAttackPatches (attackHeld, chargeHeld, charge) + in + mainAttack :: acc + end + | MAIN_CHARGING => + if attackHeld andalso Vector.length defeteadEnemies > 0 then + getThrowPatches (defeteadEnemies, projectiles, player, acc) + else + let + val mainAttack = + helpGetMainAttackPatches (attackHeld, chargeHeld, charge) + in + mainAttack :: acc + end + | MAIN_ATTACKING => let val mainAttack = helpGetMainAttackPatches (attackHeld, chargeHeld, charge) in mainAttack :: acc end - else - let - val mainAttack = - helpGetMainAttackPatches (attackHeld, chargeHeld, charge) - in - mainAttack :: acc - end + | MAIN_THROWING => + if attackHeld then + acc + else + let + val mainAttack = + helpGetMainAttackPatches (attackHeld, chargeHeld, charge) + in + mainAttack :: acc + end fun getInputPatches (player: player, input) = let @@ -615,7 +638,7 @@ struct case mainAttack of MAIN_CHARGING => Int.min (charge + 1, maxCharge) | MAIN_ATTACKING => Int.max (charge - 1, 0) - | MAIN_NOT_ATTACKING => charge + | _ => charge val acc = [W_X_AXIS xAxis, W_FACING facing, W_CHARGE charge] @@ -738,6 +761,15 @@ struct Block.lerp (x, y, size, size, width, height, 0.9, 0.9, 0.9) else Block.lerp (x, y, size, size, width, height, 0.5, 0.5, 0.5)) + | MAIN_THROWING => + (case attacked of + NOT_ATTACKED => + Block.lerp (x, y, size, size, width, height, 0.5, 0.5, 0.5) + | ATTACKED amt => + if amt mod 5 = 0 then + Block.lerp (x, y, size, size, width, height, 0.9, 0.9, 0.9) + else + Block.lerp (x, y, size, size, width, height, 0.5, 0.5, 0.5)) | MAIN_ATTACKING => (case attacked of NOT_ATTACKED =>