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
Scroller Displacement Problems
By treykrizek03, with 5 replies.
Last reply by danpost, about 6 years ago:
treykrizek03 wrote...
how I would be able to get the Player to spawn back into the world at the correct checkpoint after falling off of it ... the coordinates of the objects got displaced, so the Player isn't getting set to the correct location.)
You will need to make use of
getScrollX
and
getScrollY
. I guess one way to handle it is to negate the scrolled amount (un-scroll back to initial position), then add the player back in. Another is to subtract the scrolled amounts from the coordinates where you want the player.
Forcing the Mouse
By Brandman73, with 1 reply.
Replied to by danpost, about 6 years ago:
I would presume that the code in
Mouse Trap
by
Bourne
would provide a decent example.
score counter
By JohnBis, with 1 reply.
Replied to by danpost, about 6 years ago:
JohnBis wrote...
Can i create score counter which add score between (480,600) to (520,600) ?
Are those amounts in the hundred thousands or world coordinate pairs? Also, please show attempted codes. It can go a long way in at least showing what you are trying to accomplish.
plz help me
By Roshan123, with 1 reply.
Replied to by danpost, about 6 years ago:
You want to ask about two distinct conditions such that if BOTH are satisfied, then execute some specific code. That is a logical AND operation (if condition (a) AND if condition (b) ...: <Code Omitted>The "
&&
" is the logical AND operator and "
||
" is the logical OR operator.
Is there any other way to get user keyboard input than getKey and isKeyDown?
By mshep, with 2 replies.
Last reply by mshep, about 6 years ago:
Makes sense. Thanks a lot!
I need help, submitting this today for AP CSP!
By lucasstan, with 1 reply.
Replied to by danpost, about 6 years ago:
Apparently, you need a String type argument: <Code Omitted>
Printing an image in another class
By SnowFlurry, with 5 replies.
Last reply by danpost, about 6 years ago:
SnowFlurry wrote...
Thanks! That does make the text print in a visible place, but it still only prints when called from the Text class, calling the textBox() method from the main class still does not make the code print the image... I'm stumped.
Show main class codes with attempt.
shapes
By Roshan123, with 2 replies.
Last reply by Roshan123, about 6 years ago:
ok, thanks for reply
Cannot find method
By neoaspect, with 9 replies.
Last reply by danpost, about 6 years ago:
neoaspect wrote...
Sorry I can't seem to wrap my head around this, I understood the timer part, but not particularly what to put in the 'trackedState' parts
The
<< current state >>
would be the
isTouching
condition. The
<< perform action >>
would be the player losing a life.
Anyone knows what's wrong here?
By MYSTICPHOENIXXX, with 2 replies.
Last reply by MYSTICPHOENIXXX, about 6 years ago:
danpost wrote...
Line 23 in your Bullet class failed because the bullet was removed from from the world (probably due to line 22 or 21). Of course, without the code of the Bullet class being posted, no further assessments can be made nor can further help be provided.
OHHHH, I just saw the problem after reading your comment danpost, thank you so much, you are a really big help!
Anyone know how to prevent freezing on the transferto a second world?
By MYSTICPHOENIXXX, with 3 replies.
Last reply by MYSTICPHOENIXXX, about 6 years ago:
MYSTICPHOENIXXX wrote...
Weeb3.exe wrote...
show code
For what class? The only one that can stop Greenfoot is in the "Skythrust" class.
My music button doesn't stop
By LukaMoon, with 5 replies.
Last reply by LukaMoon, about 6 years ago:
danpost wrote...
LukaMoon wrote...
Where do I put my music?
Put filename as parameter in
BGMusic
constructor call: <Code Omitted>
Thank you so much! Just what I needed
I want to make a bullet be able to affect the lives of both heros in multiplayer mode!
By LukaMoon, with 2 replies.
Last reply by LukaMoon, about 6 years ago:
How would I do that?
How do I add 1 to my tail every time my snake eats a food?
By lova30940, with no replies.
Tail Code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Tail here. * * @author (your name) * @version (a version number or a date) */ public class Tail extends Actor { /** * Act - do whatever the Tail wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int w,g,b; int count=0; public Tail(int w, int g, int b) { this.w=w; this.b=b; this.g=g; getImage().setColor(new Color(w,g,b)); getImage().fillRect(0,0,40,40); } public void act() { count++; if (count >60) getWorld().removeObject(this); // Add your action code here. } } Snake Code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Player here. * * @author (your name) * @version (a version number or a date) */ public class Player extends Actor { /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int w, g, b, player; int speed = 2; int count=0; public Player(int player,int w,int b) { setRotation(180); this.w = w; this.b = b; this.g = g; getImage().setColor(new Color(w,g,b)); getImage().fillRect(0,0,40,40); } public void act() { count++; getWorld().addObject(new Tail(w, b, g), getX(), getY()); move(speed); if(this.player == 0){ if(Greenfoot.isKeyDown("right")) setRotation(0); if(Greenfoot.isKeyDown("left")) setRotation(180); if(Greenfoot.isKeyDown("up")) setRotation(270); if(Greenfoot.isKeyDown("down")) setRotation(90); if(isTouching(Food.class)) { removeTouching(Food.class); MyWorld world = (MyWorld)getWorld(); world.addFood(); } } } } World Code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class MyWorld extends World { /** * Constructor for objects of class MyWorld. * */ Player bluePlayer = new Player(0,255,0); Player whitePlayer = new Player(255,0,0); int count=0; public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); getBackground().setColor(Color.BLACK); getBackground().fill(); addObject(bluePlayer, 450, 300); addObject(whitePlayer, 450,100); int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); addFood(); } public void addFood() { count++; int x = Greenfoot.getRandomNumber(400); int y = Greenfoot.getRandomNumber(400); addObject(new Food(), x+1, y+1); } } Food Code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Food here. * * @author (your name) * @version (a version number or a date) */ public class Food extends Actor { /** * Act - do whatever the Food wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int count=0; public void act() { count++; if(count > 400) getWorld().removeObject(this); } }
Every time addFood comes up I get cannot find symbol-variable addFood
By lova30940, with 4 replies.
Last reply by lova30940, about 6 years ago:
Perfect
122
123
124
125
126
127
128
X