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

Report as inappropriate.

davmac
davmac presents ...

2011/1/14

tut-access-p1

This scenario is part of a tutorial 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 meant to be a score. It isn't functional. Making it work is what the tutorial is all about!

31859 views / 64 in the last 7 days

2 votes | 0 in the last 7 days

Tags: game with-source howto

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

2012/7/5

It's... meant... to... be. It's... a... tutorial.
USER67USER67

2012/11/15

The code was great! thanks! Do you know to set a counter limit with a success message or perhaps a time limit? Thanks!
davmacdavmac

2012/11/15

Please ask on the forum (the "Discuss" link). :)
USER67USER67

2012/11/15

okay thanks mate
FEearlobeFEearlobe

2013/7/4

I<3disting
davecoolkiddavecoolkid

2013/8/27

Could you explain to me what this line of code does: Space spaceWorld = (Space) getWorld(); What do the parentheses mean when you put them around "(Space)"?
danpostdanpost

2013/8/27

'getWorld' return a World object (not particularly a 'Space' object; though it could be one). That is what '(Space)' does. It makes it a 'Space' object. This is called 'typecasting' and it informs the system to look in the 'Space' class for any methods or fields referenced with the World object. Any methods or fields that are declared in the 'Space' class would not be found otherwise.
davmacdavmac

2013/8/27

davecoolkid: as danpost says 'getWorld()' returns a 'World', but in the line of code you specify the variable is of type 'Space'. The compiler doesn't let you assign just a World to a Space variable (even though the World *might* be a Space). In this case we know that the world definitely *is* a space, so we use this type cast to tell the compiler that it's ok. A simple experiment you can do is to remove the type cast (the "(Space)" part) and try to compile. What happens?
davecoolkiddavecoolkid

2013/8/27

Thanks danpost and davmac for the clarification helped me out a lot.
CubeGamer6CubeGamer6

2017/4/24

Geez, i made a game myself much like this (as in space and stuff) and what suprised me after checking this page is that the space icon that is used here is IDENTICAL. It doesn't help either that the theme is much the same too. I'll just hope my teacher will believe that it is still original XD. Well, atleast i have a fancy movement engine.

See all comments

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

Who likes this?

Antonio wwwayne