I got this game where my ship has to avoid barrels. But the barrels are comming with 4 at once.. is it possible to set an interval between the spawning barrels? My code looks like this at the moment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class barrel here. * * @author (your name) * @version (a version number or a date) */ public class barrel extends Actor { /* Act - do whatever the barrel wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment.*/ public void act() { if (isGeraakt()) { removeHealth(); getWorld().removeObject( this ); return ; } int x = Greenfoot.getRandomNumber( 2 ); move(-x); if (atWorldEdge()) getWorld().removeObject( this ); } public void removeHealth() { BotenUpgrade subWorld = (BotenUpgrade) getWorld(); heart heartObject = (heart) subWorld.getObjects(heart. class ).get( 0 ); heartObject.adjustValue(- 1 ); if (heartObject.getValue() == 0 ) removeLive(); } public boolean isGeraakt() { boolean raak = false ; Actor r = getOneObjectAtOffset( 0 , 0 ,boot. class ); if ( r != null ) { raak = true ; } return raak; } public boolean atWorldEdge() { return getX() == 0 || getX() == getWorld().getWidth() - 1 || getY() == 0 || getY() == getWorld().getHeight() - 1 ; } public void removeLive() { int lives = getWorld().getObjects(heart. class ).size(); getWorld().removeObject((Actor)getWorld().getObjects(heart. class ).get(lives- 1 )); if (lives != 1 ) { // } else { Greenfoot.setWorld( new GameOver()); } } } |