I am working on a game where the user can make their own map out of pre made squares with a track on them. The car that will travel along the track needs to be able to find the next square so it knows what track to follow. i am attempting to do this using the getObjectsAt, everything compiles but starts it starts throwing pointer exceptions when it comes time to load the next piece. What i am trying to do is check for each type of track piece. the method calls are correct, when i run to in debug it fails at the "rawInfo =" line, i don't think i am getting a list of objects.
private void loadTrack()
{
if (Math.abs(xList[29]-xList[28])>Math.abs(yList[29]-yList[28]))
{
if(xList[29]>xList[28])
{
nextX= xList[29]+10;
nextY= yList[29];
}
else
{
nextX= xList[29]-10;
nextY= yList[29];
}
}
else
{
if(yList[29]>yList[28])
{
nextY= yList[29]+10;
nextX= xList[29];
}
else
{
nextY= yList[29]-10;
nextX= xList[29];
}
}
if(getWorld().getObjectsAt(nextX,nextY,Start.class)!=null)
{
rawInfo =((Start) getWorld().getObjectsAt(nextX,nextY,Start.class).get(0)).getLaneInfo(nextLane);
trackType =((Start) getWorld().getObjectsAt(nextX,nextY,Start.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,StraitLR.class)!=null)
{
rawInfo =((StraitLR) getWorld().getObjectsAt(nextX,nextY,StraitLR.class).get(0)).getLaneInfo(nextLane);
trackType =((StraitLR) getWorld().getObjectsAt(nextX,nextY,StraitLR.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,StraitUD.class)!=null)
{
rawInfo =((StraitUD) getWorld().getObjectsAt(nextX,nextY,StraitUD.class).get(0)).getLaneInfo(nextLane);
trackType =((StraitUD) getWorld().getObjectsAt(nextX,nextY,StraitUD.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,CurveLD.class)!=null)
{
rawInfo =((CurveLD) getWorld().getObjectsAt(nextX,nextY,CurveLD.class).get(0)).getLaneInfo(nextLane);
trackType =((CurveLD) getWorld().getObjectsAt(nextX,nextY,CurveLD.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,CurveLU.class)!=null)
{
rawInfo =((CurveLU) getWorld().getObjectsAt(nextX,nextY,CurveLU.class).get(0)).getLaneInfo(nextLane);
trackType =((CurveLU) getWorld().getObjectsAt(nextX,nextY,CurveLU.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,CurveRD.class)!=null)
{
rawInfo =((CurveRD) getWorld().getObjectsAt(nextX,nextY,CurveRD.class).get(0)).getLaneInfo(nextLane);
trackType =((CurveRD) getWorld().getObjectsAt(nextX,nextY,CurveRD.class).get(0)).getTrackType();
}
if(getWorld().getObjectsAt(nextX,nextY,CurveRU.class)!=null)
{
rawInfo =((CurveRU) getWorld().getObjectsAt(nextX,nextY,CurveRU.class).get(0)).getLaneInfo(nextLane);
trackType =((CurveRU) getWorld().getObjectsAt(nextX,nextY,CurveRU.class).get(0)).getTrackType();
}
nextLane = rawInfo[0][0];
xList = rawInfo[1];
yList = rawInfo[2];
speedList = rawInfo[3];
angleList = rawInfo[4];
}
