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
testing
By hafizz.hnn, with no replies.
import greenfoot.*; public class MyWorld extends World { public MyWorld() { super(800, 600, 1); // Spawn 50 orang normal for (int i = 0; i < 50; i++) { addObject( new People(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()) ); } // Spawn 1 orang infected secara random People infected = new People(); infected.setInfected(true); addObject(infected,Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight())); // Spawn ambulance addObject(new Ambulance(), 0, 0); } } ============================================= import greenfoot.*; public class Ambulance extends Actor { private int speed = 5; private int stepDown = 30; private boolean movingRight = true; public void act() { moveZigZag(); healPeople(); } private void moveZigZag() { if (movingRight) { setLocation(getX() + speed, getY()); if (getX() >= getWorld().getWidth() - 1) { movingRight = false; setLocation(getX(), getY() + stepDown); } } else { setLocation(getX() - speed, getY()); if (getX() <= 0) { movingRight = true; setLocation(getX(), getY() + stepDown); } } // Jika sudah mencapai bawah, kembali ke atas if (getY() >= getWorld().getHeight() - 1) { setLocation(getX(), 0); } } private void healPeople() { People p = (People)getOneIntersectingObject(People.class); if (p != null && p.isInfected()) { p.setInfected(false); } } } ===================================================== import greenfoot.*; import java.util.List; public class People extends Actor { private boolean infected = false; private boolean immune = false; private int infectionTimer = 0; public People() { updateImage(); } public void act() { randomMove(); if (infected) { spreadInfection(); infectionTimer++; if (infectionTimer >= 200) { setImmune(true); } } } // Gerak random private void randomMove() { move(4); if (Greenfoot.getRandomNumber(100) < 20) { turn(Greenfoot.getRandomNumber(61) - 30); } if (isAtEdge()) { turn(180); } } // Menularkan ke orang yang disentuh private void spreadInfection() { List<People> people = getIntersectingObjects(People.class); for (People p : people) { if (p != this && !p.isImmune() && !p.isInfected()) { p.setInfected(true); } } } // Mengubah status infected public void setInfected(boolean status) { if (immune) return; infected = status; if (infected) { infectionTimer = 0; } else { infectionTimer = 0; } updateImage(); } public boolean isInfected() { return infected; } // Mengubah menjadi immune public void setImmune(boolean status) { immune = status; if (immune) { infected = false; infectionTimer = 0; } updateImage(); } public boolean isImmune() { return immune; } // Mengganti gambar sesuai status private void updateImage() { if (immune) { setImage("immune.png"); } else if (infected) { setImage("infected.png"); } else { setImage("normal.png"); } } }
Space Haven Project
By schaeff_lu, with no replies.
hallo mein Project ist nicht in der richtigen Größe was kann ich tun um es zu spielen
need help
By arumsari, with 1 reply.
Replied to by danpost, 11 days ago:
arumsari wrote...
need help << Code Omitted >>
The only thing I see wrong with your codes is in the second line of the
prepareBoard
method, which should increment the column (
c
) value, not the row (
r
) value. Don't really know what you need help with. You need to explain (in English, please) what you are trying to do and how the execution is wrong.
Need Help
By ThatsNotCode, with 1 reply.
Replied to by danpost, 16 days ago:
ThatsNotCode wrote...
I can't figure out how to make my background change colors every ten seconds, if someone could help me that would be amazing
With a simple int timer field: (note that at normal running speed, act is run about 60 times per second; hence value used) <Code Omitted> If using a range of colors:
How do i make a Project to .jar
By Zildrion, with 4 replies.
Last reply by Zildrion, 29 days ago:
tysm!!!! it helps me alot. But i dont want the bar on the bottom T.T . Whatever i take what i get
boolean not changing
By bonyay, with 29 replies.
Last reply by bonyay, about 1 month ago:
danpost wrote...
bonyay wrote...
I think if this last error is solved, it will function?
My mistake. Line 28 should be: <Code Omitted> My last edit to
change
methods still stands as it should not matter which world is currently active here. The referencing bypasses that issue. And, it should have nothing to do with actor not in world as
act
method is not executed when not in world.
Between the time I posted that and your reply, I searched far and wide for a solution and ended up basically revamping a lot of the code. Good news tho
enemy help!
By An0n_N0mad14, with 10 replies.
Last reply by An0n_N0mad14, about 1 month ago:
thats fine, i appreciate u helping, but i think im gonna make it so that there are three hearts and if it hits an enemy that one heart gets removed
get random subclass?
By bonyay, with 1 reply.
Replied to by danpost, about 1 month ago:
bonyay wrote...
I was wondering if there was any way to get a random subclass? like, say i had a subclass of actor and then 3 subclasses of that subclass, and i wanted to select a random one of those 3 to display on the screen. is that possible?
Here is an example method using mock class names. The return type can be modified to be the parent class name.
issues with score and intersecting using "child classes"
By bonyay, with 2 replies.
Last reply by bonyay, about 1 month ago:
I eventually figured it out myself (obviously, first post had that upload time delay), but thank you for the reply anyways!
how do I program hearts that act as lives ?
By shouldijuststartprayingatpquestion, with 1 reply.
Replied to by danpost, about 1 month ago:
shouldijuststartprayingatpquestion wrote...
I wanna add Hearts that function as Lives into my game and I have done that by creating three different heart actors (Named Heart, Heartt and Hearttt) but now I want those Hearts to disappear if my Player touches an object (in this Case a bomb) and reappear when my player touches another object (in this case a strawberry). Can anyone help me with how I could make it so if my player touches a bomb one heart disappears and if my player touches a strawberry one heart reappears ?? (This post is genuinely my last try, I have looked all over the internet ho
I'm new
By H_Ebb741, with 2 replies.
Last reply by unathimasina326@gmail.com, about 1 month ago:
I’m here for my coding and robotics project I’m in grade9
how to share to jar
By john_hackermann, with 1 reply.
Replied to by danpost, 2 months ago:
john_hackermann wrote...
soo i want to export a project to jar but the applecation tab isnt existent
In my version of Greenfoot, that action is performed via the
Application
tab upon clicking
Share
.
timer issue
By Haelena, with 1 reply.
Replied to by danpost, 2 months ago:
Haelena wrote...
I want to use an int timer for jumping animation (see the example of wished result in jabka.wip on my page, precisely on the jump to the left (I used delay() there, which now I want to avoid). However, the timer doesn't work at all. Any ideas of how to fix it? << Codes Omitted >>
It seems you have coded an entire jump into one act step. You have coded the act method too generally. It needs to provide what needs to be done at any one moment. A jump command (by keyboard activation) should start a jump. The jump must be controlled through multiple act steps. You may
Pulling the Code for my Game
By HaloToxin, with 1 reply.
Replied to by danpost, 4 months ago:
HaloToxin wrote...
Hi there! I'm coming back to Greenfoot after 13 years to try to get my game IceFisher to a working state, and I wanted to see if I could pull the project from the site down to my local. Is there a way that I can do that?
You apparently made the code available when you uploaded the scenario. Just go to the scenario page and click on the big green link (under your user image) that says "Open in Greenfoot". Move the downloaded folder to your 'scenarios' folder, open greenfoot app and select it (the downloaded folder) to open. Your original scenario folder should then
How do i make it so the player kepts their horizontal velocity when they were moving on the ground, but cant change horizontal velocity midair?
By JosukeHigashikata, with 3 replies.
Last reply by danpost, 4 months ago:
JosukeHigashikata wrote...
I did try that, but it didnt work and im not sure what is wrong heres my code for the characters: << Codes Omitted >>
Maybe you should take a look at the codes in my
Jump and Run Demo w/Moving Platform
scenario. You can run the scenario and look at the codes from within it (buttons along bottom of scenario window while running it).
1
2
3
4
X