While trying to create a simple game where a keyboard is tampered with a keyboard key, I am a little rather upset problem. I would like to work on it when the opposite direction key is pressed, the character will be closed; In this situation, the character can move the other two directions when stopped.
It works by placing it completely left and right; The player can be moved to UP or Down if UP and Down are organized, however, the player will not be moving forward, nor will Java accept that the left or right key is pressed.
import java.util.ArrayList; Import java.util.Random; Import org.lwjgl *; Import org.lwjgl.input.Keyboard; Import org.lwjgl.opengl. *; Import static org.lwjgl.opengl.GL11. *; Public Class Main {Private Man P; Private Arrestist & lt; Integer & gt; Remove keys, keys up; Public key (try {try.setDisplayMode (new display mode (640, 480)); Display.setTitle ("LWJGLHelloWorld"); Display.create (); } Hold (LWGLoxception E) {e.printStackTrace (); } P = new man (0, 0); Keys empty = new arseauchi & lt; & Gt; (); Keys up = new ArrayList & lt; & Gt; (); GlMatrixMode (GL_PROJECTION); GlLoadIdentity (); Glotho (0, 640, 480, 0, 1, -1); GlMatrixMode (GL_MODELVIEW); While (! Display.isCloseRequested ()) {glClear (GL_COLOR_BUFFER_BIT); CheckKeys (); P.draw (); Display.update (); Display.sync (60); } Display.destroy (); } Check Public Zero () {ArrayList & lt; Integer & gt; Keys = new arreelist & lt; & Gt; (); Keys.add (Keyboard.KEY_A); Keys.add (Keyboard.KEY_D); Keys.add (Keyboard.KEY_W); Keys.add (Keyboard.KEY_S); (Int key: key) {if (Keyboard.isKeyDown (key)) KeyDown.add (key); Else keysUp.add (key); } KeyDown Remove all keys (keys); Keys up = new ArrayList & lt; & Gt; (); Int Speed = 4; Int dx = 0; Int dy = 0; If the keys are down (keys.get (2)) {System.out.println ("keyUP"); DI - = speed; } If (keys download cantens (keys.get (3)) {System.out.println ("keyDOWN"); DI + = speed; } If (keys down canteen (keys.get (0)) {System.out.println ("keyLEFT"); DX - = speed; } If (keysDownConnecten (keys (1))} {System.out.println ("keyRIGHT"); DX + = Speed; } // If (keys Down.contains (keys.get (0)) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; // if (keys are down. Contains (keys.get (2)) & amp; amp; amp; and; right contains (keys.get (3))) dy = 0; P.update (dx, dy); } Public static zero main (string [] args) {new main (); } Class man {public int x, y, w, h; Public name CR, CG, CB; Public man (int x, int y) {this.x = x; this. Y = y; W = 50; H = 50; Random rand = new random (); CR = RAND NXFlot (); Cg = rand.nextFloat (); CB = rand.nextFloat (); } Public Zero Draw () {glColor3f (CR, CG, CB); GlRecti (x, y, x + w, y + h); } Public Zero update (int dx, int die) {x + = dx; Y + = D; }}} This is the code with which I am working. Apart from this, I am not sure how to compile an executable jar which is using the LWGG library besides slot-use.
EDIT: I forgot to say that with current set-up: ASDW, problems in it I also saw these issues with JKLI and went to the left hand side. If you change it to a key in a row (ex: ASDF) it works as expected.
Then running in the hardware limit of your keyboard, which is described in the answer.
If possible, try to use any other keyboard, ps / 2 because they allow.
Comments
Post a Comment