Collision Testing - Questions

Hi

So I was working on my project, and I started collision testing for a tilemap. Now I ran into an issue… glitching through walls. When WASD movement is handled, if keys are clicked fast enough then collision testing doesn’t work.

Background:
Each tile has a rectangle for it’s region, and the player has it’s own region. For collision checking, I see if the regions intersect and the return that there was a collision.

Movement handling:
[icode] /**
* Handle movement for the player
*/
public void handleMovement(float speed){

	if(System.nanoTime() - stamp < 600000)
		return;
	stamp = System.nanoTime();
	// handle the coordinates
	Keyboard.poll();
	float x = 0.0f;
	float y = 0.0f;
	boolean left = false, top = false, right = false, bottom = false;
	if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
		y = speed;
		top = true;
    }
	if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
		y = -speed;
		bottom = true;
    }
	if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
		x = speed;
		left = true;
    }
	if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
		x = -speed;
		right = true;
    }
    // change movement
	int direction = convertDirection(left, right, top, bottom);
	if(!Collisions.isCollision(direction)){
		if(!Collisions.isCollision(direction)){
			camera.addToPosition(x, y);
		}
	} else {
		// back up
		camera.addToPosition(-x, -y);
	}
	if(direction > 0){
		if(Collisions.isCollision(direction)){
			if(Collisions.isCollision(direction)){
				camera.addToPosition(-x, -y);
			}
		} else {
			if(Collisions.isCollision(direction)){
				if(Collisions.isCollision(direction)){
					camera.addToPosition(-x, -y);
				}
			} else {
				// Nothing.
			}
		}
	}
	
}

[/icode]
[icode] /**
* Convert the four booleans to an integer
*/
public int convertDirection(boolean left, boolean right,
boolean top, boolean bottom){

	if(left){
		if(right){
			// Doubtully so
			return -1;
		} else {
			if(top){
				if(bottom){
					// Doubtully so
					return -1;
				} else {
					return 5;
				}
			} else {
				if(bottom){
					return 6;
				} else {
					return 1;
				}
			}
		}
	} else {
		if(right){
			if(top){
				if(bottom){
					// Doubtully so
					return -1;
				} else {
					return 8;
				}
			} else {
				if(bottom){
					return 7;
				} else {
					return 2;
				}
			}
		} else {
			if(top){
				if(bottom){
					// Doubtully so
					return -1;
				} else {
					return 4;
				}
			} else {
				if(bottom){
					return 3;
				} else {
					// Doubtully so
					return -1;
				}
			}
		}
	}
	
}

[/icode]

Any thoughts or suggestions would help :slight_smile: