Before you say anything, I have googled this problem.
I’m getting an ArrayIndexOutOfBoundException every time my
int pX;
gets to 14/15. I do not understand why, because technically the
int[][] tileID = new int[15][20];
and the pX should refer to the 20. I do not know how to approach this problem, this is my code for moving my player, it includes a check to see if the player is on a tile it shouldn’t be on, which i believe is where the problem is coming from.
public void movePlayer(int pSX, int pSY)
{
// Set the previous positions of the x, y coordinates
prevX = pX;
prevY = pY;
// Set The Player Speed
pSpeedX = pSX;
pSpeedY = pSY;
// Move player then check if they are on a tile
if( pSY == 0)
{
pX += pSpeedX;
if( tiles.tileID[pY][pX] == 1)
{
pX = prevX;
pY = prevY;
}
}
if( pSX == 0)
{
pY += pSpeedY;
if( tiles.tileID[pY][pX] == 1)
{
pX = prevX;
pY= prevY;
}
}
}
I know I’m posting a lot, but I’m really not sure how to do these things