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


C++ Portal::checkCollision方法代码示例

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


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

示例1: physics

void physics(Game *g)
{
	g->mouseThrustOn=false;

	//ball collision
	if(gameStarted){
		ball.setYVel(ball.getYVel());
		ball.setXVel(ball.getXVel());
		obstacle->setYVel(obstacle->getYVel());
		bool is_ball_hit_edge = ball.checkCollision(xres, yres);
		if (is_ball_hit_edge){
			lastPaddleHit = 'N';
		}
	}


	//paddle collision
	bool isLeftHit = paddle1.checkCollision(yres, ball);
	if (isLeftHit){
		lastPaddleHit = 'L';        
	}
	bool isRightHit = paddle2.checkCollision(yres, ball);
	if (isRightHit){
		lastPaddleHit = 'R';        
	}

	if(level == 2){
		obstacle->checkCollision(xres, yres, ball, p1);
	}


	//paddle1 movement
	paddle1.setYVel(paddle1YVel);

	//paddle2 movement
	paddle2.setYVel(paddle2YVel);

	if (level == 1 && hud->isPaused()==false){
		//SET BOMBS POSITION:         
		bomb_theta = bomb_theta + speed_theta;
		if (fabs(bomb_theta) >= 2*PI){
			bomb_theta=0;
			speed_theta *= -1;
		}
		bomb_posx=(int)(xres/2 + bomb_radius*cos(bomb_theta - PI/2) - bomb_width/2);
		bomb_posy=(int)(yres/2 + bomb_radius*sin(bomb_theta - PI/2) - bomb_height/2);

		//CHECK LEFT COLLISION WITH BOMB:
		if ((beginSmallLeftPaddle + smallLeftPaddleTime) < time(NULL)){
			paddle1.setHeight(100.0f);
			bool isBallBetweenX = (ball.getXPos() > bomb_posx) && (ball.getXPos() < (bomb_posx + bomb_width));
			bool isBallBetweenY = (ball.getYPos() > bomb_posy) && (ball.getYPos() < (bomb_posy + bomb_height));
			if (lastPaddleHit == 'L' && (isBallBetweenX && isBallBetweenY)){
				bombBegin = time(NULL);
				createSound(8);
				createSound(9);
				//set to half normal height:            
				paddle1.setHeight(60.0f);
				if (hud->getPlayer1Health()>0){
					hud->setPlayer1Health(hud->getPlayer1Health()-10*(1+random(8)));
					//GAMEOVER:
					if (hud->getPlayer1Health() <= 0){
						createSound(5);
						is_gameover = true;
						ball.setXVel(0.0f);
						ball.setYVel(0.0f);
						stopGame();
					}
				}
				beginSmallLeftPaddle = time(NULL);
			}
		}

		//CHECK RIGHT COLLISION WITH BOMB:
		if ((beginSmallRightPaddle + smallRightPaddleTime) < time(NULL)){
			paddle2.setHeight(100.0f);
			//is_bomb_visible = true;
			bool isBallBetweenX = (ball.getXPos() > bomb_posx) && (ball.getXPos() < (bomb_posx + bomb_width));
			bool isBallBetweenY = (ball.getYPos() > bomb_posy) && (ball.getYPos() < (bomb_posy + bomb_height));
			if (lastPaddleHit == 'R' && (isBallBetweenX && isBallBetweenY)){
				bombBegin = time(NULL);
				createSound(8);
				createSound(9);
				//is_bomb_visible = false;
				//set to half normal height:
				paddle2.setHeight(60.0f);
				if (hud->getPlayer2Health()>0){
					hud->setPlayer2Health(hud->getPlayer2Health()- 10*(1+random(8)));
					//GAMEOVER:
					if (hud->getPlayer2Health() <= 0){
						createSound(5);
						is_gameover = true;
						ball.setXVel(0.0f);
						ball.setYVel(0.0f);
						stopGame();
					}
				}
				beginSmallRightPaddle = time(NULL);
			}
		}
//.........这里部分代码省略.........
开发者ID:jacobfrench,项目名称:cs335_battlepong,代码行数:101,代码来源:battlepong.cpp


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