import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Level2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level2 extends World
{
/**
* Constructor for objects of class Level2.
*
*/
public Level2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Strawberry strawberry = new Strawberry();
addObject(strawberry,511,373);
Strawberry strawberry2 = new Strawberry();
addObject(strawberry2,269,425);
Strawberry strawberry3 = new Strawberry();
addObject(strawberry3,335,244);
Strawberry strawberry4 = new Strawberry();
addObject(strawberry4,716,385);
Strawberry strawberry5 = new Strawberry();
addObject(strawberry5,715,20);
Strawberry strawberry6 = new Strawberry();
addObject(strawberry6,162,170);
Strawberry strawberry7 = new Strawberry();
addObject(strawberry7,98,487);
Turtle turtle = new Turtle();
addObject(turtle,476,467);
Bee bee = new Bee();
addObject(bee,361,335);
Bee bee2 = new Bee();
addObject(bee2,70,76);
Bee bee3 = new Bee();
addObject(bee3,690,170);
Counter counter = new Counter();
addObject(counter,29,36);
counter.setLocation(84,18);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Level2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level2 extends World
{
/**
* Constructor for objects of class Level2.
*
*/
public Level2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Strawberry strawberry = new Strawberry();
addObject(strawberry,511,373);
Strawberry strawberry2 = new Strawberry();
addObject(strawberry2,269,425);
Strawberry strawberry3 = new Strawberry();
addObject(strawberry3,335,244);
Strawberry strawberry4 = new Strawberry();
addObject(strawberry4,716,385);
Strawberry strawberry5 = new Strawberry();
addObject(strawberry5,715,20);
Strawberry strawberry6 = new Strawberry();
addObject(strawberry6,162,170);
Strawberry strawberry7 = new Strawberry();
addObject(strawberry7,98,487);
Turtle turtle = new Turtle();
addObject(turtle,476,467);
Bee bee = new Bee();
addObject(bee,361,335);
Bee bee2 = new Bee();
addObject(bee2,70,76);
Bee bee3 = new Bee();
addObject(bee3,690,170);
Counter counter = new Counter();
addObject(counter,29,36);
counter.setLocation(84,18);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Level2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Level2 extends World
{
/**
* Constructor for objects of class Level2.
*
*/
public Level2()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Strawberry strawberry = new Strawberry();
addObject(strawberry,511,373);
Strawberry strawberry2 = new Strawberry();
addObject(strawberry2,269,425);
Strawberry strawberry3 = new Strawberry();
addObject(strawberry3,335,244);
Strawberry strawberry4 = new Strawberry();
addObject(strawberry4,716,385);
Strawberry strawberry5 = new Strawberry();
addObject(strawberry5,715,20);
Strawberry strawberry6 = new Strawberry();
addObject(strawberry6,162,170);
Strawberry strawberry7 = new Strawberry();
addObject(strawberry7,98,487);
Turtle turtle = new Turtle();
addObject(turtle,476,467);
Bee bee = new Bee();
addObject(bee,361,335);
Bee bee2 = new Bee();
addObject(bee2,70,76);
Bee bee3 = new Bee();
addObject(bee3,690,170);
Counter counter = new Counter();
addObject(counter,29,36);
counter.setLocation(84,18);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class StartScreen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class StartScreen extends World
{
/**
* Constructor for objects of class StartScreen.
*
*/
public StartScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600 , 1);
prepare();
}
public void act()
{
if(Greenfoot.isKeyDown("enter"))
Greenfoot.setWorld(new MyWorld());
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
TitleScreen titleScreen = new TitleScreen();
addObject(titleScreen,377,313);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bee here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bee extends Actor
{
/**
* Act - do whatever the Bee wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(Greenfoot.getRandomNumber(10));
if (isAtEdge())
{
if (Greenfoot.getRandomNumber(100) <100)
{
turn(180);
}
}
if (Greenfoot.getRandomNumber(100) <20)
{
turn(Greenfoot.getRandomNumber(20));
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
int score = 0;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setImage(new GreenfootImage("Score: " + score, 24, Color.GREEN, Color.BLACK));
if (score == 5) Greenfoot.setWorld(new Level2());
}
public void addScore()
{
score++;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Counter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Counter extends Actor
{
int score = 0;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setImage(new GreenfootImage("Score: " + score, 24, Color.GREEN, Color.BLACK));
if (score == 5) Greenfoot.setWorld(new Level2());
}
public void addScore()
{
score++;
}
}
[code]import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class TitleScreen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TitleScreen extends Actor
{
/**
* Act - do whatever the TitleScreen wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Turtle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Turtle extends Actor
{
public Turtle()
{
GreenfootImage image = getImage();
image.scale(50, 50);
setImage(image);
}
/**
* Act - do whatever the Turtle wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
HitEnemy();
if (Greenfoot.isKeyDown ("a"))
{
turn (-3);
}
if (Greenfoot.isKeyDown ("d"))
{
turn (3);
}
if (Greenfoot.isKeyDown ("s"))
{
move (-3);
}
if (Greenfoot.isKeyDown ("w"))
{
move (3);
}
}
public void HitEnemy()
{
if (isTouching (Bee.class))
{
getWorld().addObject (new YouLose(), 400, 300);
getWorld().removeObject (this);
Greenfoot.stop();
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class YouLose here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class YouLose extends Actor
{
/**
* Act - do whatever the YouLose wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public YouLose()
{
GreenfootImage image = getImage();
image.scale(300, 200);
setImage(image);
}
}