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
coding error...need help!
By tomcoleman1994, with 1 reply.
Replied to by nccb, almost 13 years ago:
My guess is that either Rocket.act or Rocket.blowUpVehicle are removing the rocket from the world, and then
after
that, you look to see if it hit anything nearby. Because the rocket is no longer in the world, looking for nearby objects fails (as the error says: "Either has not yet been inserted, or it has been removed." Switch the order: check for hitting things before you remove the rocket from the world.
Subclass variables from another object
By Gazzzah, with 5 replies.
Last reply by Gazzzah, almost 13 years ago:
No worries, thanks! That's helpful, and thanks for the pro tip.
What is the symbol for OR?
By MakerOfGames, with 5 replies.
Last reply by rick, almost 13 years ago:
danpost wrote...
@rick, BTW, carefully calculate, as you stated above, 2 | 3 and see if your result is actually 2 (since both bits are 1s in binary for 3, then the result will have both bits as 1s; hence, 3).
Thanks, you're certainly right :-)
Please help me interpret this comment in to code
By jbutler9279, with 15 replies.
Last reply by jbutler9279, almost 13 years ago:
Is there anyway I can e-mail what I have so far and maybe you can steer me in the right direction?
Mouse is down
By Gazzzah, with 5 replies.
Last reply by Gazzzah, almost 13 years ago:
But that might be good to take a look at. Thanks Danpost
Reset UserInfo highscores
By trash1000, with 5 replies.
Last reply by nccb, almost 13 years ago:
It wasn't deliberate that we haven't added a way to add the high-scores... it's on our TODO list, we just haven't got to it yet! There will be a link on the website, available only to the scenario author, to wipe all data for that scenario.
my rocket wont fire :(
By tomcoleman1994, with 9 replies.
Last reply by tomcoleman1994, almost 13 years ago:
ok thanks i have used the isKeyDown Method now and all is ok, thanks
Making the Paddle Smaller
By theDoctor, with no replies.
I'm currently working on a Breakout game and need some help with something. I'm trying to make my Paddle (the object the Ball bounces off of) smaller everytime the Ball hits the bottom edge of the World. I have a set number of Balls (my method is numBalls) and I need to make it say this: "If the number of Balls is greater than 1, set the width of the Paddle to 40". The width of my Paddle at the beginning of the game is 60. I've posted my BreakoutWorld code below. import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Color; import java.awt.Font; import java.util.Calendar; import java.util.List; /** * Holds a game of breakout. In breakout there are 10 rows of bricks that the user * must get rid of to win. To get rid of bricks hit them with the ball. Use the paddle * to hit the ball. Use the left and right arrow keys to move the paddle. The user has * 3 balls to use to try to win the game and if the last ball gets past the paddle the user * loses. * * This game is based on Breakout by Eric Roberts who presented it as a nifty assignment * at SIGCSE in 2006 using the Java Task Force libraries. * * @author Barbara Ericson, Georgia Tech * @version 1.0, April 6, 2007 */ public class BreakoutWorld extends World { /** the width of the bricks in pixels (cells) */ public static final int BRICK_WIDTH = 36; /** the height of the bricks in pixels (cells) */ public static final int BRICK_HEIGHT = 8; /** the distance between bricks in pixels (cells) */ public static final int BRICK_SEP = 4; /** the number of bricks per row */ public static final int NUM_BRICKS_PER_ROW = 10; /** distance from the top edge in pixels (cells) */ public static final int BRICK_Y_OFFSET = 50; /** the number of pixels per cell */ public static final int RESOLUTION = 1; /** world width in pixels (cells) */ public static final int WIDTH = (BRICK_WIDTH + BRICK_SEP) * NUM_BRICKS_PER_ROW + BRICK_SEP; /** world height in pixels (cells) */ public static final int HEIGHT = 500; /** number of rows of bricks */ public static final int NUM_ROWS = 10; /** the colors to use for each row of bricks */ public static final Color colorArray = {Color.BLACK, Color.BLACK, Color.ORANGE, Color.ORANGE, Color.RED, Color.RED, Color.GREEN, Color.GREEN, Color.BLUE, Color.BLUE}; /** the number of balls created in the game so far */ private int numBalls = 0; /** a message displayed for the user */ private Message message = null; /** * No argument constructor */ public BreakoutWorld() { super (WIDTH, HEIGHT, RESOLUTION); setUpBreakout(); //createBrightStars(150); //createColorStars(150); } /** * Method to get the number of balls created * @return the number of balls created in the game */ public int getNumBalls() { return numBalls; } /** * Method to add a new ball */ public void newBall() { /* increment the number of balls created */ numBalls++; /* check if used 3 or more */ if (numBalls > 3) { message.setText("Game over! You fail. LOL!"); addObject(new LOLGuy(), 200, 310); Greenfoot.stop(); } /* create new ball and tell the user the number of balls created */ else { addObject(new Ball(), (WIDTH / 2), 222); message.setText("Try " + numBalls); } } /** * Method to check if the game is over and if so tell the user * and stop the simulation */ public void checkIfWon() { List brickList = this.getObjects(Brick.class); if (brickList.size() == 0) { message.setText("You didn't fail! Congratulations!"); Greenfoot.stop(); } } /** * Method to set up the breakout game */ public void setUpBreakout() { /* update image */ updateImage(); /* set up the message */ message = new Message("Creating the game... patience is a virtue."); addObject(message,WIDTH/2, 35); /* set up the bricks */ setUpBricks(); /* create the paddle */ addObject(new Paddle(),(WIDTH / 2),HEIGHT - 30); /* create a new ball */ newBall(); } /* * Method to set up the bricks in the world */ private void setUpBricks() { int yPos = BRICK_HEIGHT / 2 + BRICK_Y_OFFSET; int halfWidth = BRICK_WIDTH / 2; // addObject(new Brick(Color.RED),4,0); for (int row = 0; row < NUM_ROWS; row++, yPos = yPos + BRICK_HEIGHT + BRICK_SEP) { for (int col = 0, xPos = BRICK_SEP + halfWidth; col < NUM_BRICKS_PER_ROW; col++, xPos = xPos + BRICK_WIDTH + BRICK_SEP) { addObject(new Brick(colorArray),xPos,yPos); } } } /** * Method to create and set the image for the background */ public void updateImage() { GreenfootImage image = new GreenfootImage(WIDTH,HEIGHT); image.setColor(Color.WHITE); image.fillRect(0,0,WIDTH,HEIGHT); setBackground(image); } /** * Creates stars of random brightness to be displayed on the background image. * The parameter shows the number of stars on the background image. */ public void createBrightStars(int number) { GreenfootImage background = getBackground(); for(int i = 0; i < number; i++) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); GreenfootImage image = new GreenfootImage(4, 4); background.setColor(new Color(200, 200, 200, Greenfoot.getRandomNumber(256))); background.fillOval(Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()), 4, 4); } } /** * Creates stars of random color to be displayed on the background image. * The parameter shows the number of stars on the background image. */ public void createColorStars(int number) { GreenfootImage background = getBackground(); for(int i = 0; i < number; i++) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); GreenfootImage image = new GreenfootImage(4, 4); background.setColor(new Color(Greenfoot.getRandomNumber(256), Greenfoot.getRandomNumber(256), Greenfoot.getRandomNumber(256))); background.fillOval(Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()), 4, 4); } } } And here's my Paddle class code: import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) import java.awt.Color; /** * A paddle is a rectangular object that can be moved via the left * and right arrow keys. * * @author Barbara Ericson, Georgia Tech * @version 1.0 April 6, 2007 */ public class Paddle extends Actor { /** Width of the paddle */ private int width = 60; /** Height of the paddle */ private int height = 10; /** amount to move */ private int moveAmount = 5; /** color of this paddle */ private Color color = Color.BLACK; /** * No argument constructor */ public Paddle() { updateImage(); } /** * Constructor that takes the width, height, color, and moveAmount * @param theWidth the width to use * @param theHeight the height to use * @param theColor the color to use * @param theAmount the number of cells (pixels) to move */ public Paddle(int theWidth, int theHeight, Color theColor, int theAmount) { width = theWidth; height = theHeight; color = theColor; moveAmount = theAmount; updateImage(); } /** * Act - a paddle will move in reaction to a left or right * arrow key being pressed */ public void act() { if(Greenfoot.isKeyDown("left")) { setLocation(getX()-moveAmount, getY()); } if(Greenfoot.isKeyDown("right")) { setLocation(getX()+moveAmount, getY()); } } /** * Method to create and set the image for this paddle. Invoke * this method again when the width, height, or color change. */ public void updateImage() { GreenfootImage image = new GreenfootImage(width, height); image.setColor(color); image.fillRect(0, 0, width, height); setImage(image); } }
Picture from different sides
By martijn13039, with no replies.
how can you make from a picture a front, rear, left and right side I hope somebody has an idea martijn
Source Code Link broken?
By lex404, with 2 replies.
Last reply by davmac, almost 13 years ago:
I've fixed the link now, sorry about that.
Using a Kinect with Greenfoot
By mik, with 11 replies.
Last reply by davmac, almost 13 years ago:
It's fixed now - sorry for the inconvenience.
BufferedImages and hackyness in Greenfoot
By Builderboy2005, with 4 replies.
Last reply by davmac, almost 13 years ago:
Yep, not possible, sorry.
LearningGame help
By chris4800, with 3 replies.
Last reply by rkzkIMP, almost 13 years ago:
yanks101 wrote...
chris any interest in helping me out with the 2 labs due tonight, ill pay you.
come to you-know-where-the-linux is. ill help you out with practice 4
Flip a card one at a time and guess
By miko122, with 16 replies.
Last reply by rkzkIMP, almost 13 years ago:
yanks101// come to the comp area you can (you kno where) i can definately help you with the practice 4.
HELP ASAp
By yanks101, with 1 reply.
Replied to by tylers, almost 13 years ago:
what is it
978
979
980
981
982
983
984
X