Actually the question is to make a bullet fly in two directions in width relative to the player himself. For example, if a player shoots to the right, the bullet flies to the right; if to the left, it flies to the left ... but I don’t write the condition itself correctly! it turns out that he shoots everything correctly, but if I turn the player in the other direction and shoot, then those bullets that were flying in the other side turn and fly in the direction the player is shooting at the moment and vice versa the same thing happens! There is such a code ...
Bullet Bullet Class:
public class Bullet { private Rectangle rect; private float velocity; public Bullet(Rectangle rect, float velocity) { this.rect = rect; this.velocity = velocity; } public void updateRight() { rect.x += velocity; } public void updateLeft() { rect.x -= velocity; } public Rectangle getRect() { return rect; } public float getVelocity() { return velocity; } } Player class where I try to write a condition (this code is in the render method):
if (arrayBullet.size != 0) { for (num = 0; num < arrayBullet.size; num++) { if (isShot) { arrayBullet.get(num).updateRight(); } if (!isShot) { arrayBullet.get(num).updateLeft(); } And the actual shot itself is played in the method when the button is pressed:
byte i = 0; if(facesRight){ isShot=true; } else { isShot=false; } arrayBullet.add(new Bullet(new Rectangle(position.x, position.y + 0.3f, 0.7f, 0.7f), 0.3f)); All this is done using the ArrayList<Bullet> collection ArrayList<Bullet>
isFire, then the unfolding bullets are not your main problem :). - Igor