Changed attack logic

This commit is contained in:
Phew
2026-01-04 18:25:13 +01:00
parent e5f7e1ba84
commit b9939bbc2d

View File

@@ -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;
}