当前位置: 首页>>代码示例>>C++>>正文


C++ BBox::getLeft方法代码示例

本文整理汇总了C++中BBox::getLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ BBox::getLeft方法的具体用法?C++ BBox::getLeft怎么用?C++ BBox::getLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BBox的用法示例。


在下文中一共展示了BBox::getLeft方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void Enemy::update() 
{
	if (this->position[0] >= windowBox.getRight())
		this->position[0] = position[0] - (windowBox.getRight() - windowBox.getLeft());

	this->boundBox->minX = this->position[0] + this->minX;
	this->boundBox->maxX = this->position[0] + this->maxX;
	this->boundBox->minY = this->position[1] + this->minY;
	this->boundBox->maxY = this->position[1] + this->maxY;
}
开发者ID:majora2007,项目名称:ComputerGraphics,代码行数:10,代码来源:Enemy.cpp

示例2: checkCollision

//circle(zombie) to rectangle collision detection
bool Zombie::checkCollision(std::vector<BBox>* boxes, float p_x, float p_y){
	BBox box;
	Point A = Point(this->getX(), this->getY());
	Point B;
	for(int i = 0; i<boxes->size();i++){
		box = boxes->at(i);

		//finds a point on the rectangles bounding box and that point acts as a circle with a radius 0 radius
		if(box.getRight() < this->getBox().getLeft())
			B.setX(box.getRight());
		else if(box.getLeft() > this->getBox().getRight())
			B.setX(box.getLeft());
		else
			B.setX(this->getX());

		if(box.getTop() < this->getBox().getBottom())
			B.setY(box.getTop());
		else if(box.getBottom() > this->getBox().getTop())
			B.setY(box.getBottom());
		else
			B.setY(this->getY());


		float difx = (B.getX() - A.getX()) * (B.getX() - A.getX());
		float dify = (B.getY() - A.getY()) * (B.getY() - A.getY());

		float dist = difx + dify;
		if(dist <= this->getRadius() * this->getRadius()){
		
		//FOLLOWS THE EDGES OF BOX TO REACH the player

			//if zombie is on below or above the box
			if((this->getBox().getBottom() > box.getTop() ||
				this->getBox().getTop()  < box.getBottom())
			){
					//IF ON TOP
				if(this->getBox().getBottom() > box.getTop()){
					if(p_x == this->getX()){
						this->angle = 0;
					}
					//if player is on the right of the zombie
					else if(p_x > this->getX()){
						//if the player is positioned higher than the zombie
						if(this->getY() < p_y)
							this->angle = 8;
						else
							this->angle = 0;
						//if player is on the left of the zombie
					}else {
						//if the player is positioned higher than the zombie
						if(this->getY() < p_y)
							this->angle = 172;
						else
							this->angle = 180;
					}
					//IF BELOW THE BOX
				}else if(this->getBox().getTop() < box.getBottom()){
					if(p_x == this->getX()){
						this->angle = 0;
					}
					//if player is on the right of the zombie
					else if(p_x > this->getX()){
						if(this->getY() > p_y)
							this->angle = 352;
						else
							this->angle = 0;
						//if player is on the left of the zombie
					}else{
						if(this->getY() > p_y)
							this->angle = 188;
						else
							this->angle = 180;
					}
				}
		//if zombie is on left or right side of the box
		}else if((this->getBox().getRight() < box.getLeft() || this->getBox().getLeft() > box.getRight())
			){
		
				float up = box.getTop() - this->getY();
				float down = this->getY() - box.getBottom();
				//IF ON LEFT SIDE
				if(this->getBox().getRight() < box.getLeft()){	
						if(p_y == this->getY() ){
							this->angle = 90;
						}
						else if(p_y > this->getY()){
							if(this->getX() > p_x)
								this->turn(this->getX() - 16,box.getTop() +32);
							else
								this->turn(this->getX(),box.getTop() +32);
						}
						else{
							if(this->getX() > p_x)
								this->turn(this->getX() - 16,box.getBottom() -32);
							else
								this->turn(this->getX(),box.getBottom() - 32);	
					}

				}
//.........这里部分代码省略.........
开发者ID:Cagil,项目名称:topdown-shooter,代码行数:101,代码来源:Zombie.cpp


注:本文中的BBox::getLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。