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
Need Help with Arrays
By samnan22, with 3 replies.
Last reply by samnan22, over 6 years ago:
never mind, i got it!
reset except counter of the highscore
By realsaifalrawie, with 2 replies.
Last reply by realsaifalrawie, over 6 years ago:
ok thank you
How do i make one specific actor follow my mouse?
By Yuuki, with 10 replies.
Last reply by danpost, over 6 years ago:
Yuuki wrote...
What does constructor mean?
It is the block of code that is executed when you create a new instance of a class (a new object). The block looks similar to a method, but it does not have a return type given (nothing where "
void
" usually is) and its name is the same as the class. Your World subclass constructor starts with: <Code Omitted>My Fish class constructor above will execute when <Code Omitted>is found in your codee. Constructors automatically return the new object created. So, you would either assign the new object to a variab
Making a Counter
By mattstg, with 6 replies.
Last reply by mattstg, over 6 years ago:
danpost wrote...
danpost wrote...
Add a boolean to track touching the line and use it to regulate the scoring.
mattstg wrote...
How would I do that? Sorry I am a beginner
Perform checking car crossing line in your Car class (remove the checking from FinishLine class): <Code Omitted>
Thank you so much!
Adding a changing Scoreboard
By Carbon_Raven, with 2 replies.
Last reply by danpost, over 6 years ago:
In
changeScore
, create a text
GreenfootImage
object and set it to the image of the
Score
actor.
BB-Tan
By phipsi21, with 2 replies.
Last reply by Super_Hippo, over 6 years ago:
I once thought of creating a copy of it here but never did. But go ahead. You can do it. :)
How do I remove one object from the world?
By Bourgeoisie_Bird, with 8 replies.
Last reply by Bourgeoisie_Bird, over 6 years ago:
Hi, I think I might have come up with a solution but I'm having difficulty implementing it into code. I want to assign a value to the customer when it is added to the world increasing the assigned value by one every time a new customer is added. I also want to do the same for the drink. so if the customer with the assigned value of 1 intersects with a drink with assigned number 1 the assigned values go down by one and remove the intersecting drink .customer2 would become customer1 and drink2 would become drink1. If customer1 assigned value was zero it will ignore other drinks that interse
How to add multiple instances with animations coming from the both sides of the screeen
By Adrian26, with 1 reply.
Replied to by danpost, over 6 years ago:
Will need to see World subclass and Bat class codes.
How to add gravity when you only jump
By SPIDERVERSEE, with 1 reply.
Replied to by danpost, over 6 years ago:
SPIDERVERSEE wrote...
Do you guys know how to code gravity so that, it will only be in use when you actually jump? And that it will fall to the place where you jumped? I made a game like crossy road, but I don't know how to code the jump.
Instead of
getKey
, use
isKeyDown
with a
boolean
field to track the state of the "space" key. That way, you can regulate it so that the key is released between each jump.
what is wrong with my code
By SanjiNaha, with 4 replies.
Last reply by SanjiNaha, over 6 years ago:
i have already solved the problem thank you so much though
Dark mode ?
By uniqe1, with 1 reply.
Replied to by SanjiNaha, over 6 years ago:
no
How do i change my background with a button
By Yuuki, with 16 replies.
Last reply by danpost, over 6 years ago:
danpost wrote...
Keep a reference field to the original actor in your world class so you can get its location easily when needed.
Yuuki wrote...
What does that mean though?
Add a field to your
World
subclass to retain the actor: <Code Omitted>Assign the actor to the field so later you can get its location: <Code Omitted>
How i do get this acotr to spawn a set distance away from another actor, but that "area" has to get closer over time :p
By Yuuki, with no replies.
Uhh, *input Jojo refrence here * <Code Omitted> my player is here <Code Omitted> While I'm here, ill explain the problems that i have, one is that the actor grows but it loss its original shape, how can i change that, and my second question is how do i get my attac to spawn at random times, here is the other codes if you need it. <Code Omitted> and my defend code <Code Omitted> Ok, use your stando powers and help me please thank you.
Inventory
By Helpard_With_A_Stick?, with 9 replies.
Last reply by danpost, over 6 years ago:
Helpard_With_A_Stick? wrote...
I don't have a class for my player.... you are the player, its like an escape room game.
What is the name of your initial world and is it a game world or a pre-game world?
can you fix my code
By SanjiNaha, with no replies.
/** * Write a description of class Pxl2 here. * * @author (your name) * @version (a version number or a date) */ public class Pxl2 extends Actor { private int vSpeed = 0; private int acceleration = 1; private int jumpHeight= - 8; Ball2 ball2 = new Ball2(); Wall wall = new Wall(); /** * Act - do whatever the Pxl2 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { movement(); checkFall(); images(); fireball(); fireWall(); dead(); } /** * This method lets the character move */ public void movement() { int y = getY(); int x = getX(); if(Greenfoot.isKeyDown("left")) { move(-5); } if(Greenfoot.isKeyDown("right")) { move(5); } if(Greenfoot.isKeyDown("up")) { jump(); } } /** * changes the images for the fighting */ public void images() { if(Greenfoot.isKeyDown("/")) { setImage("Rival-punch.png"); } else { setImage("Rival-1.png"); } if(Greenfoot.isKeyDown(".")) { setImage("Rival-kick.png"); } if(Greenfoot.isKeyDown("left")) { setImage("Rival-move-forward.png"); } if(Greenfoot.isKeyDown("right")) { setImage("Rival-move.png"); } } /** * makes the character jump */public void jump() { vSpeed= -5; gravity(); } /** * makes the character fall */ public void checkFall() { if(onGround()) { vSpeed = 0; } else { gravity(); } } /** * makes the fall look real */ private void gravity() { setLocation(getX(), getY() +vSpeed); vSpeed = vSpeed + acceleration; } /** * makes the character land on the ground */ public boolean onGround() { Actor under = getOneObjectAtOffset(0,getImage().getHeight()/2,Ground.class); return under != null; } /** * makes the character shoot the fireball */ public void fireball() { if (Greenfoot.isKeyDown("'")) { setImage("Rival-punch.png"); World MyWorld = getWorld(); MyWorld.addObject(ball2, 0, 0); ball2.setLocation(getX(), getY()); ball2.setRotation(getRotation()); } } /** * special ability activate. makes a fire wall */ public void fireWall() { if (Greenfoot.isKeyDown("0")) { setImage("Rival-punch.png"); World MyWorld = getWorld(); MyWorld.addObject(wall, 0, 0); wall.setLocation(getX(), getY()); wall.setRotation(getRotation()); } } public void dead() { if(isTouching(Giant.class)) { removeTouching(Giant.class); } } public void hitByFire() { Actor Fire2 = getOneObjectAtOffset(10, 10, Fire.class); if(Fire.class != null) { World world = getWorld(); MyWorld myWorld = (MyWorld)world; healthBar healthBar = MyWorld.getHealthBar(); healthBar.loseHealth(); } } }
149
150
151
152
153
154
155
X