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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 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 ); } } } } } |