Before you say anything, I have googled this problem.
I'm getting an ArrayIndexOutOfBoundException every time my
gets to 14/15. I do not understand why, because technically the
1
| 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public void movePlayer(int pSX, int pSY) { prevX = pX; prevY = pY; pSpeedX = pSX; pSpeedY = pSY; 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 :/