This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
Discussions
You need to login to take part
Current Discussions
Multiple Worlds
By Collin, with 3 replies.
Last reply by Super_Hippo, about 11 years ago:
Start the first level as described. Don't start the other levels like that. Implement code to get to the next world: <Code Omitted>
How to see if a certain number of Animals is on the game.
By 4SeaBass, with 4 replies.
Last reply by 4SeaBass, about 11 years ago:
danpost wrote...
4SeaBass wrote...
if i wanted one object to be the last one there i would ?
You could get the current number with: <Code Omitted>or use a conditional like: <Code Omitted>
Thanks again! Sorry i am a student that is trying to make a project on the side!
Need general advice for calling/initializing classes
By oscarreks, with 9 replies.
Last reply by davmac, about 11 years ago:
is there a more elegant way to get data from it?
Again, in general, the bullet shouldn't need information from the turtle - have the turtle set the rotation of the bullet instead, and you avoid the whole issue. If you really do need to refer to the turtle, the most elegant way is to keep a reference to it somewhere (either in the object that you need to access it from, or in another object that you can get access to, such as the world).
One of the tutorials
covers this in some detail.
Save Game data
By Vellyxenya, with 8 replies.
Last reply by Vellyxenya, about 11 years ago:
It's okay I managed to fix that, thank you! :D
Prevent a class from performing an action
By Collin, with 9 replies.
Last reply by Collin, about 11 years ago:
Thanks a lot!!
How do you get a random coordinates?
By bamafan425, with 6 replies.
Last reply by danpost, about 11 years ago:
bamafan425 wrote...
I was trying to get multiple worms in to my game. Is that not the way to do it?
No. You either create and add each one into the world individually or use a 'for' loop to add them into the world.
creating multiple objects in a loop
By sse0005, with 4 replies.
Last reply by davmac, about 11 years ago:
Ok, it is empty, not null. But why is the initial capacity 5? Shouldn't it be the capacity 'numLobsters' (providing that numLobsters is an int)?
You are absolutely right. I'm not sure where I got that 5 from, sorry.
Creating txt file
By someone1, with 3 replies.
Last reply by danpost, about 11 years ago:
someone1 wrote...
Sry im not sure what you mean, i want to create a txt file using data from another existing txt file, im not to great at programming so could you show me how its done
The code for reading and writing text files is not beginner level stuff. Maybe you can use the UserInfo storage for what you want to do. You will not be able to write any files on the site, anyway, due to security restraints.
NullPointerException
By styxz99, with 7 replies.
Last reply by danpost, about 11 years ago:
The best way to learn is to add the actors manually and then use the 'Save the World' feature to write the code for you. Then look at the code in your World subclass and compare it to what actions you performed before saving the world. You can use that to learn how it is coded.
Need Help With a Game
By SonofArith, with 1 reply.
Replied to by danpost, about 11 years ago:
Please be a bit more specific. You need to determine and relay the following: * what conditions are required to begin the "re-charging" (specify all that apply) * what conditions are required to allow the space to trigger the killing of camels (specify all that apply) * what actions are taken (as far as anything that applies) when the "space" key is released (specify for all ranges of the timer (obviously you will need a timer) Give all actions and what conditions are required to begin those actions for the timer. If the timer is to count act cycles (which is probably best), three seco
Stocking numbers in an array
By Vellyxenya, with 2 replies.
Last reply by Vellyxenya, about 11 years ago:
Thank you very much danpost, for all your help :D
Galaxian
By daabas, with no replies.
import greenfoot.Actor; import greenfoot.Greenfoot; import greenfoot.World; public class Enemy extends Actor { private Score scoreNum; private static int count = 0; public Enemy(Score score_field) { this.scoreNum = score_field; count = 0; } public void act() { if (count <= 5) { setLocation(getX() - 5, getY()); } else if (count > 5) { setLocation(getX() - 8, getY()); } else if (count > 10) { setLocation(getX() - 11, getY()); } else if (count > 15) { setLocation(getX() - 14, getY()); } else if (count > 20) { setLocation(getX() - 17, getY()); } else if (count > 25) { setLocation(getX() - 20, getY()); } else if (count > 30) { setLocation(getX() - 23, getY()); } else if (count > 35) { setLocation(getX() - 26, getY()); } else if (count > 40) { setLocation(getX() - 30, getY()); } if (getX() <= 0) { setLocation(getWorld().getWidth() + 20, Greenfoot.getRandomNumber(400)); count -= 1; this.scoreNum.setText("Score: " + count); } if (getOneIntersectingObject(Missile.class) != null) { Actor laser = getOneIntersectingObject(Missile.class); getWorld().removeObject(laser); getWorld().addObject(new Explosion(), getX(), getY()); count += 1; this.scoreNum.setText("Score: " + count); Greenfoot.playSound("explosion.wav"); resurrect(); } /* extra för minus */ else if (getOneIntersectingObject(Missile.class) != null) { Actor laser = getOneIntersectingObject(Missile.class); getWorld().removeObject(laser); count -=1; this.scoreNum.setText("Score: " + count); resurrect(); } } public static int getValue() { return count; } private void resurrect() { setLocation(getWorld().getWidth() + 20, Greenfoot.getRandomNumber(400)); } }
"YOU WIN" screen help (score counter)
By CiaranDenning, with 16 replies.
Last reply by KiwiTitan, about 11 years ago:
KiwiTitan wrote...
i have the same problem ddObject(Counter, 100, 50); bear bear = new bear(); addObject(bear, 216, 267); bear bear2 = new bear(); addObject(bear2, 546, 137); bear bear3 = new bear(); addObject(bear3, 1081, 293); bear bear4 = new bear(); addObject(bear4, 1196, 523); bear bear5 = new bear(); addObject(bear5, 819, 242); bear bear6 = new bear(); addObject(bear6, 951, 584); bear bear7 = new bear(); addObject(bear7, 309, 612); bear bear8 = new bear();
hey how do i make things disapear when they hit athor thing(sorry for the English)
By logicbuildboy, with 1 reply.
Replied to by danpost, about 11 years ago:
The Actor class method 'isTouching' can be used to detect the 'hit'.
Track key presses?
By lava1234567890, with 1 reply.
Replied to by danpost, about 11 years ago:
Define a String field to hold the keystrokes. Initialize its value to an empty string and reset it to an empty string anytime the order is tested and found incorrect. Each time a key is pressed, add that character to the string. You will have to decide when to check the concatenated string for the proper sequence and when to clear its value.
540
541
542
543
544
545
546
X