From 7734496a8cbab7fcd2212a8ef3fb4b7be838c54b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 7 Feb 2025 12:32:38 +0000 Subject: [PATCH] remove some references to charging when/ife we don't need it, and also only trigger throw/attack on new button press (if held, throw/attack is not repeated) --- fcore/game-type.sml | 2 -- fcore/player-patch.sml | 20 ++++++++++++++ fcore/player.sml | 63 ++++++++++++------------------------------ 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/fcore/game-type.sml b/fcore/game-type.sml index bbdf451..8badfd5 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -22,7 +22,6 @@ sig datatype main_attack = MAIN_NOT_ATTACKING | MAIN_ATTACKING of {length: int, growing: bool} - | MAIN_CHARGING | MAIN_THROWING type defeated_enemies = {angle: int} @@ -97,7 +96,6 @@ struct datatype main_attack = MAIN_NOT_ATTACKING | MAIN_ATTACKING of {length: int, growing: bool} - | MAIN_CHARGING | MAIN_THROWING type defeated_enemies = {angle: int} diff --git a/fcore/player-patch.sml b/fcore/player-patch.sml index efae978..279918c 100644 --- a/fcore/player-patch.sml +++ b/fcore/player-patch.sml @@ -11,6 +11,7 @@ sig | W_X of int | W_Y of int | W_JUMP_PRESSED of bool + | W_MAIN_ATTACK_PRESSED of bool | W_ENEMIES of GameType.defeated_enemies vector | W_CHARGE of int | W_PROJECTILES of GameType.player_projectile vector @@ -33,6 +34,7 @@ struct | W_X of int | W_Y of int | W_JUMP_PRESSED of bool + | W_MAIN_ATTACK_PRESSED of bool | W_ENEMIES of GameType.defeated_enemies vector | W_CHARGE of int | W_PROJECTILES of GameType.player_projectile vector @@ -273,6 +275,24 @@ struct , projectiles , platID ) + | W_MAIN_ATTACK_PRESSED mainAttackPressed => + mkPlayer + ( health + , xAxis + , yAxis + , x + , y + , jumpPressed + , recoil + , attacked + , mainAttack + , facing + , mainAttackPressed + , enemies + , charge + , projectiles + , platID + ) | W_ENEMIES enemies => mkPlayer ( health diff --git a/fcore/player.sml b/fcore/player.sml index 05e3828..b0a65c8 100644 --- a/fcore/player.sml +++ b/fcore/player.sml @@ -82,17 +82,16 @@ struct end (* called only when player has no projectiles or was not previously attacking *) - fun helpGetMainAttackPatches (attackHeld, chargeHeld, charge) = + fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) = let val attack = - if attackHeld andalso charge > 0 then + if attackHeld andalso not mainAttackPressed then MAIN_ATTACKING {length = 3, growing = true} - else if chargeHeld andalso not attackHeld then - MAIN_CHARGING else MAIN_NOT_ATTACKING in - W_MAIN_ATTACK attack + W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed) + :: W_MAIN_ATTACK attack :: acc end fun degreesToRadians degrees = Real32.fromInt degrees * Constants.projectilePi @@ -146,30 +145,19 @@ struct , charge , player , acc + , mainAttackPressed ) = case prevAttack of MAIN_NOT_ATTACKING => - if attackHeld andalso Vector.length defeteadEnemies > 0 then + if + attackHeld andalso not mainAttackPressed + 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 + helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) | MAIN_ATTACKING {length, growing} => let val mainAttack = @@ -193,18 +181,13 @@ struct else MAIN_ATTACKING {length = newLength, growing = false} end in - W_MAIN_ATTACK mainAttack :: acc + W_MAIN_ATTACK_PRESSED true :: W_MAIN_ATTACK mainAttack :: acc end | MAIN_THROWING => if attackHeld then acc else - let - val mainAttack = - helpGetMainAttackPatches (attackHeld, chargeHeld, charge) - in - mainAttack :: acc - end + helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) fun getInputPatches (player: player, input) = let @@ -228,11 +211,7 @@ struct val xAxis = getXAxis (leftHeld, rightHeld) val facing = getFacing (facing, xAxis) - val charge = - case mainAttack of - MAIN_CHARGING => Int.min (charge + 1, Constants.maxCharge) - | MAIN_ATTACKING _ => (* todo: rework charge *) Int.max (charge - 1, 0) - | _ => charge + val charge = (* todo: rework charge *) charge val acc = [W_X_AXIS xAxis, W_FACING facing, W_CHARGE charge] @@ -245,6 +224,7 @@ struct , charge , player , acc + , mainAttackPressed ) val acc = getJumpPatches (player, upHeld, downHeld, acc) @@ -467,7 +447,7 @@ struct val {x, y, facing, enemies, ...} = player val x = (case facing of - FACING_RIGHT => x + length + FACING_RIGHT => x + Constants.playerSize | FACING_LEFT => x - length) val state = [] @@ -525,15 +505,6 @@ struct Block.lerp (x, y, size, size, width, height, 1.0, 0.9, 0.9) else Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5)) - | MAIN_CHARGING => - (case attacked of - NOT_ATTACKED => - Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5) - | ATTACKED amt => - if amt mod 5 = 0 then - Block.lerp (x, y, size, size, width, height, 1.0, 0.9, 0.9) - else - Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5)) fun getDrawVec (player: player, width, height) = let @@ -583,7 +554,7 @@ struct val x = case #facing player of FACING_RIGHT => x + Constants.playerSize - | FACING_LEFT => x - Constants.playerSize - length + | FACING_LEFT => x - length in if wratio < hratio then let @@ -626,7 +597,7 @@ struct val x = Real32.fromInt x * hratio + xOffset val y = Real32.fromInt y * hratio - val realLength = Real32.fromInt length * wratio + xOffset + val realLength = Real32.fromInt length * hratio val realSize = Constants.playerSizeReal * hratio val {charge, ...} = player