Hello guys,
im having a try at programming Break Out. I tried to implement a score counter into my Game but the system keeps crashing. I tried several times to understand what was going wrong but i couldnt see the problem.
Here is the relevant code and the error message. I hope that you can help me fix this.
public class Spielfeld extends World
{
private Counter counter;
public Spielfeld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(640, 480, 1);
}
public void Punkte()
{
counter.PunkteHinzufuegen();
}
public class Ball extends Actor {
private int dx;
private int dy;
private void pruefeKontaktBlock()
{
Actor block = getOneIntersectingObject (Block.class);
if (block != null)
{dy = -dy;
getWorld().removeObject(block);
Spielfeld mySpielfeld = (Spielfeld)getWorld();
mySpielfeld.Punkte();
}
}
public class Counter extends Actor
{
private int punkte;
public Counter()
{
punkte = 0;
setImage (new GreenfootImage(200, 30));
update();
}
public void PunkteHinzufuegen()
{
punkte++;
update();
}
private void update()
{
GreenfootImage img = getImage();
img.clear();
img.setColor(Color.GREEN);
img.drawString("Punkte: " + punkte, 4, 20);
}
}
