Hi, I'm creating a simple puzzle game where you click on a sphere of a color and it removes the same colored spheres next to it (think diamond mine) and I'm having some problems generating a list of spheres for removal the code I have at the moment just creates a continuous loop
List<Vector3f> ballPicked = Collections.synchronizedList(new ArrayList<Vector3f>());
ballPicked.clear();
// Check if a ball was clicked
if (pr.getNumber() != 0)
{
// Get the clicked ball's colour, geometry and position
ballColor = pr.getPickData(0).getTargetMesh().getParentGeom().getRenderState(RenderState.RS_MATERIAL);
ballGeom = pr.getPickData(0).getTargetMesh().getParentGeom();
ballPicked.add(pr.getPickData(0).getTargetMesh().getParentGeom().getLocalTranslation());
// Loop though the ballPicked array
while (ballPicked.listIterator().hasNext() == true) {
// Set the iterator element to ballOrigin
Vector3f ballOrigin = ballPicked.listIterator().next();
if (ballPicked.listIterator().previous() != ballOrigin)
{
System.out.println(ballPicked.listIterator().hasNext());
// Cast ray from picked ball towards positive x
Ray ballRay1 = new Ray(ballOrigin, new Vector3f(1,0,0));
// Cast ray from picked ball towards positive y
Ray ballRay2 = new Ray(ballOrigin, new Vector3f(0,1,0));
// Cast ray from picked ball towards negative x
Ray ballRay3 = new Ray(ballOrigin, new Vector3f(-1,0,0));
// Cast ray from picked ball towards negative y
Ray ballRay4 = new Ray(ballOrigin, new Vector3f(0,-1,0));
// Find the balls in all four directions
rootNode.findPick(ballRay1, bpr);
rootNode.findPick(ballRay2, bpr);
rootNode.findPick(ballRay3, bpr);
rootNode.findPick(ballRay4, bpr);
for (int d = 0; d < bpr.getNumber(); d++)
{
float distance = bpr.getPickData(d).getDistance();
if (distance < 96 && distance > 33 && ballColor == bpr.getPickData(d).getTargetMesh().getParentGeom().getRenderState(RenderState.RS_MATERIAL))
{
rootNode.detachChild(ballGeom);
rootNode.detachChild(bpr.getPickData(d).getTargetMesh().getParentGeom());
ballPicked.add(bpr.getPickData(d).getTargetMesh().getParentGeom().getLocalTranslation());
}
}
bpr.clear();
}
}
}
}
Any ideas on how to fix this or should it be scrapped in favor of something better?
Thanks.