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
Spawning objects after time
By Amature, with 12 replies.
Last reply by danpost, over 9 years ago:
MacG wrote...
I wanna addObject with some interval, But I want it loop, every 2 seconds, the zombie will show and it not stoping, can I do that ?
Just count act cycles; and when it reach the number of act cycles executed within a 2 second interval (usually something between 100 and 120) spawn a zombie and reset the 'int counter' field.
how do i set a timer
By Trevlodown, with 1 reply.
Replied to by Super_Hippo, over 9 years ago:
Place lines 2 through 6 into the act-method. By the way, you should probably use a higher number than 60 because 60 act-cycles is about one second at normal speed.
Greeps
By Aaron222, with no replies.
Hello I am doing the Greeps. My professor told me that the greeps should catch at least 15 tomatoes in 15 seconds in each map. I do not know where my source code should be changed. Those are my greep class' source code.<Code Omitted> import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A Greep is an alien creature that likes to collect tomatoes. * * @Alisa Johnston * @version 0.1 */ public class Greep extends Creature { // Remember: you cannot extend the Greep's memory. So: // no additional fields (other than final fields) allowed in this class! /** * Default constructor for testing purposes. */ public Greep() { this(null); } /** * Create a Greep with its home space ship. */ public Greep(Ship ship) { super(ship); } /** * Do what a greep's gotta do. */ public void act() { super.act(); // do not delete! leave as first statement in act(). TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class); Greep overlapping = (Greep) getOneIntersectingObject(Greep.class); if (atWorldEdge()) { turn(Greenfoot.getRandomNumber(90)); } if (carryingTomato()) { spit("purple"); if(atShip()) { dropTomato(); turn(180); move(); setMemory(0); } else { if (atWater()) { turn(Greenfoot.getRandomNumber(150)); move(); } else { turnHome(); move(); } } } else { if (atWater()) { turn(Greenfoot.getRandomNumber(150)); } if (tomatoes != null) { if (getMemory() < 9) { setMemory(getMemory() + 1); } if (getMemory() < 8) { move(); } } else { if (seePaint("purple") && !carryingTomato() && tomatoes == null && !atWorldEdge() && !atWater()) { turnHome(); turn(180); spit("orange"); } else if (!seePaint("purple") && !seePaint("orange")) { if (randomChance(30) == true) { if (randomChance(50) == true) { turn(0); } else { turn(-10); } } if (!atWater()) { spit("red"); } } else if (seePaint("red") && !seePaint("purple") && !seePaint("orange")) { if (randomChance(50) == true) { turn(90); } else { turn(-90); } } move(100); } checkFood(); } if (tomatoes == null) { setMemory(0); } } /** * Is there any food here where we are? If so, try to load some! */ public void checkFood() { // check whether there's a tomato pile here TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class); if(tomatoes != null) { loadTomato(); // Note: this attempts to load a tomato onto *another* Greep. It won't // do anything if we are alone here. } } /** * This method specifies the name of the author (for display on the result board). */ public static String getAuthorName() { return "Alisa Johnston"; // write your name here! } /** * This method specifies the image we want displayed at any time. (No need * to change this for the competition.) */ public String getCurrentImage() { if(carryingTomato()) return "greep-with-food.png"; else return "greep.png"; } }
Cannot find a simple collision method.
By elektrikpulse61, with 4 replies.
Last reply by elektrikpulse61, over 9 years ago:
Now that you've put it that way, your idea is much more logical. Of course when I try to assign a list-returning method to an Actor object, I'm going to get an incompatible types error! Thank you both davmac and danpost for your help on this. I'll be sure to remember your advice for next time!
Transparent part of an PNG sound not be able to be clicked
By 31oli31, with 4 replies.
Last reply by danpost, over 9 years ago:
Both the circle and the triangle/rectangle issues can be resolved using math. The circle issue is a 'length of an hypotenuse' problem (distance between two points) while the triangle/rectangle issue is a basic ratio problem (the percent distance of the mouse click from the center of the actor image to the left or right edge of the actor image compared to the percentage distance of the mouse click from the top edge of the actor image to the bottom edge). Both can also be resolved by checking for the color of the image at the location of the mouse click. If the color is not transparent the
changing text
By FutureCoder, with 9 replies.
Last reply by FutureCoder, over 9 years ago:
Thank you so much, it works perfectly.
looping
By olliequirk, with 2 replies.
Last reply by Super_Hippo, over 9 years ago:
I don't see an error there. What I notice is that lines 17 through 24 are the same as 25 through 32. If I remember correctly, the actors are only repainted in the world between the act-cycles (or if the method was called "manually"). So you can't see the character moving down when you hold down the down-key. When you release the key, the actor will be somewhere below the last position, but changing the image while falling in the do-while-loop doesn't really make sense because you can't see it. Why do you want to use a do-while-loop? Maybe it would work like you wish if you just use line 1 as
Making Solid Walls
By cleeming, with 1 reply.
Replied to by Super_Hippo, over 9 years ago:
Save the current position, move and if it is touching something it shouldn't be able to walk through, walk back. <Code Omitted>
how to
By Trevlodown, with 1 reply.
Replied to by danpost, over 9 years ago:
Trevlodown wrote...
How can I add one of my own games on to this website
Either click the 'Share' button near the top-right corner of the scenario window or press Ctrl-E; then use the 'Publish' tab on the pop-up 'Share' frame.
Need help stopping a timer when the world is changed.
By Exelious, with 4 replies.
Last reply by Exelious, over 9 years ago:
Thank you so much Danpost, it works perfectly now! You are the real MVP, what would I ever do without you? <3
Animated GIFs in Greenfoot (3)
By lehrerfreund, with 9 replies.
Last reply by Game/maniac, over 9 years ago:
Weird, the last time I tried to use the GifImage class it didn't work when I uploaded it to the greenfoot site. Maybe they fixed it?
UserInfo isStorageAvalible() not working
By trimil, with 13 replies.
Last reply by trimil, over 9 years ago:
I am working on both of those problems.
why am I getting this error, please explain
By divinity, with 24 replies.
Last reply by danpost, over 9 years ago:
divinity wrote...
can I ask a stupid question? can one make a constructor in the main and how do i make it
The 'main' can be placed into any class; but, you are only allowed to have one 'main' in any project. All classes are subclasses of the Object class (except the Object class itself, of course) and have constructors, whether explicitly given or not. So, the answer is you can have a constructor along with a main in a class (the constructor would not be in the 'main' code-block, of course). To me, doing so would seem a bit strange, however, as the name of the class the main is in w
Galactic Patrol
By Octavius, with 3 replies.
Last reply by Octavius, over 9 years ago:
thanks! it works now.
java.lang.NullPointerException
By Changster101, with 3 replies.
Last reply by danpost, over 9 years ago:
Before giving any suggestions for fixing the issue, let me explain what is happening here -- because if you can make sense of what is happening, you are better equipped to avoid the same issue in the future. In the Space class, you have line 33 assigning a new Pirate object to the 'pirate' field declared on line 13. On line 34, you are passing this object to a new Cruiser object for it to store by line 26 of the Cruiser class in its 'pirate' field declared on line 12. Nowhere past line 34 of the Space class is this Pirate object ever referred to again; that is, it is not added into the wo
449
450
451
452
453
454
455
X