Hello,
I have problems with creating class arrays and with this error. Here is my code :
java.lang.NullPointerException is at
What I want to do :
- a 2 player "line" game
My problem :
- Line1 class is not allowed to touch itself, but it touchs itself as soon as I create a new object of the class
Please help me :)
public class LineWorld extends World
{
Linep1[] line1 = new Linep1[5000];
Linep2 line2 = new Linep2();
static final int x = 500;
static final int y = 300;
int dir1 = 0;
int dir2 = 0;
public LineWorld()
{
super(x, y, 2);
Greenfoot.setSpeed(50);
addObject(new Linep1(), Greenfoot.getRandomNumber(x-30), Greenfoot.getRandomNumber(y-30));
addObject(line2, Greenfoot.getRandomNumber(x-30), Greenfoot.getRandomNumber(y-30));
Line1main();
}
public void Line1main()
{
if(Greenfoot.isKeyDown("right")) dir1+=8;
if(Greenfoot.isKeyDown("left")) dir1-=8;
line1[0].move(1);
line1[0].setRotation(dir1);
for(int i=0;i < 5000; i++)
{
addObject(line1[i], (line1[0].getX()), line1[0].getY());
}
}line1[0].move(1);
