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
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
user info
By Roshan123, with 7 replies.
Last reply by danpost, about 6 years ago:
Roshan123 wrote...
is their any coding needs to be done to get the user info or without coding i can get just by clicking -- get data
User data does not store itself. You will need to decide the appropriate time that any info should be stored and produce code to store what information available for that user you want to store. Even then, only when storage is available (user is logged in and data server is accessible).
How to make a counter that counts every time my player collects a gem
By neoaspect, with 1 reply.
Replied to by danpost, about 6 years ago:
Your
karmengemEaten
field declared at line 5 in the
Karmen
class IS (apparently) the counter. What you want, I believe is an actor to display the counter value (or the state and its value -- like "
Gems: 0
"). A true
Counter
class will have the
int
field included within it (which is not what you show). What you show, however is okay. You just need a simple
Actor
object to display an image in your world that shows the state. Please refer to my
Value Display Tutorial
scenario for details.
Anyone know how to make a settings screen and/or High Score screen in Greenfoot?
By MYSTICPHOENIXXX, with no replies.
This is for a game that I have to create, and so some of the criteria that we have to fulfil and this includes having to make a high score screen and a settings screen. Can anyone help me?
Is there a way to get something to happen if there are no enemies on the world?
By MYSTICPHOENIXXX, with 25 replies.
Last reply by danpost, about 6 years ago:
Show code where shot enemies are removed from world and indicate where that code is located.
I am trying to add make it so that food keeps spawning every time the snake eats it.
By lova30940, with 6 replies.
Last reply by danpost, about 6 years ago:
lova30940 wrote...
Can you guys give me an example of how the code would look if it were right?
This post
describes your problem as well (very similar ideas with different details).
122
123
124
125
126
127
128
X