2 of the towers i want to work with special attacks (one for slowing down units when they are hit, and the other to do splash damage).
for the splash damage one i figured if i get all the units in a range and damage them then that would work, but it won't let me cast an array, so should i make a loop in there that takes each non empty value of the array and damage it individually, or is there a way to attack them all at once? the way the units spawn now i have the range set to hit 2 of them, and i want it to do damage to them when the attack hits one of them and is removed.
here's the coding i have for the attack:
the commented out part is that original attack that only hits one.
as for the slowing one, since the units that spawn have a different move method then the regular move that you can add an int to, not sure how to slow them down for a few seconds.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | public class splashDamage extends towerAttacks { /** * Act - do whatever the splashDamage wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ //damage 2/4 //att spd 1/.75 sec //aoe radius 2 units/3 units (space wise) int x, y; enemies e; int damage; public splashDamage(enemies E, int Damage) { e = E; damage = Damage; } public void act() { // Add your action code here. if (isNotThere()) { getWorld().removeObject( this ); } else { x = e.getX(); y = e.getY(); moveTo(x, y); isHit(); } } private void moveTo( int x, int y) { double xX = x - getX(); double yY = y - getY(); double angle = Math.atan2(yY, xX)* 180 /Math.PI; setRotation( ( int ) angle); move( 1 ); } public void isHit() { // if(getOneObjectAtOffset(0, 0, enemies.class) != null) // { // //do attack damage // enemies a = (enemies) getOneObjectAtOffset(0, 0, enemies.class); // a.decHealth(damage); // getWorld().removeObject(this); // } if (!getObjectsInRange( 70 , enemies. class ).isEmpty()) { enemies a = (enemies) getObjectsInRange( 70 , enemies. class ); a.decHealth(damage); getWorld().removeObject( this ); } else if (getX() <= 0 || getX() >= getWorld().getWidth() || getY() <= 0 || getY() >= getWorld().getHeight()) { getWorld().removeObject( this ); } } public boolean isNotThere() { if (e.getWorld() == null ) { return true ; } return false ; } } |