Hello,
I am making a game where the actor has to stay on screen as long as possible and not get touched by the balls. I have a timer that works, but when the ball touches the actor, the score (in seconds) should appear but what appears is only "your score : 0.0". How can I change the 0.0 and make it the actual score?
Here is my code for the timer class:
Can you help me please?
public class Timer extends Actor
{
private long startTime;
private long stopTime;
private long scoreTime;
private double elapsedTime;
private int a = 0;
private int b = 0;
GreenfootImage time;
private static double score;
public void act()
{
if (a == 0){
startTime = System.currentTimeMillis();
a = 1;
}
updateTime();
endTime();
}
private void updateTime()
{
stopTime = System.currentTimeMillis();
elapsedTime = (stopTime-startTime)/1000.0;
time = new GreenfootImage("Timer: " + new DecimalFormat("0.0").format(elapsedTime), 30, Color.WHITE, null, Color.BLACK); // makes the timer image, the decimal format makes the timer only have one decimal place (0.0) (you could do more if you do (0.00) etc.
setImage(time);
}
private void endTime(){
if (getWorld().getObjects(Player1.class).isEmpty()){
score = (scoreTime - startTime)/1000.0;
}
}
public static double getScore(){
return score;
}
}

