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
- 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- #
Expand|Select|Wrap|Line Numbers
- 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 ----------------------------------------------------------------
-------------------------------------------------
Expand|Select|Wrap|Line Numbers
- 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**
Expand|Select|Wrap|Line Numbers
- EnemyBoss enemyBossObject = new EnemyBoss(600, 100);
- eBossBulletStore.add(enemyBossObject);