ever wanted to have time-based commands in a game? Like if you were to hit 236A you’d throw a fireball if they were input fast enough and no other keys were between them? Well this is for you than!
/*Created by William Starkovich*/
public class KeyBuf {
int key[];
int length = 10;
int ticks = 0;
int maxTicks = 15;
int num = 0;
public KeyBuf(int l, int mt){
length = l;
maxTicks = mt;
}
public void init(){
key = new int[length];
for(int i = 0; i < length; i++){
key[i] = -1;
}
}
public void update(){
if(ticks >= maxTicks){
for(int i = 0; i < length; i++){
key[i] = -1;
}
num = 0;
ticks = 0;
}
ticks++;
}
public void keyPressed(int keyNum){
key[num] = keyNum;
num++;
ticks = 0;
if(num >= length){
for(int i = 1; i < length; i++){
key[i-1] = key[i];
}
num--;
}
}
}