By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

bug cant fix

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




Take a look at this image(error02.gif). This is how i want the bullets to look like. shoot red lines.



Now take a look at this image(error01.gif). 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.


# **main.java** #
Expand|Select|Wrap|Line Numbers
  1.              EnemyBoss enemyBossObject;
  2.              ArrayList<EnemyBoss> enemyBossStore = new ArrayList<EnemyBoss>();
  3.  
  4.              EBBullet eBBulletObject;
  5.              ArrayList<EBBullet> eBossBulletStore = new ArrayList<EBBullet>();
  6.         ...
  7.         public void actionPerformed(ActionEvent e)//main game loop
  8.          {
  9.               ....
  10.                  levelsObject.nextLevel(enemyBossObject, enemyBossStore);   //create emeny boss in this class
  11.               ...
  12.  
  13.               //user methods on Enemy Boss. so it can move and shoot
  14.          for(int i = 0; i < enemyBossStore.size(); i++){
  15.          enemyBossObject = (EnemyBoss)enemyBossStore.get(i);
  16.          enemyBossObject.enemyBossMove();
  17.          enemyBossObject.enemyBossShootBullet(eBBulletObject, eBossBulletStore, topMenuObject);
  18.          }
  19.  
  20.          //create Enemy Boss bullets
  21.          for(int i = 0; i < eBossBulletStore.size(); i++){
  22.          eBBulletObject = (EBBullet)eBossBulletStore.get(i);
  23.          if(!eBBulletObject.getDead()){
  24.          eBBulletObject.eBBulletMove();
  25.          eBBulletObject.eBBulletWCollision();
  26.          }
  27.          else
  28.          eBossBulletStore.remove(i);  
  29.          }
  30.             }
  31.             ...
  32.     public void paintComponent(Graphics g)
  33.      {
  34.             ...
  35.                 //create Enemy Boss on level 4
  36.      if(topMenuObject.getLevel() == 4){ //test to see if its lvl 4
  37.       enemyBossObject = (EnemyBoss)enemyBossStore.get(0);   //paint enemy boss 
  38.      enemyBossObject.paint(g);
  39.  
  40.      //paint Enemy Boss Bullet
  41.      for(int i = 0; i < eBossBulletStore.size(); i++){
  42.      eBBulletObject = (EBBullet)eBossBulletStore.get(i);
  43.      eBBulletObject.paint(g);
  44.      }
  45.  
  46.      }
  47.             ...
  48.             }




# EnemyBoss.java - create enemy boss class- #




Expand|Select|Wrap|Line Numbers
  1.     public class EnemyBoss 
  2.     {
  3.      private double x;
  4.      private double y;
  5.      private double dx = 2;
  6.      private double dy = 1;
  7.  
  8.      private int width = 100;
  9.      private int height = 100;
  10.  
  11.      private int counter = 50;
  12.      private boolean shooting = false;
  13.      private boolean hit = false;
  14.      private boolean dead = false;
  15.  
  16.      private static ImageIcon enemyBossImage = new ImageIcon("image/enemyBoss.gif");
  17.  
  18.  
  19.      public EnemyBoss(double ix, double iy)
  20.      {
  21.      this.x = ix;
  22.      this.y = iy;
  23.      }
  24.  
  25.      /*** Enemy move ***/
  26.      public void enemyBossMove()
  27.      {
  28.      if(this.x < Main.WINDOW_WIDTH-120)  //stop the enemy boss
  29.      {
  30.      this.x = Main.WINDOW_WIDTH-121;
  31.      this.y += this.dy;            //bullet error here
  32.      }
  33.      else
  34.      {
  35.      this.x -= this.dx;
  36.      }
  37.      }/*** end of enemy_move ***/
  38.  
  39.  
  40.  
  41.  
  42.  
  43.      /*** enemy Boss Shoot Bullet METHOD ***/
  44.      public void enemyBossShootBullet(EBBullet eBBulletClassTemp, ArrayList<EBBullet> eBBulletStoreTemp, topMenu tm)
  45.      {
  46.      this.counter--;
  47.      if(this.counter <= 0 && !this.shooting)
  48.      {
  49.      eBBulletClassTemp = new EBBullet(this.x, this.y);  //create enemy bullet
  50.      eBBulletStoreTemp.add(eBBulletClassTemp);  //store in arraylist
  51.  
  52.      this.shooting = true;
  53.      }
  54.  
  55.      if(this.counter != 0)
  56.      {
  57.      this.shooting= false;
  58.      }
  59.      }/*** END OF enemyBossShootBullet METHOD ***/
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.      /*** paint method ***/
  67.      public void paint(Graphics g) 
  68.      {
  69.      g.drawImage(EnemyBoss.getEnemyBossImage(), (int)x, (int)y, width, height, null);
  70.  
  71.      g.setColor(Color.white);
  72.      g.drawRect((int)x, (int)y, width, height); 
  73.      }
  74.     }





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

Expand|Select|Wrap|Line Numbers
  1.     public class EBBullet {
  2.  
  3.      private double x;
  4.      private double y;
  5.  
  6.      private double dx = 1;
  7.      private double dy;
  8.      private int width = 10;
  9.      private int height = 1;
  10.      private boolean dead = false;
  11.  
  12.  
  13.  
  14.      /*** CONSTRUCTOR METHOD ***/
  15.      public EBBullet(double ix, double iy) {
  16.      this.x = ix;
  17.      this.y = iy;
  18.      }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.      /*** enemy boss bullet move ***/
  26.      public void eBBulletMove()
  27.      {
  28.      this.x -= this.dx;
  29.      }/*** End of eBulletMove Method/
  30.  
  31.  
  32.  
  33.  
  34.      /*** kill bullet collision ***/
  35.      public void eBBulletWCollision()
  36.      {
  37.      if(this.x+this.width < 0)
  38.      {
  39.      this.dead = true;
  40.      }
  41.      }/*** End of ebbulletCollsion ***/
  42.  
  43.  
  44.  
  45.  
  46.  
  47.      /*** paint method ***/
  48.      public void paint(Graphics g) 
  49.      {
  50.      g.setColor(Color.blue);
  51.      g.fillRect((int)x, (int)y, width, height); 
  52.      }
  53.     }


**in level class iam creating the enmey by these two lines**
Expand|Select|Wrap|Line Numbers
  1.      EnemyBoss enemyBossObject = new EnemyBoss(600, 100);
  2. eBossBulletStore.add(enemyBossObject);
Apr 21 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Can't see your images. Try describing what is happening and what you want to happen instead.
Apr 22 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.