Hi! I'm currently having trouble with accessing my Timer class in the world. I want to the world to access it so it will there will be increasing chances of spawning fastGhost and evilGhost as the Timer increases.
Here is the code for my Timer class.
Here is the spawnEnemy method in my world class.
I want to make it so that when the minute becomes 2, it will increase the chances of spawning fastGhost and evilGhost, and further increasing the chances as the minute goes up. I'm having trouble with accessing the Timer in the world class.
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 | public class Timer extends Actor { /** * Act - do whatever the timer wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public int minute; public int millisecond; public int second; private int counter = 1000 ; public void act() { time(); setImage ( new GreenfootImage(minute + ":" + second, 25 , Color.RED, Color.BLACK)); } public void time() { while (counter > 0 ) counter -= 1 ; if (counter == 0 ) { millisecond++; } if (millisecond == 60 ) { millisecond = 0 ; second++; } if (second == 60 ) { second = 0 ; minute++; } counter = 60 ; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public void spawnEnemy() { if (Greenfoot.getRandomNumber( 120 ) < 1 ) { int spawnPlace = Greenfoot.getRandomNumber( 8 ); int ghostType = Greenfoot.getRandomNumber( 60 ); Actor ghost = null ; if (ghostType < 45 ) ghost = new ghost(); else if (ghostType < 55 ) ghost = new fastGhost(); else ghost = new evilGhost(); addObject(ghost, 50 + 100 *spawnPlace, 40 ); } } |