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

2019/4/26

Group AI.

Notted Notted

2019/4/26

#
We basically want individual entities or actors, to act as a group. This is more or less similar to how aliens act in Space Invaders; they act as a team but are not one big actor. How are we going to do this? One of the more obvious solutions is to make a graphic with each individual alien in a huge row, then change the image whenever the aliens get hit/die. But we want individual aliens, not one big actor.
danpost danpost

2019/4/27

#
Maybe taking a look at my Space Invaders Movement Demo scenario might help.
Notted Notted

2019/4/29

#
Getting errors when trying to implement the rows from your code:
public aRow() 
    {
        setImage(new GreenfootImage(800, 1));
    }   
    
    public boolean moveRow(int dir)
    {
        boolean changeDir = false;
        for (Object obj : getIntersectingObjects(enemyAlien.class))
        {
            enemyAlien invader = (enemyAlien) obj;
            changeDir = invader.aliensMovement(dir) || changeDir;
        }
        return changeDir;
    }
    
    public void dropRow()
    {
        for (Object obj : getIntersectingObjects(enemyAlien.class))
        {
            Actor invader = (enemyAlien) obj;
            invader.setLocation(invader.getX(), invader.getY()+10);
        }
        setLocation(getX(), getY()+10);
    }
It's saying "bad operand types for binary operator"
changeDir = invader.aliensMovement(dir) || changeDir;
danpost danpost

2019/4/29

#
Notted wrote...
It's saying "bad operand types for binary operator"
What code do you have for the aliensMovement method in the enemyAlien class?
Notted Notted

2019/4/30

#
I've just recently added a return type, an int to replace the var for the alien's speed.
public int aliensMovement (int aliensSpeed)
    {
        move(aliensSpeed);
        if (atWorldEdge())
        {
            aliensSpeed = -aliensSpeed;
            int alienY = getY();
            setLocation(getX(), alienY + 5);
            int alienWidth = getWorld().getWidth();
            gotoX = alienWidth/2+(50+Greenfoot.getRandomNumber(alienWidth/2-80))*aliensSpeed/4;
        }
        return aliensSpeed;
    }
danpost danpost

2019/4/30

#
Notted wrote...
I've just recently added a return type, an int to replace the var for the alien's speed. << Code Omitted >>
Well, you cannot use an int value as a boolean value like you try to do in your error line.
Notted Notted

2019/4/30

#
So my return type was the problem?
danpost danpost

2019/4/30

#
Notted wrote...
So my return type was the problem?
The way you are trying to use that return type is the problem. If you are to use it in an if condition, then either the return type needs to be boolean or you must compare the int return value to some other numeric value to produce a boolean value.
Notted Notted

2019/4/30

#
How I'm I going to implement the rows? Much like how you do in your demo?
danpost danpost

2019/4/30

#
Notted wrote...
How I'm I going to implement the rows? Much like how you do in your demo?
I had each invader, when moved, inform its Row object, via a boolean value, whether it reached an edge or not. The row, in turn, informed the world if any invader reach an edge. The world would then change the direction the rows would be told to move in if any invader reached an edge.
Notted Notted

2019/4/30

#
I may want to migrate my project unto your project, as the implementation into mine is getting clunky and awkward.
You need to login to post a reply.