java - KeyListener for multiplayer game with keys being pressed at the same time? -


I am writing a two-player snake game. The arrow keys respond to a snake and the WASD keys answer the other, though I have seen in my code that if one key is pressed at the same time for each snake then only a snake turns up. I have two main listers. Which consists of an array of four keys which should answer it.

  Class PlayerExpilerListener implies KeyListener {set of currently pressed keys set to personal finals & lt; Integer & gt; buried; Private int event []; Private color C; Private IT; Public PlayerPreviousListener (Int [] A, Color Call, Int I) {Super; Pressed = NewHashet & lt; Integer & gt; (); KeyEvent = a; C = col; This.i = i; } @ Override Press the public volume key (key E) {if pressed content (main event [0]) || pressed ears (key event [1]) || pressed ears (key event [2]) || pressed Pressed (keyEvent [3])) .ed (e.getKeyCode ()); ProccessKey (e.getKeyCode ()); } @ Override Public Wide Key Related (Key Event E) {Pressed. Remove (E. gecakecode ()); } @ Override Public Wide Type (keyEvent) {/ * is not used * Public Zero Processing that is (key) {if (canturn [i]) {int d = grid.getDirection (c); If (key == key event [0]) {if (D == 360) grid Set Direction (D-90, C); // Specifies the direction of snake with specific color and if (d = 180 = 180) grid Set Direction (D + 90, C); } And if (key == keyive [1]) {if (d == 360) grid. Set Direction (d + 90, c); Else if (d == 180) grid.setDirection (d - 90, c); } And if (key == keyive [2]) {if (d == 90) grid.setDirection (d-90, c); Else if (d == 270) grid.setDirection (d + 90, c); } And if (key == main event [3]) {if (d == 90) grid.set direct (d + 90, c); Else if (d == 270) grid.setDirection (d-90, c); } CanTurn [i] = false; }}}  

This is where they are created:

  int [] a = {KeyEvent.VK_LEFT, key event VK_RIHT, KEVENT VK_UP, key event .VK_DOWN}; Int [] B = {KeyEvent.VK_A, Key Event. VK_D, KeyEvent.VK_W, KeyEvent.VK_S}; This.addKeyListener (new playercomplier (a, Color.blue, 0)); This.addKeyListener (New PlayerKeyPressListener (B, Color.red, 1));  

Is there a way for two players to make it more sensitive?


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -