The problem I am currently facing is that the sourcecode of my Titlescreen is pretty much ignored, as the mainworld of my game is starting at the beginning. Here is the sourcecode of my TitleScreen-subclass:Sourcecode of my playbutton:
Code of my Main-World:Thanks for the support in advance :)
public class TitleScreen extends World
{
Actor playbutton = new Playbutton();
/**
* Constructor for objects of class TitleScreen.
*
*/
public TitleScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
Greenfoot.start();
prepare();
}
private void prepare()
{
addObject(playbutton, 100, 400);
}
}
public class Playbutton extends Actor
{
//playbutton.setImage("playbutton.png");
/**
* Act - do whatever the Playbutton wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
//playbutton.setImage("playbutton.png");
//addObject(playbutton, 300, 200);
if (Greenfoot.mouseClicked(this)) Greenfoot.setWorld(new BattleWorld());
}
}public class BattleWorld extends World
{
Player p1 = new Player(1, "tank.png", "left", "right", "up", "down");
Player p2 = new Player(2, "tank2.png", "a", "d", "w", "s");
Bar bar = new Bar();
Bar bar2 = new Bar();
public static int p1X = 100;
public static int p1Y = 300;
public static int p2X = 700;
public static int p2Y = 300;
Rohr rohr1 = new Rohr(1, "Rohr1.PNG");
Rohr rohr2 = new Rohr(2, "Rohr2.PNG");
/**
* Konstruktor für Objekte der Klasse BattleWorld
*
*/
public BattleWorld()
{
// Erstellt eine neue Welt mit 600x400 Zellen und einer Zell-Größe von 1x1 Pixeln.
super(800, 600, 1);
addObject(p1, 100, 300);
addObject(p2, 700, 300);
addObject(bar, 200, 40);
addObject(bar2, 600, 40);
addObject(rohr1,110, 300);
addObject(rohr2, 710, 300);
//addObject(playbutton, 300, 200);
}
public Bar getBar()
{
return bar;
}
}