Try something like: '(double)(time/5)/10'
public class Road extends World
{
// Variables Defined
// PSH = Player Start Height
// PSH2 = Player 2 Start Height
// middle = middle of the world's width
// origin is the center height of the world
// TSP = Treasure Starting Point
// D2T = Distance 2 Treasure
int middle = getWidth() /2 - 10 ;//Subtracted 10 to make finish class coincide with grid background
int origin = getHeight() /2;
int ran1 = getHeight();
int ran2 = getWidth();
int PSH = getHeight() /4 + origin;// added origin to the equation to the current player spawn point
int P2SH = getHeight() /6;
int TSP = Greenfoot.getRandomNumber(ran2);
int D2T = TSP - middle;
/**
* Constructor for objects of class Road.
*
*/
public Road()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(2000, 200, 1);
FinishLine finishline = new FinishLine();
addObject(finishline, middle, origin);
Player player = new Player();
addObject(player, middle, PSH);
Player2 player2 = new Player2();
addObject(player2, middle, P2SH);
Treasure treasure = new Treasure();
addObject(treasure, TSP, PSH);
Treasure treasure2 = new Treasure();
addObject(treasure2, TSP, P2SH);
}
public int treasureDistance()
{
return D2T;
}
}ublic class Player2 extends Actor
{
private int limit = 1;
private int steps = 0;
private int time = 0;
private int distance;
/**
*
*/
public void act()
{
move();
}
public void move()
{
move(1);
steps = steps + 1;
if (steps == limit)
{
turn (180);
steps = 0;
limit = limit*2;
}
TouchingTreasure();
time = time + 1;
}
public void TouchingTreasure()
{
Actor treasure = getOneObjectAtOffset(0, 0, Treasure.class);
if (treasure !=null)
{
System.out.println("Good Job Player 2! You have found the Treasure after: " + time/60 + " Seconds" + " Distance: " + distance + " Pixels");
getWorld().removeObject (this);
}
}
public int getTime()
{
return time;
}
public void treasureDistance()
{
distance = ((Road)getWorld()).treasureDistance();
}
public int getDistance()
{
return distance;
}
}