本文整理汇总了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);
}
}
//.........这里部分代码省略.........