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
hey how can you an actor walk automatic with this code
By martijn13039, with 4 replies.
Last reply by martijn13039, almost 12 years ago:
I hope you guy understand what I mean if you donĀ“t ask me what you not understand in my question
How do i take score to multiple levels?
By chilvenl01, with 6 replies.
Last reply by davmac, almost 12 years ago:
Example: <Code Omitted> You can keep the original constructor as well, so that you can still create the first world without supplying a score.
Question about Newton's lab
By rkzkIMP, with no replies.
can anybody help with the exercise 6.36 for the Newton's lab? I am trying to change/add codes for obstacle that gets switched on and off by being hit by a body. private void checkToggle() { if (!touched && isTouching()) { touched = true; toggleOn = !toggleOn; if (toggleOn) { setImage ("block-light.png"); Greenfoot.playSound(sound); } else { setImage ("block.png"); } } if (touched && !isTouching()) { touched = false; } }
Where do I get images for my game?
By MakerOfGames, with no replies.
I need help getting an image for a human character
Where can you find all the sounds available.
By lsnoss, with 2 replies.
Last reply by erdelf, almost 12 years ago:
you can use every music file in AIFF, AU, WAV, MP3 and MIDI. <Code Omitted>the commands for sounds are in the
documentation
Some Really Simple Stuff...
By theDoctor, with 2 replies.
Last reply by theDoctor, almost 12 years ago:
Thanks nccb.
coding error...need help!
By tomcoleman1994, with 1 reply.
Replied to by nccb, almost 12 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 12 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 12 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 12 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 12 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 12 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 12 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
970
971
972
973
974
975
976
X