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


C++ BoxCollider::hitright方法代码示例

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


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

示例1: update

void GameScreen::update(float mouseX, float mouseY){
	updateMouse(mouseX, mouseY);

	for (int i = 0; i < NBR_TEAMS; i++){
		m_teams[i]->update();
	}

	//Causes an explosion at where the curShor hits
	if (m_curUnit->getWeapon()->getCurShot()){
		if (m_quadTree->processCollisions(m_curUnit->getWeapon()->getCurShot()->getModel())){
			if (m_explo){
				float exploForce = 0.0f;

				exploForce = m_curUnit->getWeapon()->getPower() * 0.5f;

				if (exploForce < 0.2f){
					exploForce = 0.2f;
				}

				m_explo->circularExplosion(Vector(m_curUnit->getWeapon()->getCurShot()->getModel()->getPos().x, m_curUnit->getWeapon()->getCurShot()->getModel()->getPos().y, 1), exploForce, m_curUnit->getWeapon()->getDamage() * m_curUnit->getWeapon()->getPower(), *m_quadTree);
				m_curUnit->getWeapon()->hitObject(NULL, 0, 0);
				m_hitTerrain = true;
				m_endTurnTimer->resetTimer();
			}
		}
	}

	for (int i = 0; i < NBR_TEAMS; i++){
		for (int j = 0; j < NBR_UNITS; j++){
			Unit* tempUnit = m_teams[i]->getUnit(j);

			//Smooths out physics
			tempUnit->getModel()->setPos(tempUnit->getPhysics()->nextPos());

			//Checks to see if collision occurs between current position and next
			BoxCollider* tempCol = (BoxCollider*)m_quadTree->processCollisions(tempUnit->getModel(), tempUnit->getPhysics()->nextPos());

			if (tempCol){
				//When going left, collide with right of terrain
				if (tempUnit->getPhysics()->getVelX() < 0){
					if (tempCol->hitright(&tempUnit->getModel()->getCollider())){
						tempUnit->getPhysics()->setAccelX(0.0f);
						tempUnit->getPhysics()->setVelocityX(0.0f);
					}
				}

				//When going right collide with left of terrain
				if (tempUnit->getPhysics()->getVelX() > 0){
					if (tempCol->hitLeft(&tempUnit->getModel()->getCollider())){
						tempUnit->getPhysics()->setAccelX(0.0f);
						tempUnit->getPhysics()->setVelocityX(0.0f);
					}
				}

				//When falling collide with top of terrain
				if (tempUnit->getPhysics()->getVelY() < 0){
					if (tempCol->hitTop(&tempUnit->getModel()->getCollider())){
						tempUnit->getPhysics()->setAccelY(0.0f);
						tempUnit->getPhysics()->setVelocityY(0.0f);

						tempUnit->getPhysics()->isGrounded(true);
					}
				}

				//When jumping collide with bottom of terrain
				if (tempUnit->getPhysics()->getVelY() > 0){
					if (tempCol->hitBottom(&tempUnit->getModel()->getCollider())){
						tempUnit->getPhysics()->setAccelY(0.0f);
						tempUnit->getPhysics()->setVelocityY(0.0f);
					}
				}
			}
			else{
				//If not colliding the unit is falling
				tempUnit->getPhysics()->isGrounded(false);
			}

			//If the unit goes below the water level they die
			if (tempUnit->getPosition().y < WATER_LEVEL && !tempUnit->isDead()){
				tempUnit->setCurHealth(0);

				if (m_curUnit == tempUnit){
					changeUnit();
				}
			}

			//When a unit is below 0 health set them to dead and change unit
			if (!tempUnit->isDead() && tempUnit->getCurHealth() <= 0){
				tempUnit->setCurHealth(0);

				if (m_curUnit == tempUnit){
					changeUnit();
				}
			}

			//If the unit is alive, run its update
			if (!tempUnit->isDead()){
				if (m_delayTest){
					tempUnit->update(m_mousePos);

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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