本文整理汇总了C++中checkCollision函数的典型用法代码示例。如果您正苦于以下问题:C++ checkCollision函数的具体用法?C++ checkCollision怎么用?C++ checkCollision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkCollision函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: shiftColliders
void Bullet::moveUp( std::vector<SDL_Rect>& otherColliders )
{
mVelY++;
//Move the dot left or right
mPosX += mVelX;
shiftColliders();
//If the dot collided or went too far to the left or right
if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
{
if (!bulletsUp.empty())
{
bulletsUp.pop_back();
}
mVelY = 0;
}
//Move the dot up or down
mPosY -= mVelY;
shiftColliders();
//If the dot collided or went too far up or down
if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
{
if (!bulletsUp.empty())
{
bulletsUp.pop_back();
mVelY = 0;
}
}
}
开发者ID:PetarValkov,项目名称:UbiShipsTask,代码行数:32,代码来源:CApp.cpp
示例2: SDL_GetMouseState
void LevelPlaySelect::checkMouse(ImageManager &imageManager, SDL_Renderer &renderer){
int x,y;
//Get the current mouse location.
SDL_GetMouseState(&x,&y);
//Check if we should replay the record.
if(selectedNumber!=NULL){
SDL_Rect mouse={x,y,0,0};
if(!bestTimeFilePath.empty()){
SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-130,372,32};
if(checkCollision(box,mouse)){
Game::recordFile=bestTimeFilePath;
levels->setCurrentLevel(selectedNumber->getNumber());
setNextState(STATE_GAME);
return;
}
}
if(!bestRecordingFilePath.empty()){
SDL_Rect box={SCREEN_WIDTH-420,SCREEN_HEIGHT-98,372,32};
if(checkCollision(box,mouse)){
Game::recordFile=bestRecordingFilePath;
levels->setCurrentLevel(selectedNumber->getNumber());
setNextState(STATE_GAME);
return;
}
}
}
//Call the base method from the super class.
LevelSelect::checkMouse(imageManager, renderer);
}
开发者ID:oyvindln,项目名称:meandmyshadow,代码行数:32,代码来源:LevelPlaySelect.cpp
示例3: checkCollision
void BallController::updateCollision(Grid* grid)
{
for (int i = 0; i < grid->_cells.size(); i++)
{
int x = i % grid->_numXCells;
int y = i / grid->_numXCells;
Cell* cell = grid->getCell(x, y);
for (int j = 0; j < cell->balls.size(); j++)
{
Ball* ball = cell->balls[j];
checkCollision(ball, cell->balls, j+1);
if (x > 0)
{
checkCollision(ball, grid->getCell(x - 1, y)->balls, 0);
if (y > 0)
{
checkCollision(ball, grid->getCell(x-1,y-1)->balls, 0);
}
if (y < grid->_numYCells - 1)
{
checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0);
}
}
if (y > 0)
{
checkCollision(ball, grid->getCell(x, y - 1)->balls, 0);
}
}
}
}
开发者ID:zhuzhonghua,项目名称:sdl_gameclient,代码行数:33,代码来源:ballcontroller.cpp
示例4: move
void Dot::move( SDL_Rect& wall )
{
//Move the dot left or right
mPosX += mVelX;
mCollider.x = mPosX;
//If the dot collided or went too far to the left or right
if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mCollider, wall ) )
{
//Move back
mPosX -= mVelX;
mCollider.x = mPosX;
}
//Move the dot up or down
mPosY += mVelY;
mCollider.y = mPosY;
//If the dot collided or went too far up or down
if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mCollider, wall ) )
{
//Move back
mPosY -= mVelY;
mCollider.y = mPosY;
}
}
开发者ID:JerelynCo,项目名称:CS179.14,代码行数:26,代码来源:27_collision_detection.cpp
示例5: collideShellsWithEnemies
void CGame::collideShellsWithEnemies()
{
//get list of all plane shells
std::list<std::unique_ptr<SDL_Rect>> *shells = plane.getShellsFired();
//iterate over enemies
for (std::list<std::unique_ptr<CEnemy>>::iterator enemy = enemyList.begin(); enemy != enemyList.end(); enemy++)
{
//check if enemy is on screen, and is alive
if (checkCollision(plane.getCamera(), (*enemy)->getBox()) && (*enemy)->isAlive())
{
//iterate over plane shells
for (std::list<std::unique_ptr<SDL_Rect>>::iterator shell = shells->begin(); shell != shells->end(); shell++)
{
SDL_Rect shell_rect = {(*shell)->x, (*shell)->y, (*shell)->w, (*shell)->h };
if (checkCollision(shell_rect, (*enemy)->getBox()))
{
shell->release();
shells->erase(shell++);
if ((*enemy)->type == BRIDGE)
{
//if killed a bridge, set new starting pos
SDL_Rect bridge = (*enemy)->getBox();
plane.setStartingPos(bridge.x + bridge.w / 2, bridge.y - bridge.h);
updateScoreTexture(1000);
}
(*enemy)->kill();
updateScoreTexture(1000);
break;
}
}
}
}
}
开发者ID:wmolicki,项目名称:riverride,代码行数:34,代码来源:Game.cpp
示例6: shiftColliders
void Dot::move( std::vector<SDL_Rect>& otherColliders )
{
//Move the dot left or right
mPosX += mVelX;
shiftColliders();
//If the dot collided or went too far to the left or right
if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > SCREEN_WIDTH ) || checkCollision( mColliders, otherColliders ) )
{
//Move back
mPosX -= mVelX;
shiftColliders();
}
//Move the dot up or down
mPosY += mVelY;
shiftColliders();
//If the dot collided or went too far up or down
if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > SCREEN_HEIGHT ) || checkCollision( mColliders, otherColliders ) )
{
//Move back
mPosY -= mVelY;
shiftColliders();
}
}
开发者ID:cvg256,项目名称:SDLTestGame,代码行数:26,代码来源:28_per-pixel_collision_detection.cpp
示例7: getAdjacents
void getAdjacents(int i, int j, int* a)
{
a[0] = (checkCollision(i,j-1) == COLLISION_SOLID);
a[1] = (checkCollision(i+1,j) == COLLISION_SOLID);
a[2] = (checkCollision(i,j+1) == COLLISION_SOLID);
a[3] = (checkCollision(i-1,j) == COLLISION_SOLID);
}
开发者ID:zear,项目名称:g-ball,代码行数:7,代码来源:intersect.c
示例8: checkCollision
void BallController::updateCollision(Grid* grid) {
for (int i = 0; i < grid->m_cells.size(); i++) {
int x = i % grid->m_numXCells;
int y = i / grid->m_numXCells;
Cell& cell = grid->m_cells[i];
// Loop through all balls in a cell
for (int j = 0; j < cell.balls.size(); j++) {
Ball* ball = cell.balls[j];
/// Update with the residing cell
checkCollision(ball, cell.balls, j + 1);
/// Update collision with neighbor cells
if (x > 0) {
// Left
checkCollision(ball, grid->getCell(x - 1, y)->balls, 0);
if (y > 0) {
/// Top left
checkCollision(ball, grid->getCell(x - 1, y - 1)->balls, 0);
}
if (y < grid->m_numYCells - 1) {
// Bottom left
checkCollision(ball, grid->getCell(x - 1, y + 1)->balls, 0);
}
}
// Up cell
if (y > 0) {
checkCollision(ball, grid->getCell(x, y - 1)->balls, 0);
}
}
}
}
开发者ID:combatwombat5,项目名称:Gengine,代码行数:34,代码来源:BallController.cpp
示例9: Mix_PlayChannel
//Eat pac-dots and the power pallets
void Pacman::eat() {
for (unsigned int row = 0; row < map->size(); row++) {
for (unsigned int col = 0; col < (*map)[row].size(); col++) {
//Detect is it collided with the pac-dots
//Add 100 score if true and erase the dot from the map
if ((*map)[row][col] == "o") {
if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) {
Mix_PlayChannel(-1, sound_food, 0);
(*map)[row][col] = " ";
score += 100;
return;
}
}
//Detect is it collided with the power pallets
//Add 500 score if true and erase the power palletes from the map
if ((*map)[row][col] == "p") {
if (checkCollision((col * 30) + 15, (row * 30) + 15, 0, 0)) {
Mix_PlayChannel(-1, sound_powerup, 0);
(*map)[row][col] = " ";
score += 500;
setPowerUp(true);
return;
}
}
}
}
}
开发者ID:pisc3s,项目名称:Pacman,代码行数:29,代码来源:Pacman.cpp
示例10: if
void Hero::motion( SDL_Rect rect )
{
/* Dla kazdego warunku - jesli uzytkownik kliknal LEFT to postac porusza sie w lewo z okreslona predkoscia, itd... */
if( key[ SDL_SCANCODE_LEFT ] )
{
if( x > 0 )
{
x -= speed;
}
/* Dla kazdego warunku - jesli wystapila kolizja to cofa postac jeszcze przed wyrenderowaniem calej sytuacji */
if( checkCollision( rect ) )
{
x += speed;
}
}
else if( key[ SDL_SCANCODE_RIGHT ] )
{
if( x < 800 - texture.getWidth() )
{
x += speed;
}
if( checkCollision( rect ) )
{
x -= speed;
}
}
if( key[ SDL_SCANCODE_UP ] )
{
if( y > 104 )
{
y -= speed;
}
if( checkCollision( rect ) )
{
y += speed;
}
}
else if( key[ SDL_SCANCODE_DOWN ] )
{
if( y < 600 - texture.getHeight() )
{
y += speed;
}
if( checkCollision( rect ) )
{
y -= speed;
}
}
}
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:56,代码来源:hero.cpp
示例11: refreshPacman
/* refresh pacmans position */
void refreshPacman(void) {
checkCollision();
updatePacmanPosition();
updatePacmanMovement();
checkPacmanMovement();
addScores();
checkCollision();
}
开发者ID:uysalere,项目名称:pacman,代码行数:11,代码来源:Pacman.c
示例12: isRaceOver
//Método principal para atualização do game em tempo real
void Game::gameUpdate(){
//Limite de Frame Rate
gameWindow.setFramerateLimit(60);
//Checa se algum dos players completou as 3 voltas
isRaceOver();
//Verifica se a tecla ESC é pressionada, abrindo o menuPause
renderPause();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
menuPause.abrirMenu();
//Toca a música que será reproduzida durante a corrida
raceBGM.playMusic();
raceBGM.setVolume(100);
//Ativa os métodos de entrada de keyboard para os controles de ambos os players
player[0].ativarMovimentos(0);
player[1].ativarMovimentos(1);
//Checa todas as colisões possíveis dentro da partida para cada Player
checkCollision(0);
checkCollision(1);
//Checa se os players estão no sentido correto da pista (caso eles percorram ao contrário), seus
//carros explodirão
player[0].checarSentido();
player[1].checarSentido();
//Checa durante a partida quando a linha de chegada é ultrapassada
checkLap();
//Centralizando cada câmera em seu respectivo player
player[0].centralizarCamera();
player[1].centralizarCamera();
//Renderizações na tela do Player1
gameWindow.setView(player[0].getCamera());
renderMap();
gameWindow.draw(player[0].getSprite());
gameWindow.draw(player[1].getSprite());
renderProjeteis();
renderGUI(0);
//Renderizações na tela do Player 2
gameWindow.setView(player[1].getCamera());
renderMap();
gameWindow.draw(player[1].getSprite());
gameWindow.draw(player[0].getSprite());
renderProjeteis();
renderGUI(1);
gameWindow.display();
gameWindow.clear();
}
开发者ID:TioMinho,项目名称:CarMayhem,代码行数:56,代码来源:Game.cpp
示例13: checkCollision
bool CGame::standingOnCollapsingBridge(SDL_Rect A)
{
for (std::list<std::unique_ptr<CEnemy>>::iterator it = enemyList.begin(); it != enemyList.end(); it++)
{
//checks all bridges on screen, and returns whether A is standing on dead brigde
if ((*it)->type == BRIDGE && checkCollision((*it)->getBox(), plane.getCamera()) && !(*it)->isAlive())
{
return checkCollision(A, (*it)->getBox());
}
}
return false;
}
开发者ID:wmolicki,项目名称:riverride,代码行数:12,代码来源:Game.cpp
示例14: checkCharHitChar
/***********************************************************************
; Name: checkCharHitChar
; Description: This function checks for collisions between the attack
; of one character and the position of another character.
; It doesn't matter which character calls the function,
; it performs correctly.
;***********************************************************************/
char checkCharHitChar(struct character *self, char attackx, char attacky, unsigned char attackw, unsigned char attackh)
{
char ret = 0;
if (self->player == 0)
{
ret = checkCollision(attackx, attacky, attackw, attackh, player1.x, player1.y, player1.framew, player1.frameh);
}
else
{
ret = checkCollision(attackx, attacky, attackw, attackh, player0.x, player0.y, player0.framew, player0.frameh);
}
return ret;
}
开发者ID:brownkp,项目名称:vga_9s12,代码行数:20,代码来源:sillydigijocks.c
示例15: checkCollision
bool ShapeRay::checkCollision( ShapeRect const *const other ) const
{
// TODO: Do this properly (not with ray approximation
ShapeRay bltr;
bltr.pos = other->getCorner( diBOTTOMLEFT );
bltr.target = other->getCorner( diTOPRIGHT );
ShapeRay brtl;
brtl.pos = other->getCorner( diBOTTOMRIGHT );
brtl.target = other->getCorner( diTOPLEFT );
if ( checkCollision( &bltr ) || checkCollision( &brtl ) )
return true;
return false;
}
开发者ID:foxblock,项目名称:Project4,代码行数:13,代码来源:ShapeRay.cpp
示例16: PauseState
void PlayState::update()
{
if (TheInputHandler::Instance()->isKeyDown(SDL_SCANCODE_ESCAPE))
{
TheGame::Instance()->getStateMachine()->pushState(new PauseState());
}
for (int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->update();
}
//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->
//if (m_gameObjects[0]->g);
//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getBullet()->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX());
//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getVIBullet()[0]->setBulletX(dynamic_cast<SDLGameObject*>(m_gameObjects[0])->getPlayer()->getPosition().getX());
//dynamic_cast<SDLGameObject*>(m_gameObjects[1])->getPlay
for (int i = 2; i < m_gameObjects.size(); i++)
{
if (checkCollision(
dynamic_cast<SDLGameObject*>(m_gameObjects[1]),
dynamic_cast<SDLGameObject*>(m_gameObjects[i])))
{
std::string textureID = "bullet";
std::string typeID = "Bullet";
//pGameObject->load(new LoaderParams(x, y, width, height, textureID, numFrames, callbackID, animSpeed));
m_gameObjects.erase(m_gameObjects.begin() + i);
//m_gameObjects.erase(m_gameObjects.begin() + 1);
//GameObject* pGameObject = TheGameObjectFactory::Instance()->create(typeID);
m_gameObjects[1] = TheGameObjectFactory::Instance()->create(typeID);;
m_gameObjects[1]->load(new LoaderParams(200, 350, 21, 21, textureID, 1, 0, 1));
//m_gameObjects.push_back(pGameObject);
//std::string _textID = "Bullet";
//(x, y, width, height, textureID, numFrames, callbackID, animSpeed))
//m_gameObjects[1]->load(LoaderParams(100, 100, 100, 100, _textID, 1, 0, 0));
//StateParser stateParser;
//stateParser.parseState("text.xml", s_playID, &m_gameObjects, &m_textureIDList);
}
if (checkCollision(
dynamic_cast<SDLGameObject*>(m_gameObjects[0]),
dynamic_cast<SDLGameObject*>(m_gameObjects[i])))
{
TheGame::Instance()->setState(State::GameOver);
}
}
}
开发者ID:hoseogame,项目名称:20101940_SDL,代码行数:50,代码来源:PlayState.cpp
示例17: animate
void Bomb::explode()
{
_explodeTime = Director::getInstance()->getTotalFrames();
_isFire = true;
_isRemote = false;
_tick = 9999;
GameSounds::Instance().playSound(ES_BOMB, false);
if (_player)
{
_player->explodeBomb();
_player = nullptr;
}
if (_brick)
{
_brick->explodeBomb();
_brick = nullptr;
}
animate(_sprite, FCENTER);
checkCollision(_sprite);
_fires.push_back(_sprite);
for (auto p : sPoints)
{
for (int i = 1; i <= _size; i++)
{
FireType type = i == _size ? FTAIL : FBODY;
auto sprite = Sprite::createWithSpriteFrameName(typeStr[type] + "_1.png");
sprite->setPosition(_sprite->getPosition() + p * i);
Direction dir = pointToDir(p);
if (dir == RIGHT)
{
sprite->setRotation(90);
}
else if (dir == LEFT)
{
sprite->setRotation(270);
}
else if (dir == DOWN)
{
sprite->setFlippedY(true);
}
animate(sprite, type);
if (checkCollision(sprite)) break;
_fires.push_back(sprite);
addChild(sprite);
}
}
}
开发者ID:nonothing,项目名称:Dyna-Blaster,代码行数:49,代码来源:Bomb.cpp
示例18: checkCollision
void MyRect::move()
{
bool isColliding= checkCollision();
//move down
if(isColliding==false){
if(pos().y()< 600){
setPos(x(),y()+30);
//setPos(x(),600);
//qDebug()<<"position change";
}
else{
qDebug()<<"count:"<<count;
points+=2;
myGame.printText(QString("Nice 2 Points: "),700,count,1.5);
myGame.printText(QString::number(points),900,count,1.5);
count+=50;
if(count>=500){
count=30;
}
isRowFilled(pos().y()+15);
//qDebug()<<"rim";
time->stop();
myGame.spawn();
}
}
else if(pos().y() < 29 &&isColliding){
qDebug()<<"lose";
scene()->clear();
// scene()->removeItem(this);
// delete this;
QString yolo = QString ("You Lose");
myGame.printText(yolo,425,250,3);
}
else if(checkCollision()){
points+=2;
myGame.printText(QString("Nice 2 Points: "),700,count,1.5);
myGame.printText(QString::number(points),900,count,1.5);
count+=50;
if(count>=500){
count=30;
}
isRowFilled(pos().y()+15);
qDebug()<<"spawning";
time->stop();
myGame.spawn();
}
}
开发者ID:Shammsize,项目名称:Estructura,代码行数:49,代码来源:myrect.cpp
示例19: sin
void Bullet::update(){
float deltaX = 0;
float deltaY = 0;
deltaX = sin(this->angle) * this->moveSpeed;
deltaY = -cos(this->angle) * this->moveSpeed;
if(!inShop){
if(this->playerShot){
for(int i = 0; i < MAX_ZOMBIES; i++){
if(zombieList[i] != NULL && zombieList[i]->checkActive()){
if(checkCollision(this->posX, this->posY, zombieList[i]->posX, zombieList[i]->posY, this->width, this->height, zombieList[i]->width, zombieList[i]->height)){
zombieList[i]->health -= this->damage;
this->active = false;
}
}
}
}else{
if(checkCollision(this->posX, this->posY, playerCenterX, playerCenterY, this->width, this->height, playerWidth, playerHeight)){
playerHealth -= this->damage;
this->active = false;
}
}
if(isPassable(this->posX+deltaX, this->posY, this->width, this->height, deltaX, deltaY)){
this->posX += deltaX;
}else{
this->active = false;
}
if(isPassable(this->posX, this->posY+deltaY, this->width, this->height, deltaX, deltaY)){
this->posY += deltaY;
}else{
this->active = false;
}
}else{
if(this->posX+deltaX >= 0 && this->posX+deltaX + this->width < 400 && this->posY >= 0 && this->posY + this->height < 400){
this->posX += deltaX;
}else{
this->active = false;
}
if(this->posX >= 0 && this->posX + this->width < 400 && this->posY+deltaY >= 0 && this->posY+deltaY + this->height < 400){
this->posY += deltaY;
}else{
this->active = false;
}
}
}
开发者ID:FlipskiZ,项目名称:My-Games-Dump,代码行数:48,代码来源:Bullet.cpp
示例20: checkCollision
float Item::checkCollision(BaseObject* object, float dt)
{
auto collisionBody = (CollisionBody*)_listComponent["CollisionBody"];
auto objeciId = object->getId();
eDirection direction;
if (collisionBody->checkCollision(object, direction, dt))
{
if (objeciId == eID::LAND || objeciId == eID::BRIDGE) // => ??
{
if (this->getVelocity().y > 0)
return 0.0;
if (direction == eDirection::TOP)
{
auto gravity = (Gravity*)this->_listComponent["Gravity"];
gravity->setStatus(eGravityStatus::SHALLOWED);
gravity->setGravity(VECTOR2ZERO);
auto move = (Movement*) this->_listComponent["Movement"];
move->setVelocity(VECTOR2ZERO);
}
}
if (objeciId == eID::BILL)
{
this->setStatus(eStatus::DESTROY);
((Bill*)object)->changeBulletType(this->_type);
}
}
return 0.0f;
}
开发者ID:7ung,项目名称:NMGAME,代码行数:30,代码来源:Item.cpp
注:本文中的checkCollision函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论