yes doesn't work
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bom here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bom extends Actor
{
private GreenfootImage image1;
private GreenfootImage image2;
public Bom(){
image1 = new GreenfootImage("blue.png");
image2 =new GreenfootImage("red.png");
setImage(image1);
}
public void switchImage(){
if (getImage() == image1){
setImage(image2);
}
else{
setImage(image1);
}
}
/**
* Act - do whatever the Bom wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//turnAtEdge();
unknownMove();
hitCar();
switchImage();
checkForWall();
}
/*public void turnAtEdge(){
if (isAtEdge()){
turn(17);
}
}*/
public void unknownMove(){
if(Greenfoot.getRandomNumber(100)>60){
turn(+Greenfoot.getRandomNumber(90) -45);
move(4);
checkForWall();
}
}
public void hitCar(){
if(isTouching(car.class)){
World myWorld = getWorld();
GameOver over =new GameOver();
myWorld.addObject(over,myWorld.getWidth()/2,myWorld.getHeight()/2);
Greenfoot.stop();
}
}
public void checkForWall(){
if(isTouching(wall1.class)){
move(-4);
}
}
}
public void act()
{
int x0 = getX(); // initial x-coordinate
int y0 = getY(); // initial y-coordinate
.... /** set a new location or move */
if (/** not a good location */) setLocation(x0, y0);
}
// or
public void act()
{
int ySpeed = 1; // change in y-coordinate
... /** setLocation(getX(), getY()+ySpeed); */
if (/** not a good location */) setLocation(getX(), getY()-ySpeed);
}public class Ant extends Actor
{
/**
* Act - do whatever the Ant wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(2);
int x0 = getX(); // initial x-coordinate
int y0 = getY(); // initial y-coordinate
/** set a new location or move */
if (isTouching(Ciricle.class)){
setLocation(x0, y0);public void act()
{
move(2);
if (isTouching(Ciricle.class)) move(-2);
}