So I have an object controllable with the keyboard using the arrow keys and a,d,w.
I’m trying to accomplish translation, rotation, and firing bullets all at the same time.
When I rotate, shoot and translate simultaneously, I can not move right but can move up, left and down.
I’ve included some code snippets on how I’m trying to achieve this.
KEY INPUTS – Inside “Cluster” Object
public void keyPress(int k) {
if (k == KeyEvent.VK_UP) { keyup = true; }
if (k == KeyEvent.VK_DOWN) { keydown = true; }
if (k == KeyEvent.VK_LEFT) { keyleft = true; }
if (k == KeyEvent.VK_RIGHT) { keyright = true; }
if (k == KeyEvent.VK_A) { keya = true; }
if (k == KeyEvent.VK_D) { keyd = true; }
if (k == KeyEvent.VK_W) { keyw = true; }
}
public void keyReleased(int k) {
if (k == KeyEvent.VK_UP) { keyup = false; }
if (k == KeyEvent.VK_DOWN) { keydown = false; }
if (k == KeyEvent.VK_LEFT) { keyleft = false; }
if (k == KeyEvent.VK_RIGHT) { keyright = false; }
if (k == KeyEvent.VK_A) { keya = false; }
if (k == KeyEvent.VK_D) { keyd = false; }
if (k == KeyEvent.VK_W) { keyw = false; }
}
IF BLOCK – Inside “Cluster” Object
if (keyup) { dy = -speed; }
if (keydown) { dy = speed; }
if (keyleft) { dx = -speed; }
if (keyright) { dx = speed; }
if (keyd && !keya) { rotateCW(dt); }
if (!keyd && !keya && angle != 0) { slowdownCW(dt); }
if (keya && !keyd) { rotateCCW(dt); }
if (!keya && !keyd && angle != 0) { slowdownCCW(dt); }
for (int i = 0; i < positions.length; i++) {
positions[i][0] += dx * dt;
positions[i][1] += dy * dt;
}
CODE Outside “Cluster Object”
This is where I’m making calls to all objects like update
// THE BULLETS
bulletmanager.update(dt);
if (cluster.isCreated() && cluster.keyw && bulletmanager.isReadyFire()) {
bulletmanager.fire();
float[][] position = bulletmanager.determinePosition();
float x = position[0][0];
float y = position[0][1];
float[][] velocity = bulletmanager.determineVelocities();
float vx = velocity[0][0];
float vy = velocity[0][1];
Bullets b = new Bullets(x, y, vx, vy);
bullets.add(b);
}
http://www.flashpawcomputers.com/mine/Untitled-1.jpg
nXnzljmiVVA
I am controlling keyw inside an object and referencing this variable from another object as is shown in the third code snippet.
Any ideas on why I am able to rotate, shoot, and move left, up, OR down but NOT right?
I can move right and rotate or can move right and shoot but am not able to rotate, shoot, and move right.
EDIT: Added video for clarification