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
Wombats
By baseball2244, with 1 reply.
Replied to by danpost, over 7 years ago:
baseball2244 wrote...
Is it possible for the wombats to move diagonally? << Code Omitted >>
You would need to change line 48 to: <Code Omitted>and add the appropriate cases to the
switch
block in the
canMove
method. However, once an edge is reached, it will turn twice to go along each edge, anyway. Maybe adding a random turn to the code would help: <Code Omitted>
Help on background music!
By SniperRocks, with 6 replies.
Last reply by SniperRocks, over 7 years ago:
ive got a plan so hopefully itll work, ill give an update tomorrow evening.
Variable from MyWorld
By JPEG, with 3 replies.
Last reply by danpost, over 7 years ago:
JPEG wrote...
I'm not sure how, but I treat my actors like Variables. ... how do I figure out what case random has been assigned to? e.g If random followed case 2 (as I already said that the actor paper has to be pressed), the IF statement will mean that scissor's actor will be removed.
Place your actors in an array field: <Code Omitted>They will each now have a number associated with them: <Code Omitted>Your act method can then start wit
Variable Passing
By northernlights176, with 17 replies.
Last reply by danpost, over 7 years ago:
northernlights176 wrote...
You meant the GameScene and not the TitleScreen right? << Code Omitted >>
Yeah. I wanted to see what it does for its extensions. It is not a cause of your current concern; however, I do not really see a need for the class (it actually creates and plays multiple instances of the bg music -- one for each time an object is created for it or any of its extensions). Let us start afresh -- back to your originally posted code (w/o any of the changes I previously suggested) and think about this logically. You start with a
TitleScreen
object. Fine -- let
Enemy Collision
By iminblue, with 5 replies.
Last reply by danpost, over 7 years ago:
iminblue wrote...
They end up in a traffic jam that's the problem .
Well, they will be either on top of each other (fully or partially) or not. You cannot have it any other way.
Random Function
By JPEG, with 2 replies.
Last reply by JPEG, over 7 years ago:
Thanks, it worked!
get backgroound of an Actor
By xandreas_1, with 27 replies.
Last reply by xandreas_1, over 7 years ago:
thx a lot :D
Smooth movements
By aexelmaexel, with 1 reply.
Replied to by danpost, over 7 years ago:
This: <Code Omitted>from the
nachrechts
method, is equivalent to this: <Code Omitted>A similar thing can be said for the loop in the
nachlinks
method. Instead of Position values of 0 and 1, it would be better to have Direction values of 1 and -1. Also, instead of a constant verschiebung value, you can have it decremented to zero during a move (setting it to 88 when a move is initiated). The multiple similar if statements can also be simplified. You woul
Greenfoot crashes as soon as I go onto one of my own projects
By Digital_rookie4, with 9 replies.
Last reply by Digital_rookie4, over 7 years ago:
Its fine now I have found an older but more awkward version that does work
Random Function
By JPEG, with 2 replies.
Last reply by JPEG, over 7 years ago:
Sorry, that's not what I'm asking :)
Using a variable defined in a World class in an Actor Class
By oltmanac, with 6 replies.
Last reply by oltmanac, over 7 years ago:
Thank you so much! Everything works now! I really appreciate you taking the time to help me.
How to use mousePressed?
By Fargesia, with 1 reply.
Replied to by danpost, over 7 years ago:
Fargesia wrote...
I don't understand how to use the Greenfoot.mousePressed command. Like what do I have to put in the brackets? I know that I have to put the object but how do I write it?
The Greenfoot class documentation says this:
Parameters: obj - Typically one of Actor, World or null
Most of the time, it will be '
null
', meaning any click anywhere, or '
this
', referring to the object, created from that class or one of its subclasses, that the current block of code is being executed on (or for). If not one of those, it will be a named reference to an
wombat leaves java code
By rsmithlax, with 8 replies.
Last reply by codinglover456, over 7 years ago:
This is not a joke. its over for u young man
Need Help (says illegal start of expression)
By wcs0040, with no replies.
public class Ball extends Actor { /** * Responds to motion control from the arrow keys and removes * any buttons from the world when it intersects them. */ public void act() { handleKeyPress(); lookForButton(); } /** * Handles input from the arrow keys. */ public void handleKeyPress() { checkLeftArrow() ; checkRightArrow() ; checkUPArrow() ; checkDownArrow() ; } } /** * Checks to see if the left arrow key is being pressed. * If it is, then the ball sets its rotation angle to zero degrees * and moves backward 5 units. If it is not being pressed, * this method does nothing. */ public void checkLeftArrow() { public void act() { if (Greenfoot.isKeyDown("left") { setRotation(0); turn(-5); } } } /** * Checks to see if the right arrow key is being pressed. * If it is, then the ball sets its rotation angle to zero degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkRightArrow() { public void act() { if (Greenfoot.isKeyDown("right") { setRotation(0); turn(5); } } } /** * Checks to see if the up arrow key is being pressed. * If it is, then the ball sets its rotation angle to 270 degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkUpArrow() { public void act() { if (Greenfoot.isKeyDown("up") { setRotation(270); turn(5); } } } /** * Checks to see if the down arrow key is being pressed. * If it is, then the ball sets its rotation angle to 90 degrees * and moves forward 5 units. If it is not being pressed, * this method does nothing. */ public void checkDownArrow() { public void act() { if (Greenfoot.isKeyDown("down") { setRotation(90); turn(5); } } } public class Button extends Actor { /** * Checks to see if the ball is "touching" an object of the Button class. * If it is, then the ball removes from the World a Button that it touches. * If the ball isn't touching an object of the Button class, then this * method does nothing. */ public void lookForButton() { Actor B =getOneIntersectingObject(Ball.class) if (isTouching(Ball.Class)) { removeTouching(Ball.class) } } }
Helper class Mover. Where did it go?
By TNesler, with 2 replies.
Last reply by TNesler, over 7 years ago:
Thank you very much! Tom Nesler
213
214
215
216
217
218
219
X