Can someone help me to make a method where all bears turn to face a pig? in case you want to know here is my code
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class bear here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class bear extends Actor
{
/**
* Act - do whatever the bear wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//no code for bear... yet.
}
}
//and for the tree(thats the player, yes I know it is weird)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class tree here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class tree extends Actor
{
/**
* Act - do whatever the tree wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int PigsAdded = 0;
public void act()
{
if(Greenfoot.mouseClicked(this)) {
World world;
world = getWorld();
world.addObject (new bear(), getX(), getY());
PigPlaces();
}
if(Greenfoot.isKeyDown("space"))
move(3);
if(Greenfoot.isKeyDown("right"))
turn(5);
if(Greenfoot.isKeyDown("left"))
turn(-5);
}
public void PigPlaces()
{
if( (PigsAdded ==0)||(PigsAdded==1))
{
World world;
world = getWorld();
world.addObject(new poorpig(),400,400);
PigsAdded++;
}
if(( PigsAdded ==2)||(PigsAdded==3))
{
World world;
world = getWorld();
world.addObject(new poorpig(),200,200);
PigsAdded++;
}
}
}

