multiple shots

hi, i’m new to game programming in java, and i made game like space invader before, but now, i’m trying to remake game of Raiden(which is more difficult) and encountered problems like how to do multiple shots.

mainPanel or Board class:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;


public class mainPanel extends JPanel implements Runnable, KeyListener {
   
   public final int NO_MOVE = 0;
   public final int LEFT = 1;
   public final int RIGHT = 2;
   public final int UP = 3;
   public final int DOWN = 4;
   public final int SPEED = 3;
   
   private int[] keys = new int[5];
   
   ImageIcon i = new ImageIcon(getClass().getResource("res/map1.png"));
   Image BG = i.getImage();
   
   ImageIcon p = new ImageIcon(getClass().getResource("res/plane1.gif"));
   Image player = p.getImage();
   
   
   background map = new background(0, 2400-640);
   plane p1;
   
   boolean ingame = true;
   
   public mainPanel(){
      
      p1 = new plane(225, 600);
      
      for(int x = 0;x<5;x++)
         keys[x] = 0; 
      
      setFocusable(true);
      addKeyListener(this);
      
      Thread thread = new Thread(this);
      thread.start();
   }
   
   public void paintComponent(Graphics g){
      super.paintComponent(g);
      map.draw(g, BG);
      p1.draw(g, player);
   }
      
   public void keyUpdate() {
       if(keys[LEFT]>0){
           p1.setDX(p1.getDX()-(1*SPEED));
       }

       if(keys[RIGHT]>0){
          p1.setDX(p1.getDX()+(1*SPEED));
       }

       if(keys[UP]>0){
          p1.setDY(p1.getDY()-(1*SPEED));
       }

       if(keys[DOWN]>0){
          p1.setDY(p1.getDY()+(1*SPEED)); 
       }
   }

   @Override
   public void run() {
      
      while(ingame){
         p1.update();
         keyUpdate();
         map.update();
         repaint();
         try {
            Thread.sleep(20);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
   }

   @Override
   public void keyTyped(KeyEvent arg0) {
      // TODO Auto-generated method stub
      
   }
   
   public void keyPressed(KeyEvent e){
      if (e.getKeyCode() == KeyEvent.VK_LEFT){
         keys[LEFT]++;
      } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         keys[RIGHT]++;
      } else if (e.getKeyCode() == KeyEvent.VK_UP) {
         keys[UP]++;
      } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         keys[DOWN]++;
      }
      if(e.getKeyCode() == KeyEvent.VK_SPACE){
         System.out.println("SPACE");
         p1.shot();
      }
         
   }
   
   public void keyReleased(KeyEvent e){
      if (e.getKeyCode() == KeyEvent.VK_LEFT){
         keys[LEFT]=0;
      } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
         keys[RIGHT]=0;
      } else if (e.getKeyCode() == KeyEvent.VK_UP) {
         keys[UP]=0;
      } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
         keys[DOWN]=0;
      }
      if(e.getKeyCode() == KeyEvent.VK_SPACE){
      }
   }
   
}

plane class

import java.awt.Graphics;
import java.awt.Image;



public class plane {
   
   private final int MAX_SHOT = 20;
   
   private int dX;
   private int dY;
   private int sX=5;
   private int sY=7;
   private int count=-1;
   bullet shot1= new bullet();
   bullet shot2[];
   
   private boolean isAlive = true;
   
   public plane(int x, int y){
      dX = x;
      dY = y;
      isAlive = true;
      
      shot2 = new bullet[MAX_SHOT];
      for(int i=0; i<MAX_SHOT;i++)
         shot2[i] = new bullet();
   }
   
   public void setDX(int x){dX = x;}
   public void setDY(int y){dY = y;}
   public void setSX(int x){sX = x;}
   public void setSY(int y){sY = y;}
   public int getDX(){return dX;}
   public int getDY(){return dY;}
   public int getSX(){return sX;}
   public int getSY(){return sY;}
   
   public void setAlive(boolean t){
      isAlive = t;
   }
   public boolean getAlive(){
      return isAlive;
   }
   
   public void setShot(){
      for(int j=0;j<MAX_SHOT;j++){
         if(shot2[j].getDY() < 0){
            shot2[j].setShot(false);
         }
      }
      for(int i=0;i<MAX_SHOT;i++){
         if(shot2[i].isShot() == false){
            shot2[i].setDX(dX+20);
            shot2[i].setDY(dY+20);
         }
      }
   }
   
