[Java for Android App Development] dillenge:
I am trying to make a top down two player shooter and am currently trying to implement a system for the character to shoot his gun multiple times, but currently overtime he changes direction, the bullets change direction. I know why this occurs I just have no idea how to get around this issue. I need the bullets in the iterator to move independently of the next bullet. I am also using LibGdx to accomplish thins in which the render method is called every frame

<

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;

import com.badlogic.gdx.Gdx;

import com.badlogic.gdx.Input;

import com.badlogic.gdx.graphics.GL20;

import com.badlogic.gdx.graphics.Texture;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import com.badlogic.gdx.graphics.g2d.TextureRegion;

import com.badlogic.gdx.math.MathUtils;

import com.badlogic.gdx.math.Rectangle;

import com.badlogic.gdx.utils.Array;

import com.badlogic.gdx.utils.TimeUtils;

import java.util.Iterator;

public class MyGdxGame extends ApplicationAdapter {

SpriteBatch batch;

Texture bluePlayerTexture, redPlayerTexture,bulletTexture;

Rectangle bluePlayer,redPlayer;

TextureRegion[] regions = new TextureRegion[2];

TextureRegion[] bulletRegions = new TextureRegion[1];

private int blueRotation = 0,redRotation = 180,bulletSpeed = 1;

private float xRedBulletSpeed, yRedBulletSpeed;

private Array redBullets;

private long lastShotTime;

[MENTION=439709]override[/MENTION]

public void create () {

batch = new SpriteBatch();

bluePlayerTexture = new Texture("blue.png");

redPlayerTexture = new Texture("red.png");

bulletTexture = new Texture("bullet.png");

regions[0] = new TextureRegion(bluePlayerTexture, 0f,0f,1f,1f);

regions[1] = new TextureRegion(redPlayerTexture, 0f,0f,1f,1f);

bulletRegions[0] = new TextureRegion(bulletTexture, 0f,0f,1f,1f);

createRectangles();

redBullets = new Array<Rectangle>();

spawnRedBullet();

}

[MENTION=439709]override[/MENTION]

public void render () {

Gdx.gl.glClearColor(1, 1, 1, 1);

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

setBulletRedVelocity();

batch.begin();

redPlayerInput(batch);

bluePlayerInput(batch);

for(Rectangle redBullet: redBullets) {

batch.draw(bulletRegions[0], redBullet.x, redBullet.y, redBullet.width / 2, redBullet.height / 2, redBullet.width, redBullet.height, 1, 1, redRotation);

}

batch.draw(regions[0], bluePlayer.x, bluePlayer.y, bluePlayer.width / 2, bluePlayer.height / 2, bluePlayer.width, bluePlayer.height, 1, 1, blueRotation);

batch.draw(regions[1], redPlayer.x, redPlayer.y, redPlayer.width / 2, redPlayer.height / 2, redPlayer.width, redPlayer.height, 1, 1, redRotation);

batch.end();

Iterator<Rectangle> iter = redBullets.iterator();

while(iter.hasNext()) {

Rectangle redBullet = iter.next();

if(redRotation == 90) {

redBullet.y += 200 * Gdx.graphics.getDeltaTime();

}

if(redRotation == 180) {

redBullet.x -= 200 * Gdx.graphics.getDeltaTime();

}

if(redRotation == 0){

redBullet.x += 200 * Gdx.graphics.getDeltaTime();

}

if(redRotation == 270){

redBullet.y -= 200 * Gdx.graphics.getDeltaTime();

}

}

}

private void spawnRedBullet() {

Rectangle redBullet = new Rectangle();

redBullet.x = redPlayer.x;

redBullet.y = redPlayer.y;

redBullet.width = 20;

redBullet.height = 12;

redBullets.add(redBullet);

lastShotTime = TimeUtils.nanoTime();

}

public void createRectangles(){

bluePlayer = new Rectangle();

bluePlayer.width = 64;

bluePlayer.height = 64;

bluePlayer.x = Gdx.graphics.getWidth()/4-bluePlayer.width/2;

bluePlayer.y = Gdx.graphics.getHeight()/2-bluePlayer.width/2;

redPlayer = new Rectangle();

redPlayer.width = 64;

redPlayer.height = 64;

redPlayer.x = (Gdx.graphics.getWidth()/4)*3-redPlayer.width/2;

redPlayer.y = Gdx.graphics.getHeight()/2-redPlayer.width/2;

}

public void redPlayerInput(SpriteBatch batch){

//if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {

//redRotation+=2;

//}

//if(Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)){

// redRotation-=2;

//}

if(Gdx.input.isKeyPressed(Input.Keys.W)){

redRotation = 90;

redPlayer.y+=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.S)){

redRotation = 270;

redPlayer.y-=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.A)){

redRotation = 180;

redPlayer.x-=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.D)){

redRotation = 0;

redPlayer.x+=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.E)){

if(TimeUtils.nanoTime() - lastShotTime > 500000000) spawnRedBullet();

}

}

public void bluePlayerInput(SpriteBatch batch){

//if(Gdx.input.isKeyPressed(Input.Keys.SHIFT_RIGHT)) {

// blueRotation-=2;

//}

//if(Gdx.input.isKeyPressed(Input.Keys.ENTER)){

// blueRotation+=2;

//}

if(Gdx.input.isKeyPressed(Input.Keys.P)){

bluePlayer.y+=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.SEMICOLON)){

bluePlayer.y-=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.L)){

bluePlayer.x-=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.APOSTROPHE)){

bluePlayer.x+=2;

}

if(Gdx.input.isKeyPressed(Input.Keys.O)){

//fire gun

}

}

public void setBulletRedVelocity(){

xRedBulletSpeed = (float) (Math.cos(redRotation)*bulletSpeed);

yRedBulletSpeed = (float) (Math.sin(redRotation)*bulletSpeed);

}

>