i need help with a weird logic problem (kinda long topic)

Hello,
i’ve been working on my tiled map “system” and today i found a new a problem which is normally do because of a bad use of an “if statement”
here is the thing :
i have an aabb collision class :

public boolean aabb(double x1, double y1, double w1, double h1, double x2,
			double y2, double w2, double h2) {

		double cntrX1 = x1 + w1 / 2;
		double cntrY1 = y1 + h1 / 2;

		double cntrX2 = x2 + w2 / 2;
		double cntrY2 = y2 + h2 / 2;

		double distanceX = Math.abs(cntrX1 - cntrX2);
		double distanceY = Math.abs(cntrY1 - cntrY2);

		double sumWidth = (w1 / 2 + w2 / 2);
		double sumHeight = (h1 / 2 + h2 / 2);

		if (distanceX < sumWidth) {
			if (distanceY < sumHeight) {
				return true;
			}
		}
		return false;

	}

which i use to check collision between the player and the grid elements here :


private void collisionBooleans() {
		String[][] myWorld = world.getWorld();

		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				int blockX = x * 32;
				int blockY = y * 32;
				String block = myWorld[y][x];
				if (tool.aabb(hero.getX(), hero.getY(), hero.getWidth(),
						hero.getHeight(), blockX, blockY, 32, 32)) {
					System.out.println("world");
					if (block.equals("g")) {
						onGround = true;
						System.out.println("ground");
					} else {
						System.out.println("!ground");
						onGround = false;
					}
				}
			}

		}


just to give you an idea about “g” , this is my tile map file


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g   
g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g  g 


and this is how the game look

http://s20.postimg.org/4is9cyxx9/Capture.png

until now everything is fine, but once i draw another map elements (“g”)
the collision detection doesn’t work with the last drawn element for example :
i have create 3 blocks of type ground, if am on the 1st 2 of them (from the left) then everything is fine

http://s20.postimg.org/irrvv1cfx/image.png

but if am on the last one, it doesn’t work

http://s20.postimg.org/l7tp8vuil/image.png

now here is the weird part, i turned off the gravity and make the program print something only if am on the ground, and guess what, it does print even if am standing on the last block which doesn’t suppose to work

finally here is another 2 methods that you might need,
this one use the class CollisionBooleans to do stuff (gravity and jumping (jumping still doesn’t work ::slight_smile: ) )


private void collisionLogick() {

		if (onGround) {
			canJump = true;
		} else {
			heroY -= gravity * delta;
			canJump = false;
		}
		double jum = 0;
		if (jumping) {

			jum += 0.5;
			hero.setY(hero.getY() + jum);

		}

		
	}

and this is the player update method that i call in the main update method

private void heroUpdate() {
		control(delta);
		hero.setX(heroX);
		hero.setY(heroY);
		hero.setWidth(heroW);
		hero.setHeight(heroH);
		
		collisionBooleans();
		collisionLogick();

	}

thank you very much