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

Report as inappropriate.

davmac
davmac presents ...

2011/1/14

tut-access-p2

This scenario is part of a HOW-TO about accessing objects from another.
See the tutorial here: http://www.greenfoot.org/doc/howto-1
---------

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!

36661 views / 3661 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 does not support the canvas tag.
Au79Au79

2014/3/22

Thank you very much!, this is very helpful!
jordan93jordan93

2015/3/24

THANKS ! it was cool!
JMB123JMB123

2015/4/8

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(Shot.java:58) at Shot.act(Shot.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) -------------------------------------------------------------------------------------------------- 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 :)
Super_HippoSuper_Hippo

2017/6/14

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.
VenbhaVenbha

2017/8/27

WOW!!!!!!!!
VenbhaVenbha

2017/8/27

Nice
Roshan123Roshan123

2020/6/23

i have a doubt i your tutorial will it work or not //in rocket.class //globally Counter counter; //i already added it in the world i.e. Counter counter=new Counter addObject(counter,150,100) //in hitByAsteriod() method { counter.bumpCount(5); }
Roshan123Roshan123

2020/6/23

plz ignore upper comment
Roshan123Roshan123

2020/6/23

reply this one i have a doubt in your tutorial will it work or not //in rocket.class //globally Counter counter; //i already added it in the world i.e. Counter counter=new Counter addObject(counter,150,100) //in hitByAsteriod() method of Rocket.class { counter.bumpCount(5); }

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