I want to change this code:
if(this.getOneIntersectingObject(AnnoyingPig.class) != null)
instead of intersecting object it will be mouse clicked.
Can anyone help me with this?
Thank you!


1 | if (Greenfoot.mouseClicked( this )) |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | public void actions() { greenfoot.MouseInfo mouse = Greenfoot.getMouseInfo(); if (Greenfoot.mouseClicked( this )) { setLocation( 0 , 0 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 1 , 0 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 2 , 0 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 0 , 1 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 1 , 1 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 2 , 1 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 0 , 2 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 1 , 2 ); checkForPig(); } if (Greenfoot.mouseClicked( this )) { setLocation( 2 , 2 ); checkForPig(); } } /** * Checks to see if a mole is present where the hammer is. * If it is then it is a hit. */ public void checkForPig() { if ( this .getOneIntersectingObject(AnnoyingPig. class ) != null ) { playHit(); } else { playMiss(); } } |
1 2 3 4 5 6 7 8 | public void ouchIfHit() { greenfoot.MouseInfo mouse = Greenfoot.getMouseInfo(); if (Greenfoot.mouseClicked( this )) { setImage( "ouch.png" ); } } |