sorry
World
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Log1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Log1 extends Log
{
/**
* Act - do whatever the Log1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (isAtEdge())
{
getWorld().removeObject(this);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Log2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Log2 extends Log
{
/**
* Act - do whatever the Log2 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (isAtEdge())
{
getWorld().removeObject(this);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Log3 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Log3 extends Log
{
/**
* Act - do whatever the Log3 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(4);
if (isAtEdge())
{
getWorld().removeObject(this);
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
// int getX() x = Car3X;
int fastcarTimer = 100;
int slowcarTimer = 100;
int logSpawner = 100;
Lives life1 = new Lives();
Lives life2 = new Lives();
Lives life3 = new Lives();
Frog frog = new Frog();
Log1 log1 = new Log1();
Log2 log2 = new Log2();
Log3 log3 = new Log3();
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 900, 1);
addObject(new Finish(), 305, 32); // adding the finish lilypad
addObject(new Finish(), 515, 32); // adding the finish lilypad
addObject(new Finish(), 713, 32); // adding the finish lilypad
addObject(new Finish(), 905, 32); // adding the finish lilypad
addObject(new Finish(), 95, 32); // adding the finish lilypad
addObject(new Car1(), 10, 630);
addObject(new Car1(), 500, 630);
addObject(new Car1(), 900, 630);
addObject(new Car1(), 300, 630);
addObject(new Car3(), 995, 537);
addObject(new Car3(), 750, 537);
addObject(new Car3(), 395, 537);
addObject(new Car3(), 195, 537);
addObject(new Car3(), 95, 537);
addObject(new Car2(), 300, 736);
addObject(new Car2(), 994, 736);
addObject(new Car2(), 800, 736);
showText("Lives : " , 40, 880);
addObject(new Log1(), 183, 366);
addObject(new Log2(), 537, 366);
addObject(new Log2(), 846, 366);
addObject(new Log3(), 107, 282);
addObject(new Log1(), 408, 282);
addObject(new Log2(), 778, 282);
addObject(new Log3(), 214, 204);
addObject(new Log2(), 475, 204);
addObject(new Log1(), 811, 204);
addObject(new Log3(), 106, 136);
addObject(new Log2(), 395, 136);
addObject(new Log1(), 774, 136);
addObject(new Boundary(), 500, 243);
// Greenfoot.playSound("Commodore64Music(Frogger).mp3");
}
public void act()
{
// if (Car3X == 0)
// {
// }
randomslowCarSpawner();
randomfastCarSpawner();
createLives();
logSpawner();
start();
}
public void slowCarSpawn()
{
}
public void fastCarSpawn()
{
}
public void createLives()
{
if(frog.getLives() == 3)
{
addObject(life1, 90, 880);
addObject(life2, 120, 880);
addObject(life3, 150, 880);
}else if(frog.getLives() == 2)
{
addObject(life1, 90, 880);
addObject(life2, 120, 880);
}else if(frog.getLives() == 1)
{
addObject(life1, 90, 880);
}
// public void removeAtWorldEdge()
// {
// if (isAtEdge(Car3()))
// {
// removeObject(Car3());
// spawnTimer();
// }
// }
// public void spawnTimer()
// {
// spawnTimer++;
// if (spawnTimer == 0)
// {
// addObject(new Car3(), 36, 36);
// }
// }
}
public void randomfastCarSpawner()
{
fastcarTimer++;
if(Greenfoot.getRandomNumber(40)<50&&fastcarTimer == 100)
{
addObject(new Car1(),10, 630);
}
if(Greenfoot.getRandomNumber(30)<40&&fastcarTimer == 100)
{
addObject(new Car3(),995, 537);
}
if(fastcarTimer == 101)
{
fastcarTimer = 0;
}
}
public void randomslowCarSpawner()
{
slowcarTimer++;
if(Greenfoot.getRandomNumber(40)<60&&slowcarTimer == 100)
{
addObject(new Car2(),995, 736);
}
if(slowcarTimer == 101)
{
slowcarTimer = 0;
}
}
public void logSpawner()
{
logSpawner++;
if(Greenfoot.getRandomNumber(100)<80&&logSpawner == 100)
{
addObject(new Log1(), 30, 366);
}
if(Greenfoot.getRandomNumber(100)<80&&logSpawner == 100)
{
addObject(new Log2(), 30, 282);
}
if(Greenfoot.getRandomNumber(100)<80&&logSpawner == 100)
{
addObject(new Log3(), 30, 204);
}
if(Greenfoot.getRandomNumber(100)<80&&logSpawner == 100)
{
addObject(new Log2(), 30, 136);
}
if(logSpawner == 101)
{
logSpawner = 0;
}
}
public void addedToWorld()
{
}
public void reset()
{
if(frog.getLives() == 0)
{
Greenfoot.stop();
}
else if(frog.getLives() == 2){
removeObject(life1);
}else{
removeObject(life2);
}
removeObject(frog);
addObject(frog, 500, 850);
}
public void start()
{
addObject(frog, 500, 850);
}
}
