First, in your example you do:
if(isColliding == true)
Where isColliding
is calculated?
An easy way to check for collision in a tiled environment is to check the tile facing the player e.g if the player wants to move up and if he's currently on tile x,y
, you will check if the tile x,y-1
is a blocking tile (is not AIR
in your case, i suppose).
The above method only works if the player have the size of the tiles and if the player move tile by tile, and it does not seem to be your case.
If your player has a totally different size than your tiles and/or can move more/less than TILE_SIZE
per frame, you will need to use a bit more complex approach (also described herehere).
Basically, you need to create a new Shape for each of your game entities and keep them in a kind of Collection and each time your player move, proceed all the shapes in this collection and check if one of them intersect with your player's shape.
public Class CollisionSystem {
public static List<Shape> collidingShapes = new...
public static boolean checkPlayerCollision(Shape playerShape) {
for (Shape s : collidingShapes) {
if (s.intersects(playerShape) {
//or do some more precise collision calculation here, like pixel perfect
return true;
}
return false;
}
It's a really simplified example since in a real case you will probably need to update position of the shapes for moving entities.