Xbox 360 controller combinations with LWJGL in Java.

 

I suppose instead of starting a new blog I may as well reboot this old blog.
In this section of the blog I’d like to talk about a solution I developed to finding combinations of buttons pressed on a controller. It may not be perfect, like everything I am sure it has flaws. In my controller assignment I was concerned with ABXY on the Xbox 360 controller. Having no background in programming with controllers this was something new I never came across before, how to tell a combination of button presses. So if A followed soon by A is double jump how’d I note that down?

I suppose it’s important to note, the original idea of having button combinations as part of my assignment was suggested to me by Joost, a lead developer of a game called “Awesomenauts” and who’s part of Ronimo and indie games company.

I started off thinking the possible ways to do it, one thing that kept on coming to mind was the Fibonacci sequence(0..1..1..2..3..5..8..etc). But why?Well the logic I had was if I assigned a number, let’s say 1 to A, then if A was pressed twice I knew the combination number would be 2. This was similar to the Fibonacci in that regard. But then we can face a problem. For this idea to work I needed to make it so no 2 combinations could create the same sum. Here’s where we begin to face a problem. As an example, if we assigned 0 to A, 2 to B, and 1 to X. Then the combination of AB is the same as XX.

From here my approach was that whatever number I assigned to each button needed to be sum of previous combinations added together + 1.(..1..3..5..9..18..36). The only reason that this would work is a single button press doesn’t count as a combination. You may get 9 + 9 which gives 18, but whatever button has the value of 18 wont count as a combination until the value of another button is added to it. I cross referenced this against (https://en.wikipedia.org/wiki/List_of_OEIS_sequences) The only similar sequence you could get would be “Jacobsthal number”.

At this point I also noticed, AB and BA would result in the same value. This was problematic and I still have figured an approach to deal with this problem truth be told. I suppose Booleans could be used for it. But truth be told for this assignment I decided to sweep this problem under the rug.

The code snippet (in Java) I used for calculating what number it would be is here.

if(buttoncounter==0)
{
buttime1=System.currentTimeMillis();
buttonvalues.add(number);
}
if(buttoncounter==1)
{
buttime2=System.currentTimeMillis();
buttonvalues.add(number);
timebetween=buttime2-buttime1;
if(timebetween < buttonms)
{
buttonadder();
buttoncounter=-1;
timebetween=buttonms*2;
buttonvalues.clear()

}
else
{
buttonvalues.clear();
buttoncounter=-1;
timebetween=buttonms*2;
buttime1=buttime2=buttonms*20;
}
buttonvalues.clear();
}
}

So, at this point I leave you a question. How’d you go about this? What do you think of my method?All constructive criticism is appreciated.

Leave a comment