i have a problem.
In one of my world there are 2 of the following actors.
In line 59 a new shotRock2 should be generated
This shotRock2 actor shold turn in the same direction the boctork, that generated the rock was facing at the moment of the generation(line 59)
how could i do that.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class boctorok here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class boctorok extends Actor
{
public static int direction;
public int counter;
/**
* Act - do whatever the boctorok wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
bewegen();
}
public void bewegen()
{
if(getX() <58)
{
setLocation(getX()+3,getY());
}
if(getX() > 441)
{
setLocation(getX() - 3,getY());
}
if(getY() <230)
{
setLocation(getX(),getY()+3);
}
if(getY() > 446)
{
setLocation(getX() ,getY() - 3);
}
if(counter == 0)
{
direction = Greenfoot.getRandomNumber(4);
}
setRotation(direction * 90);
if (counter < 50)
{
move(1);
}
counter = (counter + 1)%75;
if(counter<75||counter>50)
{
if(Greenfoot.getRandomNumber(100)<5)
{
turn(90);
}
else
if(Greenfoot.getRandomNumber(100)<5)
{
getWorld().addObject(new shotRock2(),getX(),getY());
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class shotRock2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class shotRock2 extends Actor
{
public static int direction;
/**
* Act - do whatever the shotRock2 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(1);
}
public shotRock2()
{
}
}
