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


C++ Physics::boundarycheck方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........

	spritecollection.push_back(sprite);

	
	SDL_Texture *shrub = loadTexture(resPath + "shrub.png", renderer);
	if (shrub == nullptr){
		cleanup(shrub, renderer, window);
		IMG_Quit();
		SDL_Quit();
		return 1;
	}

	Sprite* obstacle1 = new Sprite(50, 50, renderer); //random objects
	obstacle1->setID("SHRUB");
	obstacle1->setPos(200, 200);
	int obstacleframe = obstacle1->makeFrame(shrub, 0, 0);
	spritecollection.push_back(obstacle1);

	int x = SCREEN_WIDTH / 2;
	int y = SCREEN_HEIGHT / 2;
	sprite->setPos(x, y);

	Physics* physic = new Physics();

	SDL_Event e;
	bool quit = false;
	std::string spriteDirection = "float up";
	while (!quit){
		while (SDL_PollEvent(&e)){
			if (e.type == SDL_QUIT){
				quit = true;
			}
			/*std::vector<Sprite*>::iterator it; //collding not working
			if (physic->boundarycheck(sprite, 100, 100, 440, 280) == physic->NONE) //sprite is inside boundary, not touching the "walls/corners"
			{
				for (it = spritecollection.begin(); it != spritecollection.end(); ++it) //going through each sprite to test for collision
				{
					if (physic->collisiondetection(sprite, *it) == physic->LEFT) //it is touching sprite's left
					{
						if (e.type == SDL_KEYDOWN){
							if (e.key.keysym.sym == SDLK_RIGHT)
							{
								sprite->movex(5);
								spriteDirection = "walk right";
							}
							else if (e.key.keysym.sym == SDLK_UP)
							{
								sprite->movey(-5);
								spriteDirection = "float up";
							}
							else if (e.key.keysym.sym == SDLK_DOWN)
							{
								sprite->movey(5);
								spriteDirection = "float down";
							}
						}
					}
					else if (physic->collisiondetection(sprite, *it) == physic->RIGHT) //object is touching sprite's right
					{
						if (e.type == SDL_KEYDOWN){
							if (e.key.keysym.sym == SDLK_LEFT)
							{
								sprite->movex(-5);
								spriteDirection = "walk left";
							}
							else if (e.key.keysym.sym == SDLK_UP)
开发者ID:pgtruong,项目名称:Puzzle-Engine,代码行数:67,代码来源:SpriteDemo.cpp


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