java - Collision detection bug -
i've tried expand little on enemy spawning system using factory design pattern.
so have: enemy (abstract): enemytyp ea, b, c, d... etc., each of extend enemy.
i have this: (works)
public void spawnenemy(int type, int amount) { enemy theenemy = null; (int i=1; i<amount+1; i++ ) { theenemy = enemyfactory.makeenemy(type, 0-i*40, 400); aliens.add(theenemy); health.add(2); system.out.println("attack message recieved "+i); } repaint(); }
but cannot seem collision detection work.
public void checkcollisions() { rectangle r3 = player.getbounds(); arraylist ms = player.getmissiles(); (int = 0; < ms.size(); i++) { missile m = (missile) ms.get(i); rectangle r1 = m.getbounds(); (int j = 0; j<aliens.size(); j++) { enemy = (enemy) aliens.get(j); rectangle r2 = a.getbounds(); if (r1.intersects(r2)) { m.setvisible(false); a.sethealth(-1); if(a.gethealth()==0){ a.setvisible(false); } }} } }
i believe it's because turning enemy (abstract) , why getting no collision.. when take item out of arraylist how can take out exact enemytype put in in spawnenemy()
method? use theenemy
variable , combination of instanceof
? extremely confused.
Comments
Post a Comment