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
Spawn new items after this items disappear
By Vojin, with 1 reply.
Replied to by SPower, over 10 years ago:
I'm assuming that at some point you do one of these things: <Code Omitted>You could simply add a line before doing this: <Code Omitted>It is important that if you use option 3, you add the new object
before
removing the object itself. because after it is removed, getWorld() will return null.
Delay spawn of objects when holding down a specific key?
By Sonarwave, with 6 replies.
Last reply by SPower, over 10 years ago:
I had put a comment in the code I posted, which explained that fireBullet was referring to the code you posted. But I'm glad it works now :)
Making an enemy character stay on the screen until killed.
By xlRenn, with 2 replies.
Last reply by valdes, over 10 years ago:
your variable movespeed, looks something like this: <Code Omitted> int your act() method or in other method called by act() <Code Omitted>
Scaling an Image
By ZacBuzzsaw, with 3 replies.
Last reply by davmac, over 10 years ago:
Turns out the image rescales when the run button is pressed
That indicates you have the code in an act() method. You should instead put it in the constructor for the actor.
Changing Smoke Image
By KatLady325, with no replies.
I have a game of Breaking Bricks I am working on. Ive been trying to change the image of the smoke every time the ball hits a brick, and I really have no clue how. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Ball extends Actor { private final int MAX_SPEED = 5; private int deltaX; // x movement speed private int deltaY; // y movement speed private int count = 2; private boolean stuck = true; // stuck to paddle private Brick brick; public void act() { if (!stuck && !((Board) getWorld()).getCheck()) { move(); makeSmoke(); checkOut(); } } private void move() { setLocation (getX() + deltaX, getY() + deltaY); checkPaddle(); checkBrick(); checkWalls(); } private void checkPaddle() { Actor paddle = getOneIntersectingObject(Paddle.class); if (paddle != null && getY() < paddle.getY()) { deltaY = -deltaY; int offset = getX() - paddle.getX(); deltaX = deltaX + (offset/10); if (deltaX > MAX_SPEED) { deltaX = MAX_SPEED; } if (deltaX < -MAX_SPEED) { deltaX = -MAX_SPEED; } Greenfoot.playSound("Pad.wav"); } } private void checkBrick() { brick = (Brick)getOneIntersectingObject(MetalBrick.class); if(brick==null){ brick = (Brick)getOneIntersectingObject(NormalBrick.class); } if(brick != null){ if(getY() > brick.getY()){ setLocation(getX(),getY()+2); deltaY = -deltaY; } else if(getY() < brick.getY()){ setLocation(getX(),getY()-2); deltaY = -deltaY; } else{ deltaX = -(deltaX+1); } if(brick instanceof MetalBrick){ Greenfoot.playSound("Bop.wav"); MetalBrick metalBrick = (MetalBrick)brick; metalBrick.decreaseCount(); if(metalBrick.isZero()){ metalBrick.remove(); ((Board) getWorld()).breakBrick(); } else{ metalBrick.updateImage(); } } if(brick instanceof NormalBrick){ Greenfoot.playSound("Bop.wav"); NormalBrick normalBrick = (NormalBrick)brick; normalBrick.decreaseCount(); if(normalBrick.isZero()){ normalBrick.remove(); ((Board) getWorld()).breakBrick(); } } } } private void checkWalls() { if (getX() == 0 || getX() == getWorld().getWidth()-1) { deltaX = -deltaX; } if (getY() == 0) { deltaY = -deltaY; } } private void checkOut() { if (getY() == getWorld().getHeight()-1) { ((Board) getWorld()).ballIsOut(); getWorld().removeObject(this); } } public void moveLR(int dist) { setLocation (getX() + dist, getY()); } public void moveUD(int dist) { setLocation (getX(), getY() + dist); } private void makeSmoke() { count--; if (count == 0) { getWorld().addObject ( new Smoke(), getX(), getY()); count = 2; } } public void release() { deltaX = Greenfoot.getRandomNumber(11) - 5; deltaY = -MAX_SPEED; stuck = false; } } import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Smoke extends Actor { private GreenfootImage image; // the original image private int fade; // the rate of fading public Smoke() { image = getImage(); fade = Greenfoot.getRandomNumber(4) + 1; // 1 to 3 if (fade > 3) { fade = fade - 2; } } public void act() { shrink(); } private void shrink() { if(getImage().getWidth() < 10) { getWorld().removeObject(this); } else { GreenfootImage img = new GreenfootImage(image); img.scale ( getImage().getWidth()-fade, getImage().getHeight()-fade ); setImage (img); } } } (very new to coding,sorry if this is unnecessary)
How can I build in a character choice
By JustQuinty, with no replies.
So I'm making a game for school, the only thing I did so far is build a world and I created two actor which I want to choose between. I will be adding other actors later on. Can anyone give me some advice?
Editing a second level
By kgorman, with 2 replies.
Last reply by kgorman, over 10 years ago:
Works great! Not sure why though, but I'll deal with that later - thank you!
Why Greenfoot wont let me publish my game :(
By AngelusNeko13, with 2 replies.
Last reply by AngelusNeko13, over 10 years ago:
thanks, ill see what i can do
Issues with player-controlled character falling through platforms
By jphb12, with 1 reply.
Replied to by danpost, over 10 years ago:
You must determine the direction that R2D2 is "falling" (up or down) when making contact with a platform to figure out whether he should stop below or above the platform (if moving up, then stop under the platform; if moving down, stop to stand on the platform). My
Jump and Run Demo w/Moving Platform
scenario shows how this is accomplished in the Who class.
Having a problem with changing the world.
By unpeaceful, with 5 replies.
Last reply by unpeaceful, over 10 years ago:
danpost wrote...
unpeaceful wrote...
It is an array of strings, is there any way to convert strings to a world or even the other way around?
You would have to do that systematically, one check at a time. Java now supports strings in 'switch' statements. You could possibly do something like this: <Code Omitted>If your java does not yet support strings in 'switch' statements, you will need to use 'if' statements for each case. Line 10 can be uncommented to show what an objet turned to a string would look like.
Thank you so much! I've been stressing over this for a whil
Input user content
By jpcp8000, with 1 reply.
Replied to by davmac, over 10 years ago:
You could use the
Greenfoot.ask()
method.
how would i make the code simpler?
By TheInternetJunkie, with 1 reply.
Replied to by davmac, over 10 years ago:
Hi, Please don't post Greeps code on this site. Greeps is used as an assignment in many schools and institutions, and the whole point of it is to think for yourself about how to improve their behavior and get a higher score. We would prefer that no Greeps code is available, since being able to look at other people's code defeats the purpose of the exercise. Thanks for understanding.
Having trouble with it compiling.
By Sanchala, with 1 reply.
Replied to by danpost, over 10 years ago:
Sanchala wrote...
side note- There's a lot of code to check so I'm wondering if someone can look it over. Thank you!
There is no problem with you posting the code here for us to look over. Just make sure you use code tags (see the link below the reply box -- 'Posting code? read this!'). You should include which side-scroller was the original (who published it and in what scenario), if not readily apparent.
Issue with printing array list in my game, please help!
By Quezng, with 1 reply.
Replied to by danpost, over 10 years ago:
Quezng wrote...
I am trying to make an array print with how many seconds are left everytime it is met. please help!
I am sorry. But, this is cryptic. First, an array does not print. Second, what is 'it' and what is it meeting (and how)? Finally, show the array (how it is declared, initialized and loaded).
Help about adding a timer
By Philip23, with 1 reply.
Replied to by danpost, over 10 years ago:
Please refer to my
Value Display Tutorial
scenario.
464
465
466
467
468
469
470
X