protected void checkVerticalCollisions(Block block) { //if player is left of the block and colliding, move player back to the left if ((!this.isFalling) && (this.boundingBox.Right > block.boundingBox.Left) && (this.boundingBox.Right < block.boundingBox.Right)) { while ((this.boundingBox.Right > block.boundingBox.Left)) { this.position.X -= this.boundingBox.Right - block.boundingBox.Left; } } //if player is right of the block and colliding, move player back to the right if ((!this.isFalling) && (this.boundingBox.Left < block.boundingBox.Right) && (this.boundingBox.Left > block.boundingBox.Left)) { while ((this.boundingBox.Left < block.boundingBox.Right)) { this.position.X += block.boundingBox.Right - this.boundingBox.Left; } } }
protected void checkHorizontalCollisions(Block block) { //if player is on top of block move player up (don't let player fall through a block) if ((this.isFalling) && (this.boundingBox.Bottom > block.boundingBox.Top)) { if (!this.isJumping) { this.isFalling = false; //move player up based on how much overlap there is between player's boundingBox and the block's boundingBox while ((this.boundingBox.Bottom > block.boundingBox.Top)) { this.position.Y -= (this.boundingBox.Bottom - block.boundingBox.Top); } this.isStanding = true; } } }