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
What is happening right now?
Latest Scenarios
Project Space H...
Demo Jump and Run
Bob Lutas
Flappy Kong
Street World - ...
BinaryGame
more
Popular Scenarios
Gundala Adventure
Trash Clash Roy...
LegendOfGreenfoot
Chess Board
Meeresszenario_...
wizard_advanture
more
Popular Users
more
Popular Collections
Optical Illusions
Reusable actors...
Scenario showcase
Demos by danpost
more
Update: Project Space Haven
By schaeff_lu - 1 day ago
Indie Space Shooter developed in Informatik
New Scenario: Demo Jump and Run
By nico1107 - 2 days ago
New Scenario: Bob Lutas
By aluno.tech4me - 3 days ago
New Scenario: Flappy Kong
By aluno.tech4me - 3 days ago
New Scenario: Street World - Retro Coders
By aluno.tech4me - 4 days ago
New Scenario: BinaryGame
By ostvest - 4 days ago
Test your binary convertion knowledge
New Scenario: NOVA-RUN
By ostvest - 4 days ago
Platformer game for a school project
Update: Casino
By EierVogelGame - 5 days ago
Comment on Pengu
By Nosson1459 - 5 days ago
finally got around to fixing this
Update: Pengu
By Nosson1459 - 5 days ago
Platform Jumper
New Scenario: Retro Coders
By aluno.tech4me - 5 days ago
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"); } } }
X
Comment on Pengu