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
Life system isn't working
By sihaco, with no replies.
I have a class Tumbler and a subclass of Tumbler called Life. The Tumbler has a public field called lifes which is initially equal to 3. When the Tubmler hits an object of the class Car, the field lifes should decreased with one (lifes = lifes - 1). In the class Life (subclass of Tumbler) I have code to remove one object of Life (which is a heart symbol). The problem is, instead of doing lifes = lifes - 1 (so the first time, it should be 3 - 1 = 2) lifes gets a value of -185. This is the code for the method when the Tumbler hits a Car: <Code Omitted> And this is the code for Life: <Code Omitted> Both methods are called from the act method. What's the problem? It should simply just do life - 1, instead of making the value of life equal to -100 +.
Piggie change direction
By ddvink, with 2 replies.
Last reply by danpost, about 11 years ago:
The 'checkFloor' method only lets you know if you are on an end floor; but does not let you know which end. So, your actor needs more information to determine which way to go. The simple solution is to ask whether the x location of the actor is greater than or less than half the width of the world. <Code Omitted>I may have '1' and '2' arranged incorrectly; but, the main idea should be apparent.
Starting at a random interval
By Baenefin, with 4 replies.
Last reply by danpost, about 11 years ago:
I guess you could change 'if (j >= 250)' to something like 'if (j >= 225+Greenfoot.getRandomNumber(50))' to vary the intervals.
Animation stays behind char
By ddvink, with no replies.
Dear all, I have a game where I control a character. When the character levels an object is called from a levelup class where an animation takes place. This animation is about twenty images. Everything looks ok, but when the char levels and walks on, the animation stays behind. Is there a way to move that animation with the character? Yours, Dennis
to end a game
By sophiefordream, with 2 replies.
Last reply by danpost, about 11 years ago:
In the world class, you can use 'getObjects(null).isEmpty()' to see if no actors are in the world. For a specific set of actors, you will need to combine them like this 'getObjects(Butterfly.class).isEmpty && getObjects(Elephant.class).isEmpty() && /* etc */'.
my program stop
By sophiefordream, with 7 replies.
Last reply by sophiefordream, about 11 years ago:
thanks.....^^
Why does my for loop add the course to every element?
By thekidj, with 1 reply.
Replied to by erdelf, about 11 years ago:
why are u using a for-loop when u just want one index to be set`?
Passing background music to other worlds and controlling.
By Tavi, with 4 replies.
Last reply by danpost, about 11 years ago:
Remove line 39. Line 45 needs to be moved elsewhere (to wherever the next level is called).
keeping and incrementing a score
By i_joker123, with 7 replies.
Last reply by danpost, about 11 years ago:
Change line 18 to 'if (getWorld() != null) collide();'. (when 'go_off' removes the actor, 'collide' cannot get intersectors).
NullPointerException
By Lee1121, with 4 replies.
Last reply by Lee1121, about 11 years ago:
danpost wrote...
Line 15 in the Enemy class assigns dungeonWorld a value using 'getWorld()' which has a value of 'null' at the time the assignment takes place. The assignment of the fields take place during the construction of the object and the object is never added into any world until construction is complete. To assign the proper value to that field, you need to make use of the 'addedToWorld' method supplied by the Actor class. <Code Omitted>The 'addedToWorld(World)' method is automatically called by th
Spawning according to lifecounter
By Baenefin, with 11 replies.
Last reply by danpost, about 11 years ago:
Try: <Code Omitted>
Game Over
By Mar_Om, with no replies.
Hello, I'm trying to adjust the color and font of the string on the World. Here is what I've got so far. Tanks <Code Omitted>
collision of more than one object at a time.
By i_joker123, with 2 replies.
Last reply by i_joker123, about 11 years ago:
public class baddie extends Actor { /** * Act - do whatever the arrow wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private int speed; public void act() { // Add your action code here. MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse !=null) setRotation((int)(180*Math.atan2(mouse.getY()-getY(),mouse.getX()-getX())/Math.PI)); move(speed); if(Greenfoot.mouseClicked(null)) {
for() loops... how to use? -gruver
By ksksks, with 2 replies.
Last reply by ksksks, about 11 years ago:
I don't read that kind of type well, I have poor eyesight. Also, I was trying to find a way that would explain better than my textbook.
follow objects
By 13111876, with no replies.
Hello all, I'm trying to get my objects follow an other object. Here is my code till now: <Code Omitted> public int weight; // instance variable private int limit = 300; //instance variable public boolean isOverWeight() { List<Persoon> personen = (List<Persoon>)getIntersectingObjects(Persoon.class); int currentWeight = 0; for (Persoon persoon : personen) { currentWeight += persoon.getWeight() ; } if (currentWeight >= 49) { setLocation (getX(), getY() +1); //setLocation (List<Persoon>)getIntersectingObjects(Persoon.class) (getX() getY() +5); } return currentWeight > 300; } In this code I let the objects follow 'Boot'. The 'Boot' keeps track of how much weight there is in 'Boot' and who is intersecting him. I want 'Boot' to sink a every time an objects intersects him. Help please.
771
772
773
774
775
776
777
X