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


C++ checkCollision函数代码示例

本文整理汇总了C++中checkCollision函数的典型用法代码示例。如果您正苦于以下问题:C++ checkCollision函数的具体用法?C++ checkCollision怎么用?C++ checkCollision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了checkCollision函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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