@Eli I got a feeling I didn't explain what this really is enough. When I said 236A I didn't mean (2 + 3 + 6 + the A Key) I meant QFC + Weak Punch, or D -> DF -> F -> A. Umm Think of a Hadoken. You don't hit down (2) + down-forward (3) + forward(6) +Weak Punch (A) you hit 2 than 3 than 6 than A, so if I removed a key every time it was released I would end up with only A on my buffer when I got to the last part of the special attack and it wouldn't go off, or would go off any time I hit A depending on how I code it.
You guys were right. I can still have a user-length selected array length without a separate length variable.
@Nate "It would be better to use a circular buffer rather than shifting all the keys." I don't quite understand this. what do you mean "circular buffer?"
@Nate "You could use zero for "no key" and get rid of the loop in init." I'm a little paranoid about Null stuff, so that's why I set the value myself.
updated src:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public class KeyBuf { int key[]; int ticks = 0; int maxTicks = 15; int num = 0; public KeyBuf(int l, int mt){ if(l <= 0) l = 1;
maxTicks = mt; key = new int[l]; for(int i = 0; i < key.length; i++){ key[i] = -1; } }
public void update(){ if(ticks >= maxTicks){ for(int i = 0; i < key.length; i++){ key[i] = -1; } num = 0; ticks = 0; } ticks++; } public void keyPressed(int keyNum){ key[num] = keyNum; num++; ticks = 0; if(num >= key.length){ for(int i = 1; i < key.length; i++){ key[i-1] = key[i]; } num--; } } }
|