i am tring to debug this problem for about a week but had no luck in it.

522461a63915f3683bcd1e3e8f00d81d

Take a look at this image above. This is how i want the bullets to look like. shoot red lines.

da7b3eb64b1486e6fec4b7c680889fe7

Now take a look at this image above. I am tring to make my enemy boss shoot blue bullets. the blue thing you see in image is the bullet. this is the problem it is not shooting the way i want it.

i have two arraylists. 'enemyBossStore' arraylist will online hold one enemy boss. 'eBBulletStore' will hold enemy bullets.

main.java
         EnemyBoss enemyBossObject;
            ArrayList<EnemyBoss> enemyBossStore = new ArrayList<EnemyBoss>();

            EBBullet eBBulletObject;
            ArrayList<EBBullet> eBossBulletStore = new ArrayList<EBBullet>();
    ...
    public void actionPerformed(ActionEvent e)//main game loop
        {
          ....
             levelsObject.nextLevel(enemyBossObject, enemyBossStore);   //create emeny boss in this class
          ...

          //user methods on Enemy Boss. so it can move and shoot
                for(int i = 0; i < enemyBossStore.size(); i++){
                    enemyBossObject = (EnemyBoss)enemyBossStore.get(i);
                    enemyBossObject.enemyBossMove();
                    enemyBossObject.enemyBossShootBullet(eBBulletObject, eBossBulletStore, topMenuObject);
                }

                //create Enemy Boss bullets
                for(int i = 0; i < eBossBulletStore.size(); i++){
                    eBBulletObject = (EBBullet)eBossBulletStore.get(i);
                    if(!eBBulletObject.getDead()){
                        eBBulletObject.eBBulletMove();
                        eBBulletObject.eBBulletWCollision();
                    }
                    else
                        eBossBulletStore.remove(i);  
                }
        }
        ...
public void paintComponent(Graphics g)
        {
        ...
            //create Enemy Boss on level 4
                if(topMenuObject.getLevel() == 4){ //test to see if its lvl 4
                    enemyBossObject = (EnemyBoss)enemyBossStore.get(0);   //paint enemy boss    
                    enemyBossObject.paint(g);

                    //paint Enemy Boss Bullet
                    for(int i = 0; i < eBossBulletStore.size(); i++){
                        eBBulletObject = (EBBullet)eBossBulletStore.get(i);
                        eBBulletObject.paint(g);
                    }

                }
        ...
        }
EnemyBoss.java - create enemy boss class-
public class EnemyBoss 
{
    private double x;
    private double y;
    private double dx = 2;
    private double dy = 1;

    private int width = 100;
    private int height = 100;

    private int counter = 50;
    private boolean shooting = false;
    private boolean hit = false;
    private boolean dead = false;

    private static ImageIcon enemyBossImage = new ImageIcon("image/enemyBoss.gif");


    public EnemyBoss(double ix, double iy)
    {
        this.x = ix;
        this.y = iy;
    }

    /*** Enemy move ***/
    public void enemyBossMove()
    {
        if(this.x < Main.WINDOW_WIDTH-120)  //stop the enemy boss
        {
            this.x = Main.WINDOW_WIDTH-121;
            this.y += this.dy;            //bullet error here
        }
        else
        {
            this.x -= this.dx;
        }
    }/*** end of enemy_move ***/





    /*** enemy Boss Shoot Bullet METHOD ***/
    public void enemyBossShootBullet(EBBullet eBBulletClassTemp, ArrayList<EBBullet> eBBulletStoreTemp, topMenu tm)
    {
        this.counter--;
        if(this.counter <= 0 && !this.shooting)
        {
            eBBulletClassTemp = new EBBullet(this.x, this.y);  //create enemy bullet
            eBBulletStoreTemp.add(eBBulletClassTemp);  //store in arraylist

            this.shooting = true;
        }

        if(this.counter != 0)
        {
            this.shooting= false;
        }
    }/*** END OF enemyBossShootBullet METHOD ***/






    /*** paint method ***/
    public void paint(Graphics g) 
    {
        g.drawImage(EnemyBoss.getEnemyBossImage(), (int)x, (int)y, width, height, null);

        g.setColor(Color.white);
        g.drawRect((int)x, (int)y, width, height); 
    }
}

-----------------------------------------------

EBBullet.java - create enemy bullets class ----------------------------------------------------------------
public class EBBullet {

    private double x;
    private double y;

    private double dx = 1;
    private double dy;
    private int width = 10;
    private int height = 1;
    private boolean dead = false;



    /*** CONSTRUCTOR METHOD ***/
    public EBBullet(double ix, double iy) {
        this.x = ix;
        this.y = iy;
    }






    /*** enemy boss bullet move ***/
    public void eBBulletMove()
    {
        this.x -= this.dx;
    }/*** End of eBulletMove Method/




    /*** kill bullet collision ***/
    public void eBBulletWCollision()
    {
        if(this.x+this.width < 0)
        {
            this.dead = true;
        }
    }/*** End of ebbulletCollsion ***/





    /*** paint method ***/
    public void paint(Graphics g) 
    {
        g.setColor(Color.blue);
        g.fillRect((int)x, (int)y, width, height); 
    }
}
in level class iam creating the enmey by these two lines
     EnemyBoss enemyBossObject = new EnemyBoss(600, 100);
            eBossBulletStore.add(enemyBossObject);

That code looks like every Boss fires a new bullet on every pass through the game loop - that's a lot of bullets. Or is there some other code that determines how often a new bullet is fired?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.