473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

bug cant fix

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
1 1173
r035198x
13,262 8TB
Can't see your images. Try describing what is happening and what you want to happen instead.
Apr 22 '13 #2

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

Similar topics

3
by: Aaron Brockhurst | last post by:
Hi Can anyone help? I cant get my php script to insert or delete records into a mysql table. I can view them all fine but that's about it. I've checked the user permissions on mysql and...
4
by: gregsands | last post by:
Hi I have read all (ok most) of the posts relating to "Call to undefined function mysql_connect()", read the manual on PHP.net and done eveything thats ive been asked to do but cant get PHP to...
9
by: Dan K. | last post by:
Hi Folks, Problem is, that on one of my controls the DEL key wont work in textboxes. i have different controls of this kind in my app and this is the only one the DEL Key wont do his job....
0
by: Tillmann Neben | last post by:
As the topic already says, i just cant get it working. I am using "ftp-mode" to get the files onto the server instead of using frontpage extension. When I try to debug, VS tells me, that the...
16
by: Mike Fellows | last post by:
when i load my windows form i populate a combobox i use the code below Dim conn As New System.Data.SqlClient.SqlConnection(strConn) Dim sql As String = "AllLenders" Dim da As New...
2
by: g35rider | last post by:
Hi, I have the following code that is giving this error, I cant simplify the code, I was just testing some theory for something we are doing and was getting an issue here. Please someone point out...
3
by: arun.hallan | last post by:
Hi, I'm having problems with authentication. I have a set of users that are allowed to use a webpage. They are in domain A. My goal is to get the username of these users and then check them...
2
by: andrewanderson | last post by:
hi can anyone help me with this prog. cant find the prob why it cant display cout<<"This is the display of your transaction"<<endl; ifstream fobj; //declare input file stream ...
1
by: Nagaraj | last post by:
hi all, I have simple basic c++ program "hello world" which i cant compile on linux system. I have given extension as .C. please tell me how to compile C++ programs on Linux.
6
by: WolfgangS | last post by:
Ok first off, i am a total beginner at this groups stuff and i have no clue how this works. This is probabaly the wrong group for my problem but i will post it anyways. Learning by doing right? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.