so as asked above how would i fix it here?
public void fire() { if (detectHuman(<the issue is the void here>) == true) { shoot(); } }
public void fire() { if (detectHuman(<the issue is the void here>) == true) { shoot(); } }
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; } } turnTowards(closest.getX(),closest.getY()); } }
public class RobotEnemy extends EnemyCharacters { private GreenfootImage Robot1= new GreenfootImage("RobotEnemyIdle.png"); private GreenfootImage Robot2= new GreenfootImage("RobotEnemy1.png"); private GreenfootImage Robot3= new GreenfootImage("RobotEnemy2.png"); private int animatecounter; public int fireTimer = 0; private boolean fire = false; /** * Act - do whatever the RobotEnemy wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { RobotMovement(); animate(); if (detectHuman()) { shoot(); } detectBillyMetal(); detectBilly(); } private void RobotMovement() { } public void animate() { animatecounter++; if (animatecounter > 5) { animatecounter = 0; if (getImage() == Robot2) { setImage(Robot3); } else { setImage(Robot2); } } } public void fire() { } 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 class EnemyCharacters extends Actor { /** * 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 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; } } turnTowards(closest.getX(),closest.getY()); } } 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; } } turnTowards(closest.getX(),closest.getY()); } } 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; } } turnTowards(closest.getX(),closest.getY()); } } }
if (closest != null) { turnTowards ... shoot(); }