merge hitbox function branch

Add GameMode for changing configuration at booting
This commit is contained in:
2022-01-08 13:50:13 +09:00
parent 34d866d243
commit 11d1b92a58

View File

@@ -12,7 +12,10 @@ int index = 0;
int val = 1;
int prevVal = 1;
struct arrow {
int gameMode = 0;
struct arrow
{
int pinNumber;
int current;
int prev;
@@ -21,7 +24,8 @@ struct arrow {
Hat arrowSymbol;
};
struct ButtonInfo {
struct ButtonInfo
{
int pinNumber;
bool prev;
bool current;
@@ -31,20 +35,27 @@ struct ButtonInfo {
struct arrow arrowTable[4];
struct arrow oldestArrow;
struct arrow newestArrow;
struct arrow oldestXArrow;
struct arrow newestXArrow;
struct arrow oldestYArrow;
struct arrow newestYArrow;
#define ButtonInfoTableSize 9
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
Hat last = Hat::CENTER;
void perms() {
if(val == 0){
if (rapidFireTable[index] == 1){
void perms()
{
if (val == 0)
{
if (rapidFireTable[index] == 1)
{
SwitchControlLibrary().PressButtonA();
rapidPressState = true;
}
if (rapidFireTable[index] == 2){
if (rapidFireTable[index] == 2)
{
SwitchControlLibrary().ReleaseButtonA();
rapidPressState = false;
}
@@ -52,8 +63,8 @@ void perms() {
index = (index + 1) % RapidFireTableSize;
}
void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol) {
void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol)
{
but->pinNumber = pinNumber;
but->buttonSymbol = buttonSymbol;
pinMode(pinNumber, INPUT_PULLUP);
@@ -67,9 +78,6 @@ void setup()
rapidFireTable[RapidFireTableSize / 2] = 2;
SwitchControlLibrary();
MsTimer2::set(1, perms);
MsTimer2::start();
setupButton(&(buttonInfoTable[0]), 3, Button::B);
setupButton(&(buttonInfoTable[1]), 4, Button::X);
setupButton(&(buttonInfoTable[2]), 5, Button::Y);
@@ -91,65 +99,104 @@ void setup()
arrowTable[3].pinNumber = 9;
arrowTable[3].arrowSymbol = Hat::RIGHT;
for (int i=0; i<4; i++){
for (int i = 0; i < 4; i++)
{
pinMode(arrowTable[i].pinNumber, INPUT_PULLUP);
arrowTable[i].older = NULL;
arrowTable[i].newer = NULL;
}
oldestXArrow.older = NULL;
oldestXArrow.newer = &newestXArrow;
oldestXArrow.arrowSymbol = Hat::CENTER;
newestXArrow.older = &oldestXArrow;
newestXArrow.newer = NULL;
oldestYArrow.older = NULL;
oldestYArrow.newer = &newestYArrow;
oldestYArrow.arrowSymbol = Hat::CENTER;
newestYArrow.older = &oldestYArrow;
newestYArrow.newer = NULL;
oldestArrow.older = NULL;
oldestArrow.newer = &newestArrow;
oldestArrow.arrowSymbol = Hat::CENTER;
newestArrow.older = &oldestArrow;
newestArrow.newer = NULL;
if (digitalRead(5) == 0) // check Y button for setting GameMode
{
gameMode = 1;
}
void handleButtonInput(ButtonInfo *but){
MsTimer2::set(1, perms);
MsTimer2::start();
}
void handleButtonInput(ButtonInfo *but)
{
but->current = digitalRead(but->pinNumber);
if(but->prev == 1 && but->current ==0 ){
if (but->prev == 1 && but->current == 0)
{
SwitchControlLibrary().PressButton(but->buttonSymbol);
}
else if(but->prev == 0 && but->current ==1 ) {
else if (but->prev == 0 && but->current == 1)
{
SwitchControlLibrary().ReleaseButton(but->buttonSymbol);
}
but->prev = but->current;
}
void moveHat(Hat dir)
{
if (last != dir)
{
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(dir));
last = dir;
}
}
void loop()
{
if (gameMode == 1)
{
val = digitalRead(2);
if(prevVal == 1 && val == 0){
if (prevVal == 1 && val == 0)
{
SwitchControlLibrary().PressButtonA();
rapidPressState = true;
index = 1;
}
else if(prevVal == 0 && val == 1){
if(rapidPressState){
else if (prevVal == 0 && val == 1)
{
if (rapidPressState)
{
SwitchControlLibrary().ReleaseButtonA();
}
}
prevVal = val;
for(int i=0; i<ButtonInfoTableSize; i++){
for (int i = 0; i < ButtonInfoTableSize; i++)
{
handleButtonInput(&(buttonInfoTable[i]));
}
for (int i=0; i<4; i++){
for (int i = 0; i < 4; i++)
{
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
if(arrowTable[i].prev==1 && arrowTable[i].current==0){
if (arrowTable[i].prev == 1 && arrowTable[i].current == 0)
{
// add arrow to the tail of linked list
arrowTable[i].older = newestArrow.older;
arrowTable[i].newer = &newestArrow;
newestArrow.older->newer = &(arrowTable[i]);
newestArrow.older = &(arrowTable[i]);
}
else if (arrowTable[i].prev==0 && arrowTable[i].current==1){
else if (arrowTable[i].prev == 0 && arrowTable[i].current == 1)
{
arrowTable[i].newer->older = arrowTable[i].older;
arrowTable[i].older->newer = arrowTable[i].newer;
arrowTable[i].newer = NULL;
@@ -158,10 +205,113 @@ void loop()
arrowTable[i].prev = arrowTable[i].current;
}
if(newestArrow.older->arrowSymbol != last){
if (newestArrow.older->arrowSymbol != last)
{
last = newestArrow.older->arrowSymbol;
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(newestArrow.older->arrowSymbol));
}
}
else
{
val = digitalRead(2);
if (prevVal == 1 && val == 0)
{
SwitchControlLibrary().PressButtonA();
index = 1;
}
else if (prevVal == 0 && val == 1)
{
SwitchControlLibrary().ReleaseButtonA();
}
prevVal = val;
for (int i = 0; i < ButtonInfoTableSize; i++)
{
handleButtonInput(&(buttonInfoTable[i]));
}
for (int i = 0; i < 4; i++)
{
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
}
if (arrowTable[1].current == 0)
{
if (arrowTable[3].current == 0)
{
if (arrowTable[0].current == 0)
{
moveHat(Hat::TOP);
}
else
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM);
}
else
{
moveHat(Hat::CENTER);
}
}
}
else
{
if (arrowTable[0].current == 0)
{
moveHat(Hat::TOP_LEFT);
}
else
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM_LEFT);
}
else
{
moveHat(Hat::LEFT);
}
}
}
}
else
{
if (arrowTable[3].current == 0)
{
if (arrowTable[0].current == 0)
{
moveHat(Hat::TOP_RIGHT);
}
else
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM_RIGHT);
}
else
{
moveHat(Hat::RIGHT);
}
}
}
else
{
if (arrowTable[0].current == 0)
{
moveHat(Hat::TOP);
}
else
{
if (arrowTable[2].current == 0)
{
moveHat(Hat::BOTTOM);
}
else
{
moveHat(Hat::CENTER);
}
}
}
}
}
}