コード例 #1
0
ファイル: QuadNode.cpp プロジェクト: diemhuongpie/GameDx
void CQuadNode::SplitParent()
{
	m_Node			= new CQuadNode*[4];

	this->m_Node[0] = new CQuadNode(this->m_NodeLevel + 1, CBox2D(this->m_NodeSize.getX(), this->m_NodeSize.getY(), this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getHeight() / 2));
	this->m_Node[1] = new CQuadNode(this->m_NodeLevel + 1, CBox2D(this->m_NodeSize.getX() + this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getY(), this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getHeight() / 2));
	this->m_Node[2] = new CQuadNode(this->m_NodeLevel + 1, CBox2D(this->m_NodeSize.getX(), this->m_NodeSize.getY() + this->m_NodeSize.getHeight() / 2, this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getHeight() / 2));
	this->m_Node[3] = new CQuadNode(this->m_NodeLevel + 1, CBox2D(this->m_NodeSize.getX() + this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getY() + this->m_NodeSize.getHeight() / 2, this->m_NodeSize.getWidth() / 2, this->m_NodeSize.getHeight() / 2));
}
コード例 #2
0
CBox2D		CCamera::getBoundingScreen()
{
	return CBox2D(m_Position.x, m_Position.y, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
}
コード例 #3
0
void CPlayer::handleCollisionWithTile(float deltaTime) {

	vector<CBox2D*> listRect = CMapManager::getInstance()->getListRect();

	for (int i = 0; i < listRect.size(); ++i) {
		if (this->m_State != PLAYERSTATES::DIE) {

			this->getBounding().setVelocity(this->getVelocity());

			switch (CCollision::CheckCollision(this->getBounding(), *(listRect.at(i))))
			{
			case COLDIRECTION::COLDIRECTION_TOP:
				m_IsFreeFall = false;
				m_IsAutoJump = false;
				m_Velocity.y = VEL_DEFAULT_Y;

				this->m_Position.y = listRect.at(i)->getY() + this->getBounding().getHeight() / 2;

				if (!m_IsAutoMove) {
					if (this->m_State != PLAYERSTATES::RUN && this->m_State != PLAYERSTATES::MOVE_SHOOT) {
						this->m_PlayerState->exitCurrentState(*this, new CStandState());
						this->m_PlayerState->enter(*this);
					}
				}
				else {
					this->m_PlayerState->exitCurrentState(*this, new CRunState());
					this->m_PlayerState->enter(*this);
				}

				break;
			case COLDIRECTION::COLDIRECTION_NONE:
				if (m_State != PLAYERSTATES::JUMP) {
					if (!IsCollision_WithRect(this, listRect)){
						m_Velocity.y = VEL_PLAYER_Y_MIN;
						m_IsFreeFall = true;
					}

				}

				break;

			case COLDIRECTION::COLDIRECTION_BOTTOM:
				this->m_Position.y = listRect.at(i)->getY() - listRect.at(i)->getHeight() - this->getBounding().getHeight() / 2;
				if (this->m_Velocity.y >= 0)
				{
					//this->m_Velocity.y = CHANGE_DIRECTION(this->m_Velocity.y);
					this->m_Velocity.y = VEL_PLAYER_Y_MIN;
				}
				break;
			case COLDIRECTION::COLDIRECTION_LEFT:
				if (this->m_Direction.at(DIRECTIONINDEX::DIRECTION_X) == DIRECTION::DIRECTION_RIGHT) {
					m_Position.x = listRect.at(i)->getX() - this->getBounding().getWidth() / 2;
					m_Velocity.x = VEL_PLAYER_X_MIN;

					if (m_IsAutoJump) {
						m_Velocity.y = VEL_PLAYER_Y_MIN;
					}
				}
				else if (this->m_Direction.at(DIRECTIONINDEX::DIRECTION_X) == DIRECTION::DIRECTION_LEFT) {
					m_Velocity.x = -VEL_PLAYER_X;
				}
				break;
			case COLDIRECTION::COLDIRECTION_RIGHT:
				if (this->m_Direction.at(DIRECTIONINDEX::DIRECTION_X) == DIRECTION::DIRECTION_LEFT) {
					m_Velocity.x = VEL_PLAYER_X_MIN;
					m_Position.x = listRect.at(i)->getX() + listRect.at(i)->getWidth() + this->getBounding().getWidth() / 2;

				/*	if (m_IsAutoJump) {
						m_Velocity.y = VEL_PLAYER_Y_MIN;
					}*/
				}
				else if (this->m_Direction.at(DIRECTIONINDEX::DIRECTION_X) == DIRECTION::DIRECTION_RIGHT) {
					m_Velocity.x = VEL_PLAYER_X;
				}
				break;
			default:

				break;
			}

			//}
		}
		else
		{
			if (m_Position.y >= 100 && m_Velocity.y >= 0){
				m_Velocity.y = CHANGE_DIRECTION(m_Velocity.y);
			}

		}

	}

	//-----Handle Collision with Screen - Die State----//

	this->getBounding().setVelocity(this->getVelocity());
	if (CCollision::CheckCollision(this->getBounding(), CBox2D(0, 0, 3584, 0)) == COLDIRECTION::COLDIRECTION_TOP) {
		if (!m_IsAutoMove && !m_IsAutoJump && m_State != PLAYERSTATES::DIE){
			m_Velocity.y = VEL_DEFAULT_Y + VEL_PLAYER_Y;
			m_IsFreeFall = false;
			this->m_PlayerState->exitCurrentState(*this, new CDieState());
			this->m_PlayerState->enter(*this);
		}
	}
}