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


C++ CollisionDetector::clearVector方法代码示例

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


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

示例1: run

void GameEngine::run()
{
	spriteVec.push_back(levelVec.at(currentLevel)->getBackground());
	spriteVec.push_back(player);
	bool goOn = true;
	long laps = 0;
	while (goOn) {
		Uint32 nextTick = SDL_GetTicks() + ticks;
		SDL_RenderClear(win->getRen());
		if (initialLoop) {
			textInput();
			initialLoop = false;
		}
		SDL_Event eve2;
		for (size_t i = 0; i < spriteVec.size(); i++) {
			spriteVec.at(i)->draw();
			cd.checkCollisions(spriteVec.at(i));
		}
		removeSprites();
		cd.clearVector();
		for (size_t i = 0; i < textBoxVec.size(); i++) {
			textBoxVec.at(i)->draw();
		}
		if (pointCounter != nullptr) {
			pointCounter->draw();
		}
		SDL_RenderPresent(win->getRen());
		
		if (player == nullptr) {
			playerDied();
		}
		while (SDL_PollEvent(&eve2)) {
			switch (eve2.type) {
			case SDL_QUIT: goOn = false;
				break;
			case SDL_KEYDOWN:
				if (functionMap.count(eve2.key.keysym.sym) != 0) {
					functionMap[eve2.key.keysym.sym]();
				}
				for (size_t i = 0; i < memberFuncVec.size(); i++) {
					memberFuncVec.at(i)->perform(eve2.key.keysym.sym);
				}
				for (size_t i = 0; i < spriteVec.size(); i++) {
					spriteVec.at(i)->draw(eve2);
				}
				break;
			case SDL_KEYUP:
				for (size_t i = 0; i < spriteVec.size(); i++) {
					spriteVec.at(i)->draw(eve2);
				}
				break;
			}
		}
		laps++;
		
		levelVec.at(currentLevel)->spawnWave(this, laps);
		
		deleteSpawns(laps);

		//This is triggered when the level is over:
		if (laps > levelVec.at(currentLevel)->getEndFrame()) {
			SDL_RenderClear(win->getRen());
			for (size_t i = 0; i < spriteVec.size(); i++) {
				if (spriteVec.at(i)->getIsPlayer() == false) {
					spriteVec.at(i)->destroy(); //Prepare every sprite for removal except the player
				}
			}
			removeSprites();
			spriteVec.clear();
			deleteAllSpawns();
			SDL_RenderClear(win->getRen());
			levelSwap(); //Needs to be set by the game programmer
			currentLevel++;
			return this->run();
		}
		if (SDL_GetTicks() < nextTick) {
			SDL_Delay(nextTick - SDL_GetTicks());
		}
	}
}
开发者ID:gronstrand,项目名称:prog3-ht2015-gameengine,代码行数:80,代码来源:GameEngine.cpp


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