This site requires JavaScript, please enable it in your browser!
Greenfoot back
Weeb2.exe
Weeb2.exe wrote ...

2020/5/17

how would i fix a void type not allowed here issue

1
2
3
4
5
danpost danpost

2020/5/19

#
Weeb3.exe wrote...
which class?
In RobotEnemy: Remove lines 17 thru 20. In EnemyCharacters: Replace lines 28, 48 and 68 with:
if (closest != null)
{
    turnTowards ...
    shoot();
}
Weeb3.exe Weeb3.exe

2020/5/19

#
danpost wrote...
Weeb3.exe wrote...
which class?
In RobotEnemy: Remove lines 17 thru 20. In EnemyCharacters: Replace lines 28, 48 and 68 with:
if (closest != null)
{
    turnTowards ...
    shoot();
}
ok
Weeb3.exe Weeb3.exe

2020/5/19

#
ok so that doesn't work very well bc it can only shoot once and it shoots only forward not towards the player
danpost danpost

2020/5/19

#
You need to set the rotation of the bullet in the fireTime method.
Weeb3.exe Weeb3.exe

2020/5/19

#
how would i do that?
danpost danpost

2020/5/19

#
I do not see where your boolean fire is turned back to false nor where the value of fireTimer is being controlled.
Weeb3.exe Weeb3.exe

2020/5/19

#
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();
            }
        }   
    }
}
danpost danpost

2020/5/19

#
Weeb3.exe wrote...
how would i do that?
Stop asking how and just do it. How do you think you do it?
Weeb3.exe Weeb3.exe

2020/5/19

#
turn(5)?
Weeb3.exe Weeb3.exe

2020/5/19

#
no wait that doesn't work
danpost danpost

2020/5/19

#
Weeb3.exe wrote...
turn(5)? no wait that doesn't work
What direction do you want the bullet to face?
Weeb3.exe Weeb3.exe

2020/5/19

#
would it be that it shoots in the direction that it detects human if so would it be bullet.turn(5)?
danpost danpost

2020/5/19

#
Weeb3.exe wrote...
would it be that it shoots in the direction that it detects human if so would it be bullet.turn(5)?
What is significant about a 5 degree rotation?
Weeb3.exe Weeb3.exe

2020/5/19

#
danpost wrote...
Weeb3.exe wrote...
turn(5)? no wait that doesn't work
What direction do you want the bullet to face?
towards the player
danpost danpost

2020/5/19

#
Weeb3.exe wrote...
towards the player
How can you acquire that value for the bullet?
There are more replies on the next page.
1
2
3
4
5