This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

davmac presents ...



This scenario is part of a HOW-TO about accessing objects from another.
See the tutorial here:

This is a simple game. Press space bar to fire a shot at the asteroids which go past overhead. There is a delay between each shot so you must aim carefully.

The counter at the bottom left is a score counter.

This scenario represents the "finished product" that you should have after completing the HOW-TO!

23636 views / 87 in the last 7 days

9 votes | 0 in the last 7 days

Tags: game with-source howto

This scenario is a member of: Grand Designs

open in greenfoot
Your browser is ignoring the <APPLET> tag.


Thank you so very much for giving a tutorial on a simple counter!!!!!


Thanks a ton for this.


Alright so I've tried to do the exercise myself. I've followed the instructions as told and compare to the answer. It seems the code matches and while I compiled it the counter does not change every time I shot an asteroid. Please help.


thanks I tried my self and I found it very useful
Cool! I was having a hard time trying to figure it out. Thanks!


Thank you very much!, this is very helpful!


THANKS ! it was cool!


OMG thank you... I might become famous for this all thanks to you..YOU...Dave just. just thanks!
Not working for me :( Compiling works, no errors getting returned. But if a shot hits an asteroid it says: ------------------------------------------------------------------------------------- java.lang.NullPointerException at Shot.hitAnAsteroid( at Shot.act( at greenfoot.core.Simulation.actActor( at greenfoot.core.Simulation.runOneLoop( at greenfoot.core.Simulation.runContent( at -------------------------------------------------------------------------------------------------- private void hitAnAsteroid() { Space spaceWorld = (Space) getWorld(); // get a reference to the world XX Counter counter = spaceWorld.getCounter(); // get a reference to the counter XX counter.bumpCount(5); } -------------------------------------------------------------------------------------------------- that´s the code, the line marked with X´s is supposedly containing the error... but i dont get it Any help appreciated :)


I guess you changed the code of the class. You added at least four lines of code. The original one works without errors. What did you change (for example in the act method)? It would probably be the best to open a new discussion with a link to this scenario instead.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

猎鹰ndnd Samaguana Au79 epicm512 PStigerID Loncle jontin vinsent comphandler