Weeb3.exe wrote...
which class?if (closest != null)
{
turnTowards ...
shoot();
}if (closest != null)
{
turnTowards ...
shoot();
}if (closest != null)
{
turnTowards ...
shoot();
}public class EnemyCharacters extends Actor
{
public int fireTimer = 0;
private boolean fire = false;
/**
* Act - do whatever the EnemyCharacters wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
public void shoot()
{
if ( fire == false)
{
fireTime();
fire = true;
fireTimer = 25;
}
}
public void fireTime()
{
EnemyBullet bullet = new EnemyBullet();
getWorld().addObject(bullet, getX(), getY());
bullet.move(06);
}
public void detectHuman()
{
int dist = 100;
Actor closest = null;
if(!getObjectsInRange(dist, Betty.class).isEmpty())
{
for (Object obj: getObjectsInRange(dist, Betty.class))
{
Actor guy = (Actor) obj;
int guyDist = (int) Math.hypot(guy.getX() - getX(), guy.getY() - getY());
if (closest == null || guyDist< dist)
{
closest = guy;
dist = guyDist;
}
}
if (closest != null)
{
turnTowards(closest.getX(),closest.getY());
shoot();
}
}
}
public void detectBillyMetal()
{
int dist = 100;
Actor closest = null;
if(!getObjectsInRange(dist, BillyMetal.class).isEmpty())
{
for (Object obj: getObjectsInRange(dist, BillyMetal.class))
{
Actor guy = (Actor) obj;
int guyDist = (int) Math.hypot(guy.getX() - getX(), guy.getY() - getY());
if (closest == null || guyDist< dist)
{
closest = guy;
dist = guyDist;
}
}
if (closest != null)
{
turnTowards(closest.getX(),closest.getY());
shoot();
}
}
}
public void detectBilly()
{
int dist = 100;
Actor closest = null;
if(!getObjectsInRange(dist, Billy.class).isEmpty())
{
for (Object obj: getObjectsInRange(dist, Billy.class))
{
Actor guy = (Actor) obj;
int guyDist = (int) Math.hypot(guy.getX() - getX(), guy.getY() - getY());
if (closest == null || guyDist< dist)
{
closest = guy;
dist = guyDist;
}
}
if (closest != null)
{
turnTowards(closest.getX(),closest.getY());
shoot();
}
}
}
}