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!
if (Greenfoot.mouseClicked(this))
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();
}
}public void ouchIfHit()
{
greenfoot.MouseInfo mouse = Greenfoot.getMouseInfo();
if(Greenfoot.mouseClicked(this))
{
setImage("ouch.png");
}
}