final commit
This commit is contained in:
parent
1e819f99e0
commit
4d67a8b0e6
@ -33,8 +33,8 @@ public class inputHandler {
|
||||
|
||||
public static final Rectangle mouseMovementArea = new Rectangle(30,20, 708, 472);
|
||||
|
||||
public static char[] inputBuffer = new char[64];
|
||||
public static char[] keyReleaseBuffer = new char[64];
|
||||
public static char[] inputBuffer = new char[1024];
|
||||
public static char[] keyReleaseBuffer = new char[1024];
|
||||
|
||||
public static int inputCounter, inputBufferIndex, keyReleaseCounter, keyReleaseBufferIndex;
|
||||
|
||||
@ -52,7 +52,45 @@ public class inputHandler {
|
||||
int theCounter = inputCounter;
|
||||
|
||||
mainThread.currentInputChar = 255;
|
||||
|
||||
|
||||
//handle over flow
|
||||
if(inputBufferIndex > theCounter){
|
||||
while(inputBufferIndex < 1024){
|
||||
char c = inputBuffer[inputBufferIndex];
|
||||
mainThread.currentInputChar = c;
|
||||
|
||||
|
||||
if(c == 's' || c == 'S'){
|
||||
|
||||
S_pressed = true;
|
||||
}
|
||||
|
||||
if(c == 'a' || c == 'A'){
|
||||
A_pressed = true;
|
||||
}
|
||||
|
||||
if(c == 'c' || c == 'C'){
|
||||
|
||||
C_pressed = true;
|
||||
}
|
||||
|
||||
if(c == 'f' || c == 'F'){
|
||||
F_pressed = true;
|
||||
}
|
||||
|
||||
|
||||
if(c >=49 && c <=53){
|
||||
numberTyped = c - 48;
|
||||
}
|
||||
|
||||
|
||||
inputBufferIndex++;
|
||||
|
||||
}
|
||||
inputBufferIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
while(inputBufferIndex < theCounter){
|
||||
char c = inputBuffer[inputBufferIndex];
|
||||
mainThread.currentInputChar = c;
|
||||
@ -80,13 +118,37 @@ public class inputHandler {
|
||||
|
||||
inputBufferIndex++;
|
||||
}
|
||||
|
||||
//clear key input buffer
|
||||
inputBufferIndex = 0;
|
||||
inputCounter = 0;
|
||||
|
||||
|
||||
//read released char
|
||||
theCounter = keyReleaseCounter;
|
||||
//handle over flow
|
||||
if(keyReleaseBufferIndex > theCounter){
|
||||
while(keyReleaseBufferIndex < 1024){
|
||||
char c = keyReleaseBuffer[keyReleaseBufferIndex];
|
||||
|
||||
if(c == 's' || c == 'S'){
|
||||
S_pressed = false;
|
||||
}
|
||||
|
||||
if(c == 'a' || c == 'A'){
|
||||
A_pressed = false;
|
||||
userIsHoldingA = false;
|
||||
|
||||
}
|
||||
if(c == 'c' || c == 'C'){
|
||||
C_pressed = false;
|
||||
userIsHoldingC = false;
|
||||
|
||||
}
|
||||
if(c == 'f' || c == 'F'){
|
||||
F_pressed = false;
|
||||
userIsHoldingF = false;
|
||||
}
|
||||
keyReleaseBufferIndex++;
|
||||
}
|
||||
keyReleaseBufferIndex = 0;
|
||||
}
|
||||
while(keyReleaseBufferIndex < theCounter){
|
||||
char c = keyReleaseBuffer[keyReleaseBufferIndex];
|
||||
|
||||
@ -111,9 +173,7 @@ public class inputHandler {
|
||||
keyReleaseBufferIndex++;
|
||||
}
|
||||
|
||||
//clear key release buffer
|
||||
keyReleaseBufferIndex = 0;
|
||||
keyReleaseCounter = 0;
|
||||
|
||||
|
||||
//handle input when game is running
|
||||
if(!mainThread.gamePaused && mainThread.gameStarted){
|
||||
@ -369,14 +429,16 @@ public class inputHandler {
|
||||
public static void readCharacter(char c){
|
||||
inputBuffer[inputCounter] = c;
|
||||
inputCounter++;
|
||||
if(inputCounter == inputBuffer.length)
|
||||
if(inputCounter == 1024)
|
||||
inputCounter = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void handleKeyRelease(char c){
|
||||
keyReleaseBuffer[keyReleaseCounter] = c;
|
||||
keyReleaseCounter++;
|
||||
if(keyReleaseCounter == keyReleaseBuffer.length)
|
||||
if(keyReleaseCounter == 1024)
|
||||
keyReleaseCounter = 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user