I am trying to get my vehicle class cars to reduce and show up one car per lane instead of 1000 on the screen every time i move right and left of my main car. How can i do it. This is what i have.
in my world subclass
public void act()
{
if (countDown>0)
{
countDown--;
}else
{
int random=(int)(Math.random()* 7);
if (random ==0 ) lane = 51;
if (random ==1 ) lane = 115;
if (random ==2) lane = 189;
if (random ==3) lane = 256;
if (random ==4) lane = 328;
if (random ==5) lane = 398;
if (random ==6) lane = 480;
if (random ==7) lane = 550;
Vehicle v1 = new Vehicle();
addObject(v1, lane,7);
countDown = (int)(Math.random()* 5);
}
}
and in my Vehicle class i have
public class Vehicle extends Actor
{
private int speed;
private int count;
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(7, 8, clss);
return actor != null;
}
public void hit(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
public Vehicle()
{
speed = (int)(Math.random()* 10 );
}
/**
* Act - do whatever the Vehicle wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.mov
{
moveDown();
}
if(getY()>=getWorld().getHeight()-2)
{
getWorld().removeObject(this);
}
count++;
}
public void moveDown()
{
setLocation(getX(),getY()+speed);
}
}
