This site requires JavaScript, please enable it in your browser!
Greenfoot back
Game/maniac
Game/maniac wrote ...

2012/10/6

I need help, again!

Game/maniac Game/maniac

2012/10/6

#
every time I shoot a smaller yellow ball the game freezes plz help, source code:http://www.greenfoot.org/scenarios/6065
-nic- -nic-

2012/10/6

#
ill have a look
-nic- -nic-

2012/10/6

#
i think your trying to use the astroballs varibels but its been removed from the world
-nic- -nic-

2012/10/6

#
im not sure though
Game/maniac Game/maniac

2012/10/6

#
I dont think that's what is causing it
-nic- -nic-

2012/10/6

#
hmm not sure im sorry
-nic- -nic-

2012/10/6

#
btw your game is very good i like it a lot one comment is that the window its played in is soo large it made made firefox almost crash and ive got a widescreen screen
Game/maniac Game/maniac

2012/10/6

#
ok ill make it a bit smaller
AceticAcid AceticAcid

2012/10/6

#
I recommand the way fix the problem. In subclass of World in your cord, declare 'Counter counter' in class but not in method. and add "counter = new Counter()" in Constructor Method. (In your class, public Worldy() method) and then do addObject in Constructor Method, too. After that, correct AstroBall class. Do not declare 'counter' in the class, and use following form: ((Worldy)getWorld()).counter.add(5) If you use that form in destroy method in AstroBall class, It may not pop up NullPointerException.
Game/maniac Game/maniac

2012/10/6

#
It now says cannot find symbol - variable counter
Gevater_Tod4711 Gevater_Tod4711

2012/10/6

#
If you hit the AstroBall with your bullet it is removed and four new AstroBalls are added to the world. But look at the construktor. You use a constructor in which no counter is given to the object and if you now try to use a method of this counter you get the nullPointerException. To fix the problem you should change this constructor maybe this way:
public AstroBall(int direction, int health, Counter pointCounter) {
    setRotation(direction);
    hp=health;
    getImage().scale(getImage().getWidth()-health,getImage().getHeight()-health);
    counter = pointCounter;
}
Now you have to change the method which adds the balls to the world:
//in the method destroy;
if(nhp<50){
    getWorld().addObject(new AstroBall(315, nhp, counter),getX()+10,getY()-10);
    getWorld().addObject(new AstroBall(45, nhp, counter),getX()+10,getY()+10);
    getWorld().addObject(new AstroBall(135, nhp, counter),getX()-10,getY()+10);
    getWorld().addObject(new AstroBall(225, nhp, counter),getX()-10,getY()-10);
}
Then it should work.
Game/maniac Game/maniac

2012/10/6

#
Its fixed now
-nic- -nic-

2012/10/6

#
nice one!
You need to login to post a reply.