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


C++ Collision::RectCollide方法代码示例

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


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

示例1: RenderFrame

void Engine::RenderFrame()
{	    
	Collision checker; //DELETE
	//Camera offsets
	int camOffsetX, camOffsetY;

	Tile* tile;
	window->clear();
	
	//Get the tile bounds we need to draw
	sf::IntRect bounds = camera->GetTileBounds(tileSize);

	//Figure out how much to offset each tile
	camOffsetX = camera->GetTileOffset(tileSize).x;
	camOffsetY = camera->GetTileOffset(tileSize).y;
	//Loop through and draw each tile
	//We're keeping track of two variables in each loop. How many tiles
	//we've drawn (x and y), and which tile on the map we're drawing (tileX
	//and tileY)
	player->ground = false;	
	for(int y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
	{
		for(int x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
		{
			tile = new Tile(TextureManager.GetTexture(0)); // background!
			tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
			//Get the tile	
			tile = currentLevel->GetTile(tileX, tileY);
			if(tile){
 				tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
				if(checker.RectCollide(sf::FloatRect((x * tileSize), (y * tileSize), tileSize, tileSize), sf::FloatRect((player->getPosition().left), (player->getPosition().top), tileSize, tileSize)) && tile->baseSprite.getTexture() == Tile(TextureManager.GetTexture(2)).baseSprite.getTexture()){
				player->ground = true;
				}				
			}
					
		}
	}
	
	player->Draw(camOffsetX, camOffsetY, window);
	window->display();
}
开发者ID:jstone05,项目名称:Snake-Game,代码行数:41,代码来源:Engine.cpp


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