Commit bc17bb47 authored by Miloslav Číž's avatar Miloslav Číž

Add button repeat

parent a86cc063
......@@ -127,6 +127,9 @@
#define UPGRADE_DAMAGE_FRACTION_INCREASE 2 /**< Fractional increase (+ 1/x) of
damage by upgrade. */
#define BUTTON_REPEAT_DELAY 20 ///< Initial button repeat delay, in frames.
#define BUTTON_REPEAT_PERIOD 6 ///< Button repeat period in frames.
#define CHEAT_NONE 0
#define CHEAT_MONEY 1
......@@ -2659,20 +2662,40 @@ void drawMap()
}
}
uint8_t buttonRepeatCounter = BUTTON_REPEAT_DELAY;
inline void checkButton(uint8_t button, bool checkRepeat=false)
{
if (arduboy.justPressed(button))
{
game.buttonDown(button);
}
if (checkRepeat)
{
if (arduboy.pressed(button))
{
if (buttonRepeatCounter == 0)
{
if (arduboy.frameCount % BUTTON_REPEAT_PERIOD == 0)
game.buttonDown(button);
}
else
buttonRepeatCounter--;
}
else if (arduboy.justReleased(button))
buttonRepeatCounter = BUTTON_REPEAT_DELAY;
}
}
void handleInputs()
{
#define checkButton(b)\
if (arduboy.justPressed(b))\
game.buttonDown(b);
checkButton(A_BUTTON);
checkButton(B_BUTTON);
checkButton(LEFT_BUTTON);
checkButton(RIGHT_BUTTON);
checkButton(UP_BUTTON);
checkButton(DOWN_BUTTON);
#undef checkButton
checkButton(LEFT_BUTTON,true);
checkButton(RIGHT_BUTTON,true);
checkButton(UP_BUTTON,true);
checkButton(DOWN_BUTTON,true);
// cheat
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment