Hello, I'm having some trouble making a mouse click trigger an entire action, rather than a single loop of the actions. I'll attach my programming along with a list of what I've tried/am currently trying.
I'm not sure why the boolean value isn't working and isn't triggering the method. I've previously tried using mouseClicked to call a method, but it only moves the characters through one rotation/moves them once and then requires another click to move. Right now when I run the program either nothing happens when I click or the opponents just start to move and clicking does absolutely nothing. I'm quite new to Greenfoot, and I'm not sure what I could be doing wrong. I'd appreciate any help. Thank you!
public class Opponent extends Actor
{
private boolean clicked = false;
/**
* Act - do whatever the Opponent wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
hitWall();
battleRoyale();
{
if(Greenfoot.mouseClicked(null))
{
clicked=true;
}
}
}
public Opponent() //scales the image
{
GreenfootImage myImage = getImage();
int myNewHeight = myImage.getHeight()/3;
int myNewWidth = myImage.getWidth()/3;
myImage.scale(myNewWidth, myNewHeight);
}
public void hitWall()
{
if (isAtEdge())
{
turn(180);
}
}
public void battleRoyale()
{
if (clicked=true)
{
move(5);
if (isTouching(Shephard.class))
{
if (Greenfoot.getRandomNumber(100) > 50)
{
removeTouching(Shephard.class);
}
}
}
}
}