   public void shot(){
      count++;
   }
   
   public void update(){
      
      if(count > MAX_SHOT)
         count=-1;
      
      if(count>=0 && count <MAX_SHOT){
         if(shot2[count].isShot() == false)
            shot2[count].setShot(true);
      }
      for(int i = 0; i<MAX_SHOT;i++)
         shot2[i].update();
      setShot();
   }
   
   public void draw(Graphics g, Image img){
      if(isAlive){
         g.drawImage(img, dX, dY, dX+40, dY+40, sX, sY, sX+50, sY+42, null);
         for(int i=0; i<MAX_SHOT;i++)
            shot2[i].draw(g);
      }
   }
   

}

bullet class

import java.awt.Color;
import java.awt.Graphics;


public class bullet {
   
   private int dX;
   private int dY;
   private int sX;
   private int sY;
   
   private boolean isShot = false;
   public boolean isShot() {return isShot;}
   public void setShot(boolean isShot) {this.isShot = isShot;}

   private int speed=4;
   public void setSpeed(int s){speed = s;}
   
   public void setDX(int x){dX = x;}
   public void setDY(int y){dY = y;}
   public void setSX(int x){sX = x;}
   public void setSY(int y){sY = y;}
   public int getDX(){return dX;}
   public int getDY(){return dY;}
   public int getSX(){return sX;}
   public int getSY(){return sY;}
   
   public void update(){
      if(isShot == true)
         dY-=speed;
   }
   
   public void draw(Graphics g){
      if(isShot == true)
         g.setColor(Color.WHITE);
         g.fillRect(dX, dY, 2, 10);
   }

}

What do you mean multiple shots like firing multiple bullets? what is the issue when firing is it that the x and y reset?

yeah, multiple bullets, the issue is my bullet is staggering and in the plane class, since counter always >= 0, the bullet always loop once

EDIT: Sorry I didn’t see all your code there before writing this. I was reading other posts as well.
But you can still use some logic from this code.
Create a List of bullets. Easy to check if you have bullets to update and add or remove bullets.
Also you should pass x, y, direction, etc in the bullet constructor and let bullet class do all the calculations for you. Just update bullet and draw in your main class.
Get x and y to check if you hit some enemy or wall or bullet is off screen to remove them.
That said, I hope this can help:

Create a bullet class and call it bullet.java.

bullet.java:

public class Bullet {
	// add your fields here. bullet position, bullet speed, bullet direction, etc
	int x = 0;
	int y = 0;
	// ...
	
	// constructor
	public Bullet(double angle, int x, int y, int direction_x, int direction_y) {  // every time you create a new bullet, give this fields: angle, real x, real y, direction
		this.x = x;
		this.y = y;  // save all your fields here. x, y, direction, etc.
		// ...
	}
	
	// functions go retrieve position here. to check if you hit something in your game loop.
	public int getx() { return x; }
	public int gety() { return y; }
	
	public void update() {   // call this function on your main loop. this will update bullet position

		// calculate direction here. use speed, angle, etc...

		x += direction_x;  // calculate new position
		y += direction_y;
	}
	public void draw(Graphics2D g) {   // call this on your game loop, after you draw all stuff (background, player, etc)
		// draw your bullet here. note I call grapics2d. I don't know how you draw your stuff. use graphics or whatever.
	}
}

Every time you shoot just create new bullet.

your game.java:

private static List<Bullet> bullets = new ArrayList<Bullet>();   // call this before your loop.

// inside game loop:

// add bullet:
bullets.add(new Bullet(angle, x, y, direction_x, direction_y));

// update bullets
for (int i = 0; i < bullets.size(); i++) {   // check if you have bullets to update
	bullets.get(i).update();


	// use bullets.get(i).getx and gety to calculate if bullet hit something and you need to remove bullet:
	if (you_need_to_remove_your_bullet) {
		bullets.remove(i);
		i--;
	}

}


// draw bullets
for (int i = 0; i < bullets.size(); i++) {
	bullets.get(i).draw(g);
}

What do you mean by staggering? That honestly makes no sense. Do you mean graphically? What specifically are you having issues with? I don’t understand why throwing a wall of code at someone will get you results. Ask specific questions and explain.

@Icass I would recommend checking if the bullet needs to removed first before you update it so other bullets can’t collide with the bullet that needs removing. Plus, going through an update method is more expensive than just doing a Boolean test to see if the bullet needs removing or not. Just a suggestion!