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
Inventory
By DMCGames, with 1 reply.
Replied to by DonaldDuck, over 14 years ago:
I would create an object inventory (an actor, but remove the extends Actor to make it an "other class") and inside of it make a static array called inv. You can make the array as large as you want inventory slots. Everything in this class must be static and can be called from another class by saying inventory.something or you can write inventory i = new inventory; i.something and not need to have statics. The advantage to the second method is that the variables will be reset with the program instead of having to write a reset method for it.
start/restart button
By tylers, with 1 reply.
Replied to by Duta, over 14 years ago:
Not unless you're going to re-code the actual Greenfoot source-code
embed a webpage onto a scenario
By tylers, with 2 replies.
Last reply by tylers, over 14 years ago:
ok thanks i will give it a miss then :)
for loop working on menu
By programmer22, with 1 reply.
Replied to by danpost, over 14 years ago:
To have code execute only at the initial
start
of the scenario, create a method called 'public void started()' (a method of this name will over-ride the empty super-class method with the same name that is called when the 'Run' button is pressed. The only problem to deal with is, what happens when to scenario is paused and then re-started (it
will
run again). That being said, you need a boolean instance variable in the world class to track the initial start. <Code Omitted>Then, start your new method with
strange?
By programmer22, with 2 replies.
Last reply by programmer22, over 14 years ago:
its ok i figured it out i just borrowed some pics
Sound Problem? Help!
By TheNightStrider, with 2 replies.
Last reply by TheNightStrider, over 14 years ago:
It had no tags on anyway - i have converted them in wavs anyway now - this was really irritating me!
"Life is too short..." Using getObjectsInRange()
By Omniscience, with 7 replies.
Last reply by Omniscience, over 14 years ago:
Thanks! Works great... plus I understood the logic behind it! I'm gonna try and create a Game Over dialogue Box, which will appear when the Car.class no longer exists in the world. Will post feedback! Thanks again
danpost
!
Random and not repeating
By Gazzzah, with 1 reply.
Replied to by Gazzzah, over 14 years ago:
I could do this with 4 booleans I guess, but I figure there might be an easier way. It's kind of messy to have a massive "while" statement consisting of "(position == 1 && used1) || (position == 2 && used2) || etc...
Random # and chance problems
By Tomc84, with no replies.
I am suppose to pick a # between 1-4 for my vertical speed at random with a 50% chance to go up or down. Same with my left and right and I have no clue what I'm doing wrong... PLZ I need help :( import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Ball here. * * @author (your name) * @version (a version number or a date) */ public class Ball extends Actor { private int ySpeed; private int xSpeed; private int wait; private int random; public Ball() { ySpeed = 3; //do not really need constructor call xSpeed = 3; wait = 80; random = Greenfoot.getRandomNumber(3)+1; } /** * Act - do whatever the Ball wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //ballMove(); //bounceOffPaddle(); bouncOffWalls(); if (wait == 0) { ballMove(); } else { wait --; } } // public void ballMove() // { // setLocation(getX() +xSpeed, getY() +ySpeed); // } /** * Move the ball */ public void ballMove() // NEW MOVE METHOD { if (getY() == 0 || getY() == 500-1) { ((PongWorld)getWorld()).updateScore(this); setLocation( 350, 250 ); } else { //setLocation (getX(Greenfoot.getRandomNumber(3)+1), getY(Greenfoot.getRandomNumber(3)+1)); //Greenfoot.getRandomNumber(random)<2); RandomMove(); setLocation(getX()+xSpeed,getY()+ySpeed); //movement bounceOffPaddle(); // new call for bounceOffPaddle } } public void RandomMove() { if (Greenfoot.getRandomNumber(random)<2); { setRotation(Greenfoot.getRandomNumber(360)); } } public void bounceOffPaddle() { Paddle paddle = (Paddle) (getOneObjectAtOffset(0, 0, Paddle.class)); // tells ball paddle is here if (paddle != null) { ySpeed = ySpeed * (-1); } } public void bouncOffWalls() { if(getX() == 0 || getX() == 700-1) // use of logic or to condense two if statements { xSpeed = xSpeed * (-1); } // else ...........WHY NOT USE AN ELSE???? // { // xSpeed = xSpeed * (-1); // } } // public void bouncOffWalls() CAN BE CONDENSED A SINGLE IF STATEMENT...... HOW THOUGH?????? // { // if(getX() == 0) // { // xSpeed = xSpeed +1; // } // if (getX() == 700-1) // { // xSpeed = xSpeed * (-1); // } // } }
I am having trouble
By Clueless, with 10 replies.
Last reply by darkmist255, over 14 years ago:
@clueless If you're still unsure I would say download the jdk-7u3-windows-i586.exe, since even if you have 64-bit system it will still run. @Builderboy2005 I'm same as Duta, I definitely think that if he's interested he should take a shot at coding! I wish him the best of luck with it, I'm just skeptical :D. Once again, if he is able to get started, I hope that he will make really good progress and will learn to be a great coder! PS: My motivational skills suck, so anything I say will probably be demotivating in some way :D.
HTML (not to do with Greenfoot)
By Duta, with 2 replies.
Last reply by Duta, over 14 years ago:
Incase anyone's interested, I got it working with the following code: <html> <title>HTML Page 1</title> <script type = "text/javascript"> <!-- function popup() { newwindow2=window.open('','name','height=200,width=150'); var title = document.forms.value; var text = document.forms.value; var tmp = newwindow2.document; tmp.write('<html><head><title>' + title + '</title>'); tmp.write('<link rel="stylesheet" href="js.css">'); tmp.write('</head><body><p>' + text + '</p>'); tmp.write('<p><a href="javascript:self.close()">Close</a> this popup.</p>'); tm
Sequence of Button Inputs
By programmar, with 12 replies.
Last reply by programmar, over 14 years ago:
It works now :) thanks again. By changing the firing method to if ("space".equals(key)) it fired multiple projectiles with one key press. I changed it to the code from http://www.greenfoot.org/topics/802.
How I could do that?
By TopInPut, with 1 reply.
Replied to by danpost, over 14 years ago:
I am assuming that 'eatLeaf()' does nothing more that returns a boolean value depending on whether a leaf is intersecting the Actor or not. You code says to take the current (intersecting) leaf and move it one grid to the right. Now, assuming you want to add the new leaf at the same location (though you may want to place it randomly on your grid) 'getWorld().addObject(new Leaf(), x, y);' would do the trick (just set up x and y to appropriate random values for anywhere).
Can you help me plz about F10-button
By terapaht, with 1 reply.
Replied to by davmac, over 14 years ago:
This happens only on Windows, but there's not much you can do about it. Use a different key.
Help!!!!!! I don't understand at all?
By TheNightStrider, with 13 replies.
Last reply by danpost, over 14 years ago:
Check out the section on 'Class methods' and the following sections in the
Classvars tutorial page
1008
1009
1010
1011
1012
1013
1014
X