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


C++ Door::isExit方法代码示例

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


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

示例1: update


//.........这里部分代码省略.........
				vector3df toPlayer = playerPos - objPos;
				if (toPlayer.getLength() < 5 && (getCurrentRoom() == obj->getCurrentRoom())){
					if (obj->getItemName() == "key") {
						_hasKey = true;
						std::cout << _hasKey << std::endl;
					}					
					obj->setPickedUp(true);
					this->setCarriedItem(obj);
					this->_isCarrying = true;
					//does the player need a hint?
					HudManager* hud = (HudManager*)EntityManager::getNamedEntities("Hudman")->front();
					if (!hud->hasHintBeenShownFor("Throw")){
						hud->drawHintFor("Throw");
					}
					break;
				}
				iter++;
			}

		}
	}

	if (inputHandler.getCurrentMouse().LeftButton){
		if (_isCarrying){//dropping
			if (this->getCarriedItem() != NULL){
				this->_isCarrying = false;
				Message m(this->getCarriedItem(), "thrown", 0);
				MessageHandler::sendMessage(m);
				this->clearCarriedItem();
				_noiseAllowance -= 5.0f;
				//does the player need a hint?
				HudManager* hud = (HudManager*)EntityManager::getNamedEntities("Hudman")->front();
				if (!hud->hasHintBeenShownFor("Noise")){
					hud->drawHintFor("Noise");
				}
				_hasKey = false;
			}
		}
	}

	/* CHECKING THE DOORS */
	std::list<Entity*>* doors = EntityManager::getNamedEntities("Door");
	vector3df playerPos = _node->getPosition();
	auto doorIter = doors->begin();
	while (doorIter != doors->end()){

		Door* door = (Door*)(*doorIter);
		btVector3 btPos = door->getRigidBody()->getCenterOfMassPosition();
		vector3df doorPos = vector3df(btPos.x(), btPos.y(), btPos.z());
		vector3df toPlayer = playerPos - doorPos;

		if (toPlayer.getLength() < 3 && inputHandler.isKeyDown(KEY_KEY_F) && !inputHandler.wasKeyDown(KEY_KEY_F)) {
			btTransform transform = getRigidBody()->getCenterOfMassTransform();

			if (door->getDirection() == 1 && playerPos.X < doorPos.X && !door->isExit()) {
				transform.setOrigin(btVector3(doorPos.X + 2.0f, playerPos.Y, doorPos.Z));
			}
			else if (door->getDirection() == 2 && playerPos.X > doorPos.X && !door->isExit()) {
				transform.setOrigin(btVector3(doorPos.X - 2.0f, playerPos.Y, doorPos.Z));
			}
			else if (door->getDirection() == 3 && playerPos.Z < doorPos.Z && !door->isExit()) {
				transform.setOrigin(btVector3(doorPos.X, playerPos.Y, doorPos.Z + 2.0f));
			}
			else if (door->getDirection() == 4 && playerPos.Z > doorPos.Z && !door->isExit()) {
				transform.setOrigin(btVector3(doorPos.X, playerPos.Y, doorPos.Z - 2.0f));
			}
			else if (door->getDirection() == 2 && playerPos.X > doorPos.X && door->isExit() && _hasKey) {
				//exitdoor with key
				game.setEndCause((allItemsCollected() ? "win" : "fail"));
				game.setNoiseMade(_startingNoise - _noiseAllowance);
				inputHandler.setEnded(true);
			}
			else if (door->getDirection() == 2 && playerPos.X > doorPos.X && door->isExit() && !_hasKey){
				game.getAudioEngine()->play2D("sounds/common/locked_door.wav");
			}

			getRigidBody()->setCenterOfMassTransform(transform);
		}
		doorIter++;
	}
	/* GET THE ROOM THE PLAYER IS IN */
	std::list<Entity*>* rooms = EntityManager::getNamedEntities("Room");
	playerPos = _node->getPosition();
	auto iterator = rooms->begin();
	while (iterator != rooms->end()){

		Room* room = (Room*)(*iterator);
		vector3df roomPos = room->getPosition();
		vector3df roomScale = room->getScale();
		vector3df toPlayer = playerPos - roomPos;
		if (toPlayer.getLength() < roomScale.Z / 2)
			setCurrentRoom(room->getName());
		iterator++;
	}

	if (_noiseAllowance<0.0f){
		game.setEndCause("lose");
		inputHandler.setEnded(true);
	}
}
开发者ID:razvanilin,项目名称:games-engineering-project,代码行数:101,代码来源:Player.cpp


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