示例#1
0
	void isColl(Blocks& _block) {
		if (getBoundingBox().intersects(_block.getBoundingBox())) {
			cout << "col" << endl;
			_block.setColor(sf::Color::Red);
			if (_spriteG.getPosition().y <= _block.getBoundingBoxTop()) {//up
				canMoveUp = false;
				MarioJumping = false;
				if (_spriteG.getPosition().x - 2 < _block.getBoundingBoxLeft() - 12) {
					MarioJumping = true;
					canMoveRight = false;
				}
				else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {
					MarioJumping = true;
					canMoveLeft = false;
				}
			}
			else if (_spriteG.getPosition().y  > _block.getBoundingBoxTop() - _block.getBoundingBoxHeight()) {
				_velocity.y = 5;
				MarioJumping = true;
			}
			else {

				if (_spriteG.getPosition().x < _block.getBoundingBoxLeft() - 12) {//Left

					canMoveLeft = false;
				}
				else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {//right
					canMoveRight = false;
				}
			}
		}
		else {
			canMoveRight = true;
			canMoveLeft = true;
			canMoveUp = true;
			if (canMoveUp == true)
				_velocity.y += gravity;
		}
	}