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

Comments for Tux

Return to Tux

A new version of this scenario was uploaded on Sat Sep 28 01:00:04 UTC 2013 add sounds
g3og3o

2013/9/28

How to I download this?
A new version of this scenario was uploaded on Sun Sep 29 00:20:43 UTC 2013 Added lives I'm still looking for a way to respawn Tux when the lives > 0 and Tux doesn't exist. Any help is appreciated
danpostdanpost

2013/9/29

Add a 'get' method to the Lives class to return the current value. Then in the world, add an act method that checks for a Tux object in world. If not in world, decrement the lives counter and check its value against zero. If zero, stop the scenario; otherwise, add a new Tux object into the world.
SniperSniper

2013/9/29

Could you post examples of that code? Sorry, I'm new.... Every way I've tried I get some kind of compiling error. Would I use getObjects(Tux.class) to find if he exists or?
SniperSniper

2013/9/29

I've tried doing this in the Lives.class but I get errors compiling whether I put = null, = 0, != 1, etc.... What am I doing wrong? public void act() { if (totalLives > 0) { if (getWorld().getObjects(Tux.class) != 1) { Tux tux = new Tux(); getWorld().addObject(tux, 300, 300); } } else { Greenfoot.stop(); } }
A new version of this scenario was uploaded on Sun Sep 29 05:55:28 UTC 2013 Added respawn and new sounds :)
Entity1037Entity1037

2013/9/29

Try using: [code] getOneIntersectingObject("[Insert Name Here].class"); [/code] instead of: [code] getOneObjectAtOffset(0,0,[Insert Name Here].class); [/code] It will detect an apple intersecting with the penguin's image instead of the center of the penguin.
A new version of this scenario was uploaded on Sun Sep 29 06:23:49 UTC 2013 Added winning/losing text/sounds
A new version of this scenario was uploaded on Sun Sep 29 06:29:31 UTC 2013 Tweaked apple detection code (thanks Entity1037)
Entity1037Entity1037

2013/9/29

You're welcome! :D
A new version of this scenario was uploaded on Sun Sep 29 06:59:05 UTC 2013 Added restart button (press r or click the red button)
danpostdanpost

2013/9/29

Referring back to Lives and respawning Tux, the code is better off in the world class, however, it should work still in the Lives class. Looking at the greenfoot.Actor class documentation, you will see that 'getObjects' returns a List object and therefore cannot be compared to an integer and will never be null. Looking at the methods in the java.util.List class documentation, you will find an 'isEmpty' method which you can make use of.