Hi, here's what I want to do:
Some Devices spawn from time to time in the world, and at a moment, they all stop and they aim at the ship I control by creating a series of little points (called DeviceLaser) going from the Devices to my ship. I succeeded in doing that, but the problem is that this "laser of points" only spawn from the last Device that have been created and I want that Every Device create a "laser of points" going from it to my ship (sorry for the repetitions).
Here's the code in my World:
Thanks :)
public void act()
{
createMonsters();
createDevices();
Options();
changeGround();
field();
Counter++;
beReady();
aim();
}
public void beReady()
{
if(Game.Counter>500 && Game.Counter%1000 == 0)
{
ready = true;
}
}
public void aim()
{
if(ready == true)
{
List<Devices> devices = getObjects(Devices.class);
for(Devices device: devices)
{
Actor gear3 = (Actor)getObjects(Gear3.class).get(0);
int xGear = gear3.getX();
int yGear = gear3.getY();
int xDevice = device.getX();
int yDevice = device.getY();
int dx = xGear-xDevice;
int dy = yGear-yDevice;
double length = Math.sqrt(dx*dx+dy*dy);
double xLength = dx/length;
double yLength = dy/length;
List<DeviceLaser> lasers = getObjects(DeviceLaser.class);
removeObjects(lasers);
for(int i=0; i<length; i++)
{
DeviceLaser devicelaser = new DeviceLaser();
addObject(devicelaser, (int)(device.getX()+i*xLength), (int)(device.getExactY()+i*yLength));
}
}
}
}


