From b9939bbc2d23dd5bb4b7edd756796fe1f590d599 Mon Sep 17 00:00:00 2001 From: Phew Date: Sun, 4 Jan 2026 18:25:13 +0100 Subject: [PATCH] Changed attack logic --- TWANG32/TWANG32.ino | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/TWANG32/TWANG32.ino b/TWANG32/TWANG32.ino index 74a3c7c..997b473 100644 --- a/TWANG32/TWANG32.ino +++ b/TWANG32/TWANG32.ino @@ -66,7 +66,7 @@ long previousMillis = 0; // Time of the last redraw int levelNumber = 0; -#define TIMEOUT 20000 // time until screen saver in milliseconds +#define TIMEOUT 60000 // time until screen saver in milliseconds int joystickTilt = 0; // Stores the angle of the joystick int joystickWobble = 0; // Stores the max amount of acceleration (wobble) @@ -74,9 +74,10 @@ int joystickWobble = 0; // Stores the max amount of acceleration (wob // WOBBLE ATTACK #define DEFAULT_ATTACK_WIDTH 70 // Width of the wobble attack, world is 1000 wide int attack_width = DEFAULT_ATTACK_WIDTH; -#define ATTACK_DURATION 500 // Duration of a wobble attack (ms) +#define ATTACK_DURATION 1000 // Duration of a wobble attack (ms) long attackMillis = 0; // Time the attack started bool attacking = 0; // Is the attack in progress? +bool canAttackAgain = 0; // Have I finished my previous attack? #define BOSS_WIDTH 40 // TODO all animation durations should be defined rather than literals @@ -268,7 +269,9 @@ void loop() { long frameTimer = mm; previousMillis = mm; - if(abs(joystickTilt) > user_settings.joystick_deadzone){ + if((abs(joystickTilt) > user_settings.joystick_deadzone) || + (joystickWobble >= user_settings.attack_threshold)) + { lastInputTime = mm; if(stage == SCREENSAVER){ levelNumber = -1; @@ -297,10 +300,18 @@ void loop() { } }else if(stage == PLAY){ // PLAYING - if(attacking && attackMillis+ATTACK_DURATION < mm) attacking = 0; + if(attacking && attackMillis+ATTACK_DURATION < mm) { + attacking = 0; + canAttackAgain = 0; + } + + if(joystickWobble < user_settings.attack_threshold){ + attacking = 0; + canAttackAgain = 1; + } // If not attacking, check if they should be - if(!attacking && joystickWobble >= user_settings.attack_threshold){ + if(!attacking && canAttackAgain && (joystickWobble >= user_settings.attack_threshold)){ attackMillis = mm; attacking = 1; }