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
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(); } } }
Why does this cause an IllegalStateException?
By davkri22, with 2 replies.
Last reply by davkri22, over 6 years ago:
Nevermind, the error was really coming from my tower constructor but greenfoot did not show me.
My Checkmarks won't go away
By Chris498, with 9 replies.
Last reply by danpost, over 6 years ago:
Chris498 wrote...
But is the
while
loop the problem? Because if not, i would prefer to keep the code to things that I fully understand
It is not down-right wrong. It is just more CPU extensive because you unnecessarily repeat a process that does not have a need to do so.
how could i make a health bar without a counter
By SanjiNaha, with 4 replies.
Last reply by SanjiNaha, over 6 years ago:
when the guy punches the other guy it should change, not randomly thanks
If i want to remove a object when it touches the World Edge the game crashes
By BimBom46, with no replies.
<Code Omitted> When it crashes, it says : java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. Under that are two red marked text : at Bullet.Spielerentfernen1(Bullet.java:26) at Bullet.act(Bullet.java:21)
For Jak
By SanjiNaha, with no replies.
i kill turtle bois if(isAtEdge()) { World MyWorld = getWorld(); MyWorld.removeObject(this); } else if(isTouching(Pxl2.class)) { World MyWorld = getWorld(); MyWorld.removeObject(this); } else if(isTouching(Wall.class)) { World MyWorld = getWorld(); MyWorld.removeObject(this); } else if(isTouching(Ball2.class)) { World MyWorld = getWorld(); MyWorld.removeObject(this); }
The Object is not getting removed
By BimBom46, with 1 reply.
Replied to by Super_Hippo, over 6 years ago:
Do you call the method from your act method?
what is wrong wit my code?
By SanjiNaha, with 5 replies.
Last reply by danpost, over 6 years ago:
SanjiNaha wrote...
<< Error Trace Omitted >>
That error was not produced with the code given above. What is your revised code that this came from?
Need help
By N1C0, with 1 reply.
Replied to by danpost, over 6 years ago:
N1C0 wrote...
i want to create two objects with a delay of 5000 in between << Code Omitted >>
Is the entire scenario to be paused until both are created? If not, then you cannot use the
delay
method. you would need to use an int timer field.
Numbers keeps increasing
By trevo, with 9 replies.
Last reply by danpost, over 6 years ago:
trevo wrote...
And the numbers represent which target it goes to. I couldn't figure out how to make it stop increasing.
If the target for a projectile is fixed, why did you add lines that change the number?
Saving the world moves objects
By Tietie12, with 8 replies.
Last reply by danpost, over 6 years ago:
Tietie12 wrote...
i know it is possible to continue with this method but it makes it incredibly slow opposed to not having too
Makes what slow -- the running of the scenario or the coding of it?
Greenfoot bug or am I dumb?
By CarolK, with 2 replies.
Last reply by CarolK, over 6 years ago:
Ok, so it was the second option... Thank you! I can not believe I forgot about it
150
151
152
153
154
155
156
X