I need help doing what the title says! Here's my code for TheWorld, and TheWorld2:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class TheWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TheWorld extends World
{
/**
* Constructor for objects of class TheWorld.
*
*/
public TheWorld()
{
super(600, 480, 1);
prepare();
}
/**
* Prepare the world the start of the game
*/
private void prepare()
{
Counter counter = new Counter();
addObject(counter, 835, 19);
Player player = new Player(counter);
addObject (player, 452, 332);
GoldCoin goldcoin = new GoldCoin();
addObject(goldcoin, 587, 327);
goldcoin.setLocation(570, 326);
GoldCoin goldcoin2 = new GoldCoin();
addObject(goldcoin2, 31, 31);
GoldCoin goldcoin3 = new GoldCoin();
addObject(goldcoin3, 849, 60);
GoldCoin goldcoin4 = new GoldCoin();
addObject(goldcoin4, 846, 644);
GoldCoin goldcoin5 = new GoldCoin();
addObject(goldcoin5, 37, 653);
goldcoin.setLocation(450, 406);
GoldCoin goldcoin6 = new GoldCoin();
addObject(goldcoin6, 448, 250);
GoldCoin goldcoin7 = new GoldCoin();
addObject(goldcoin7, 854, 317);
GoldCoin goldcoin8 = new GoldCoin();
addObject(goldcoin8, 31, 353);
GoldCoin goldcoin9 = new GoldCoin();
addObject(goldcoin9, 449, 36);
GoldCoin goldcoin10 = new GoldCoin();
addObject(goldcoin10, 463, 677);
goldcoin10.setLocation(453, 676);
counter.setLocation(556, 16);
goldcoin9.setLocation(325, 28);
goldcoin6.setLocation(330, 222);
player.setLocation(333, 329);
goldcoin.setLocation(332, 416);
goldcoin10.setLocation(29, 134);
goldcoin8.setLocation(29, 253);
goldcoin5.setLocation(27, 442);
goldcoin8.setLocation(26, 304);
goldcoin10.setLocation(27, 183);
goldcoin9.setLocation(307, 29);
goldcoin3.setLocation(568, 60);
goldcoin7.setLocation(561, 331);
goldcoin4.setLocation(564, 241);
goldcoin7.setLocation(568, 448);
goldcoin6.setLocation(307, 166);
player.setLocation(313, 262);
goldcoin.setLocation(310, 374);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(310, 453);
goldcoin.setLocation(311, 352);
goldcoin2.setLocation(29, 59);
goldcoin8.setLocation(28, 253);
goldcoin5.setLocation(26, 452);
Snake snake = new Snake();
addObject(snake, 440, 32);
Snake snake2 = new Snake();
addObject(snake2, 182, 36);
Snake snake3 = new Snake();
addObject(snake3, 464, 457);
Snake snake4 = new Snake();
addObject(snake4, 177, 456);
Snake snake5 = new Snake();
addObject(snake5, 447, 263);
Snake snake6 = new Snake();
addObject(snake6, 188, 257);
removeObject(snake4);
removeObject(snake3);
snake6.setLocation(167, 427);
snake5.setLocation(442, 428);
snake2.setLocation(167, 39);
snake.setLocation(451, 41);
SuperGoldCoin supergoldcoin = new SuperGoldCoin();
addObject(supergoldcoin, 315, 97);
}
}
TheWorld2:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class TheWorld2 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TheWorld2 extends World
{
/**
* Constructor for objects of class TheWorld2.
*
*/
public TheWorld2()
{
super(1000, 800, 1);
prepare();
}
/**
* Prepare the world the start of the game
*/
private void prepare()
{
Counter counter = new Counter();
addObject(counter, 835, 19);
Player player = new Player(counter);
addObject (player, 452, 332);
GoldCoin goldcoin = new GoldCoin();
addObject(goldcoin, 587, 327);
goldcoin.setLocation(570, 326);
GoldCoin goldcoin2 = new GoldCoin();
addObject(goldcoin2, 31, 31);
GoldCoin goldcoin3 = new GoldCoin();
addObject(goldcoin3, 849, 60);
GoldCoin goldcoin4 = new GoldCoin();
addObject(goldcoin4, 846, 644);
GoldCoin goldcoin5 = new GoldCoin();
addObject(goldcoin5, 37, 653);
goldcoin.setLocation(450, 406);
GoldCoin goldcoin6 = new GoldCoin();
addObject(goldcoin6, 448, 250);
GoldCoin goldcoin7 = new GoldCoin();
addObject(goldcoin7, 854, 317);
GoldCoin goldcoin8 = new GoldCoin();
addObject(goldcoin8, 31, 353);
GoldCoin goldcoin9 = new GoldCoin();
addObject(goldcoin9, 449, 36);
GoldCoin goldcoin10 = new GoldCoin();
addObject(goldcoin10, 463, 677);
goldcoin10.setLocation(453, 676);
counter.setLocation(556, 16);
goldcoin9.setLocation(325, 28);
goldcoin6.setLocation(330, 222);
player.setLocation(333, 329);
goldcoin.setLocation(332, 416);
goldcoin10.setLocation(29, 134);
goldcoin8.setLocation(29, 253);
goldcoin5.setLocation(27, 442);
goldcoin8.setLocation(26, 304);
goldcoin10.setLocation(27, 183);
goldcoin9.setLocation(307, 29);
goldcoin3.setLocation(568, 60);
goldcoin7.setLocation(561, 331);
goldcoin4.setLocation(564, 241);
goldcoin7.setLocation(568, 448);
goldcoin6.setLocation(307, 166);
player.setLocation(313, 262);
goldcoin.setLocation(310, 374);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(27, 183);
goldcoin10.setLocation(310, 453);
goldcoin.setLocation(311, 352);
goldcoin2.setLocation(29, 59);
goldcoin8.setLocation(28, 253);
goldcoin5.setLocation(26, 452);
Snake snake = new Snake();
addObject(snake, 440, 32);
Snake snake2 = new Snake();
addObject(snake2, 182, 36);
Snake snake3 = new Snake();
addObject(snake3, 464, 457);
Snake snake4 = new Snake();
addObject(snake4, 177, 456);
Snake snake5 = new Snake();
addObject(snake5, 447, 263);
Snake snake6 = new Snake();
addObject(snake6, 188, 257);
removeObject(snake4);
removeObject(snake3);
snake6.setLocation(167, 427);
snake5.setLocation(442, 428);
snake2.setLocation(167, 39);
snake.setLocation(451, 41);
SuperGoldCoin supergoldcoin = new SuperGoldCoin();
addObject(supergoldcoin, 315, 97);
}
}
Also when I switch worlds by touching the edge (code below) when I get in the new world, and hit the side again, it resets the world.
if (atWorldEdge())
{
Greenfoot.setWorld(new TheWorld2());
}
