I'm trying to make a bar that switches to 3 other images as time goes while the button C is held down. However, the image doesn't switch. Can someone explain what went wrong?
Code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class fishingBar here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class fishingBar extends Actor
{
public static String[] bars = {"fishingBar0.png", "fishingBar1.png", "fishingBar2.png", "fishingBar3.png"};
private boolean isC = false;
/**
* Act - do whatever the fishingBar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int x, y, maxT = 3000;
SimpleTimer timer = new SimpleTimer();
public void act()
{
while(Greenfoot.isKeyDown("c")){
timer.mark();
isC = true;
//long prev = 0;
//long cur = System.currentTimeMillis()/1000;
if(timer.millisElapsed() > maxT + 50) {
setImage(new GreenfootImage(bars[0]));
timer.mark();
}
else if(timer.millisElapsed() >= 1000 && timer.millisElapsed() < 2000) setImage(bars[1]);
else if(timer.millisElapsed() >= 2000 && timer.millisElapsed() < 3000) setImage(bars[2]);
else if(timer.millisElapsed() >= 3000 && timer.millisElapsed() <= 3050) setImage(bars[3]);
}
getWorld().removeObject(this);
}
}
