Advertisement
Guest User

dragon tale fix

a guest
Jun 14th, 2014
6,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Going outside of the map will give you an out of bounds exception. Here's the fix.
  2.  
  3. 1)
  4.  
  5. Add these two methods to TileMap.
  6.  
  7. public class TileMap {
  8. ...
  9. public int getNumRows() { return numRows; }
  10. public int getNumCols() { return numCols; }
  11. ...
  12. }
  13.  
  14. ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
  15.  
  16. 2)
  17.  
  18. Change calculateCorners() in MapObject to this:
  19.  
  20. public void calculateCorners(double x, double y) {
  21. int leftTile = (int)(x - cwidth / 2) / tileSize;
  22. int rightTile = (int)(x + cwidth / 2 - 1) / tileSize;
  23. int topTile = (int)(y - cheight / 2) / tileSize;
  24. int bottomTile = (int)(y + cheight / 2 - 1) / tileSize;
  25. if(topTile < 0 || bottomTile >= tileMap.getNumRows() ||
  26. leftTile < 0 || rightTile >= tileMap.getNumCols()) {
  27. topLeft = topRight = bottomLeft = bottomRight = false;
  28. return;
  29. }
  30. int tl = tileMap.getType(topTile, leftTile);
  31. int tr = tileMap.getType(topTile, rightTile);
  32. int bl = tileMap.getType(bottomTile, leftTile);
  33. int br = tileMap.getType(bottomTile, rightTile);
  34. topLeft = tl == Tile.BLOCKED;
  35. topRight = tr == Tile.BLOCKED;
  36. bottomLeft = bl == Tile.BLOCKED;
  37. bottomRight = br == Tile.BLOCKED;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement