I am currently working on a relatively simple platform game that has an odd bug.
You start the game by falling onto the ground (you spawn a few blocks above the ground), but when you land your feet get stuck INSIDE the world and you can't move until you jump.
Here's what I mean:

http://i.imgur.com/IKLZY.png

The player's feet are a few pixels below the ground level. However, this problem only occurs in 3 places throughout the map and only in those 3 select places. I'm assuming that the problem lies within my collision detection code but I'm not entirely sure, as I don't get an error when it happens.

public boolean isCollidingWithBlock(Point pt1, Point pt2) { 
//Checks x  
    for(int x = (int) (this.x / Tile.tileSize); x < (int) (this.x / Tile.tileSize + 4); x++) {
//Checks y
    for(int y = (int) (this.y / Tile.tileSize); y < (int) (this.y / Tile.tileSize + 4); y++) {
        if(x >= 0 && y >= 0 && x < Component.dungeon.block.length && y < Component.dungeon.block[0].length) {
//If the block is not air
            if(Component.dungeon.block[x][y].id != Tile.air) {
                //If the player is in contact with point one or two on the block 
                if(Component.dungeon.block[x][y].contains(pt1) || Component.dungeon.block[x][y].contains(pt2)) {
//Checks for specific blocks 
                    if(Component.dungeon.block[x][y].id == Tile.portalBlock) {
                        Component.isLevelDone = true;
                    } 
                    if(Component.dungeon.block[x][y].id == Tile.spike) {
                        Health.health -= 1;
                        Component.isJumping = true;

                        if(Health.health == 0) {
                            Component.isDead = true;
                        }
                    }
                    return true;
                }
            } 
        }
    }
}

return false;
}

What I'm asking is how I would fix the problem. I've looked over my code for quite a while and I'm not sure what's wrong with it. Also, if there's a more efficient way to do my collision checking then please let me know!

I hope that is enough information, if it's not just tell me what you need and I'll be sure to add it.

Thank you!

[EDIT] Jump code:

if(!isJumping && !isCollidingWithBlock(new Point((int) x + 2, (int) (y + height)), new Point((int) (x + width + 2), (int) (y + height)))) {
        y += fallSpeed;
//sY is the screen's Y.  The game is a side-scroller
        Component.sY += fallSpeed;
    } else {
        if(Component.isJumping) {
            isJumping = true;
        }
    }

if(isJumping) {
        if(!isCollidingWithBlock(new Point((int) x + 2, (int) y), new Point((int) (x + width + 2), (int) y))) {
            if(jumpCount >= jumpHeight) {
                isJumping = false;
                jumpCount = 0;
            } else {
                y -= jumpSpeed;
                Component.sY -= jumpSpeed;

                jumpCount += 1;
            }
        } else {
            isJumping = false;
            jumpCount = 0;
        }
    }
share|improve this question
I would be glad to help. However it would be nice to see more comments on the code. For instance, what is pt1, pt2. Why are you checking between this.x/tileSize and this.x /tileSize + 4 and so forth. Also I doubt the problem is in collision detection. It is far more likely in collision handling. – Arthur Wulf White Oct 12 at 18:37
You probably return true in some collision case and then handle it in a way that results in it returning true in the next frame. Meaning you are not pushing the character out of the collision area. – Arthur Wulf White Oct 12 at 18:39
I agree with @Athur. I suspect the problem is elsewhere. However your for loops have very strange guards. What are you iterating against? Can we see your jump code? – Ken Oct 12 at 18:41
I'm not sure what you man by handle it. That is the only collision code that determines whether the player can move or not, the other stuff is just for jumping and animation. In other words: I have no idea how to push the character out of the collision area. =\ – Connor Oct 12 at 18:42
I think this is too localized for the site. Check the numerous related questions on the side for plenty of other 2D platformer collision issues. – Byte56 Oct 12 at 19:23
show 1 more comment
feedback

closed as too localized by Byte56, Tetrad Oct 12 at 19:31

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.