Ok, well. This did work. But I found no way to set the same image. I mean, the logic to set the image was numruta-1. But now numruta is 7 because it will follow a different path. So, How do I set the same image that the deleted car had?
private void crear()
{
int mantener=numruta; //don't really know if I can use numruta here, so I use this.
String[] colors = { "azul", "cyan", "amarillo", "verde", "rojo" };
Recolector recolectorContinuado = new Recolector();
getWorld().addObject(recolectorContinuado, 963, 265);
recolectorContinuado.setnumRuta(7);
recolectorContinuado.setRotation(90);
recolectorContinuado.setImage("camion"+colors[mantener-1]+".png");
}
public void moverse(){
direction = (Ruta.direcciones[numruta-1][progreso]);
if (pasos == valor[j])
{
String[] colors = { "azul", "cyan", "amarillo", "verde", "rojo" };
if ("Left".equals(direction)) turn(-90); else turn(90);
String suffix = getRotation() == 180 ? "left" : "";
if (numruta!=7) setImage("camion"+colors[numruta-1]+suffix+".png"); //because if numruta==7, it will throw an Index Borders exception
if (numruta==7){
GreenfootImage img=getImage(); // there is just one turn, so I don't do this upon a condition.
img.mirrorVertically();
}
pasos = 0;
progreso++;
j++;
}
}public void act()
{
startUp();
if (numruta != 0)
{
moverse();
move(1);
pasos++;
}
}
public void moverse()
{
if (pasos == valor[j])
{
String directions = Ruta.direcciones[5][progreso];
if ("Left".equals(directions)) turn(-90);
else if ("Right".equals(directions)) turn(90);
if (getRotation() == 180) setImage("camionleft.png"); else setImage("camion.png");
pasos = 0;
progreso++;
j++;
}
}