CBoomRockManBullet::CBoomRockManBullet(Megaman* master) : CBullet(0, ID_BULLET_ROCKMAN_BOOM_NONE, ResourceManager::GetSprite(ID_SPRITE_BULLET_BOSS_BOOM), 10, D3DXVECTOR2(0,0), master->_position)
{
	_master = master;

	// Tính lại vị trí xuất hiện của đạn
	_position.y = _master->GetBox()._y;
	if (_master->_isRight)
	{
		_position.x += _master->GetBox()._width ;

		_v.x = ROCK_BOOM_BULLET_VERLOCITY_X;
		_a.x = -ROCKMAN_ACCELERATE_X;

		_velocityYDefault=_v.y = ROCK_BOOM_BULLET_VERLOCITY_Y;
		_a.y = -ROCK_BOOM_BULLET_ACCELERATE_Y;
	}
	else
	{
		_position.x -= _master->GetBox()._width;

		_v.x = -ROCK_BOOM_BULLET_VERLOCITY_X;
		_a.x = ROCKMAN_ACCELERATE_X;

		_velocityYDefault = _v.y = ROCK_BOOM_BULLET_VERLOCITY_Y;
		_a.y = -ROCK_BOOM_BULLET_ACCELERATE_Y;
	}
	UpdateBox();
	_isChangeSprite = false;
	_collideLeft = CollisionInfo(NULL, CDirection::ON_LEFT, 100);
	_collideRight = CollisionInfo(NULL, CDirection::ON_RIGHT, 100);
	_collideUp = CollisionInfo(NULL, CDirection::ON_UP, 100);
	_collideDown = CollisionInfo(NULL, CDirection::ON_DOWN, 100);
}
void CBoomRockManBullet::Update(CTimer* gameTime)
{
	if (_deltaTimeExplode == 0)
	{
		bool hasCollideHorizontal = false;
		if (_collideLeft._object != NULL)
		{
			_position.x += _v.x*_collideLeft._timeCollide;
			_v.x = 0.0f;
			_a.x = 0.0f;
			hasCollideHorizontal = true;
		}
		if (_collideRight._object != NULL)
		{
			_position.x += _v.x*_collideRight._timeCollide;
			_v.x = 0.0f;
			_a.x = 0.0f;
			hasCollideHorizontal = true;
		}
		if (_collideUp._object != NULL)
		{
			_position.y += _v.y*_collideUp._timeCollide-1;
			_v.y = 0.0f;

		}if (_collideDown._object != NULL)
		{
			_position.y += _v.y*_collideDown._timeCollide;
			_velocityYDefault /= 2.0f;
			if (_velocityYDefault > ROCK_BOOM_BULLET_VERLOCITY_Y/100)
				_v.y = _velocityYDefault;
			else{
				_typeID = ID_BULLET_ROCKMAN_BOOM;
				_deltaTimeExplode = 1;		// Tăng lên một để đảm bảo là đếm thời gian bắt đầu phát nổ
				CExplodingEffectManager::Add(new  CExplodingEffectX(_position, ResourceManager::GetSprite(ID_SPRITE_BOOMMAN_BOOM_BURST),false));
				UpdateBox();
			}
		}

		_position += _v*gameTime->GetTime();
		_v += _a*gameTime->GetTime();

		UpdateBox();
		_collideLeft = CollisionInfo(NULL, CDirection::ON_LEFT, 100);
		_collideRight = CollisionInfo(NULL, CDirection::ON_RIGHT, 100);
		_collideUp = CollisionInfo(NULL, CDirection::ON_UP, 100);
		_collideDown = CollisionInfo(NULL, CDirection::ON_DOWN, 100);
	}
	else
	{
		_deltaTimeExplode += gameTime->GetTime();
		if (_deltaTimeExplode >= 1000)
			Destroy();
	}
	_sprite.Update(gameTime);
}
示例#3
0
void CollisionHandler::loadImpulses(std::vector<CollisionInfo> &impulses, std::ifstream &ifs)
{
  impulses.clear();
  int numimpulses=0;
  ifs.read((char *)&numimpulses, sizeof(int));
  for(int i=0; i<numimpulses; i++)
    {
      CollisionInfo::collisiontype type;
      ifs.read((char *)&type, sizeof(CollisionInfo::collisiontype));
      int idx1, idx2;
      ifs.read((char *)&idx1, sizeof(int));
      ifs.read((char *)&idx2, sizeof(int));
      VectorXs n(2);
      ifs.read((char *)n.data(), n.size()*sizeof(scalar));
      double time;
      ifs.read((char *)&time, sizeof(double));
      impulses.push_back(CollisionInfo(type, idx1, idx2, n, time));
    }

  if( ifs.fail() )
    {
      std::cout << outputmod::startred << "Error while trying to deserialize time step impulses. Exiting." << std::endl;
      exit(1);
    }
}
示例#4
0
CollisionInfo Collision2D::HaveCollided_Circle(const sf::Sprite& sprite1, const sf::Sprite& sprite2)
{
	// Check for a collision between the two circles
	const sf::Vector2f kfCenterSubtraction = GetCenter(sprite1) - GetCenter(sprite2);
	const float kfMagnitude = Maths2D::Magnitude(kfCenterSubtraction);
	const float kfRadiiSum = GetRadius(sprite1) + GetRadius(sprite2);
	return CollisionInfo(kfMagnitude < kfRadiiSum, kfMagnitude);
}
示例#5
0
    //*** Start: UpdatableState implementation ***//
    virtual void reset() override
    {
        kinematics_.reset();

        if (environment_)
            environment_->reset();
        wrench_ = Wrench::zero();
        collison_info_ = CollisionInfo();
        collison_response_info_ = CollisonResponseInfo();
    }
示例#6
0
void PhysicsWorld::Collide()
{
	for(unsigned int i = 0; i < staticEntities.size(); i++)
	{
		StaticPhysicsEntity *s = staticEntities[i];

		for(unsigned int j = 0; j < dynamicEntities.size(); j++)
		{
			DynamicPhysicsEntity *d = dynamicEntities[j];
			
			Vec theNormal, theDirection;
			if(Intersects(*s, *d, theNormal, theDirection))
			{
				collidedObjects[collidedObjectsCnt] = CollisionInfo(*d, theNormal, theDirection);
				collidedObjectsCnt++;

				entSendMessage(d->ent, EntMsgCollided, (unsigned int)s->ent);
				entSendMessage(s->ent, EntMsgCollided, (unsigned int)d->ent);
			}
		}
	}
}
示例#7
0
void CollisionHandler::addParticleEdgeImpulse(int vidx, int eidx, const Vector2s &n, double time)
{
  m_impulses.push_back(CollisionInfo(CollisionInfo::PE, vidx, eidx, n, time));
}
示例#8
0
void CollisionHandler::addParticleParticleImpulse(int idx1, int idx2, const Vector2s &n, double time)
{
  m_impulses.push_back(CollisionInfo(CollisionInfo::PP, idx1, idx2, n, time));
}
示例#9
0
void CollisionHandler::addParticleHalfplaneImpulse(int vidx, int pidx, const Vector2s &n, double time)
{
  m_impulses.push_back(CollisionInfo(CollisionInfo::PH, vidx, pidx, n, time));
}
示例#10
0
CollisionInfo
PhysicsObject::collisionCheck(const PhysicsObject * /*object*/) const
{
	return CollisionInfo(false);
}
示例#11
0
CollisionInfo
BoundingBox::collisionCheck(const BoundingBox *box) const
{
	Vector3 otherPosition = box->getPosition();
	Vector3 otherBounds = box->getBounds();

	CollisionInfo info(false);
	bool infoSet = false;
	float dist;

	// +x
	dist = (m_position.x + m_bounds.x) - (otherPosition.x - otherBounds.x);
	if(dist < 0.0f) {
		return info;
	} else {
		info.direction = Vector3(-1.0f, 0.0f, 0.0f);
		info.distance = dist;
		infoSet = true;
	}

	// -x
	dist = (otherPosition.x + otherBounds.x) - (m_position.x - m_bounds.x);
	if(dist < 0.0f) {
		return info;
	} else {
		if(!infoSet || dist < info.distance) {
			info.direction = Vector3(1.0f, 0.0f, 0.0f);
			info.distance = dist;
			infoSet = true;
		}
	}

	// +y
	dist = (m_position.y + m_bounds.y) - (otherPosition.y - otherBounds.y);
	if(dist < 0.0f) {
		return info;
	} else {
		if(!infoSet || dist < info.distance) {
			info.direction = Vector3(0.0f, -1.0f, 0.0f);
			info.distance = dist;
			infoSet = true;
		}
	}

	// -y
	dist = (otherPosition.y + otherBounds.y) - (m_position.y - m_bounds.y);
	if(dist < 0.0f) {
		return info;
	} else {
		if(!infoSet || dist < info.distance) {
			info.direction = Vector3(0.0f, 1.0f, 0.0f);
			info.distance = dist;
			infoSet = true;
		}
	}

	// +z
	dist = (m_position.z + m_bounds.z) - (otherPosition.z - otherBounds.z);
	if(dist < 0.0f) {
		return info;
	} else {
		if(!infoSet || dist < info.distance) {
			info.direction = Vector3(0.0f, 0.0f, -1.0f);
			info.distance = dist;
			infoSet = true;
		}
	}

	// -z
	dist = (otherPosition.z + otherBounds.z) - (m_position.z - m_bounds.z);
	if(dist < 0.0f) {
		return info;
	} else {
		if(!infoSet || dist < info.distance) {
			info.direction = Vector3(0.0f, 0.0f, 1.0f);
			info.distance = dist;
			infoSet = true;
		}
	}

	info.collision = true;
	return info;

#if 0
	return CollisionInfo(
	       ((otherPosition.x - otherBounds.x) < (m_position.x + m_bounds.x)) &&
	       ((otherPosition.x + otherBounds.x) > (m_position.x - m_bounds.x)) &&
	       ((otherPosition.y - otherBounds.y) < (m_position.y + m_bounds.y)) &&
	       ((otherPosition.y + otherBounds.y) > (m_position.y - m_bounds.y)) &&
	       ((otherPosition.z - otherBounds.z) < (m_position.z + m_bounds.z)) &&
	       ((otherPosition.z + otherBounds.z) > (m_position.z - m_bounds.z))
	);
#endif
}
示例#12
0
CollisionInfo
BoundingBox::collisionCheck(const BoundingSphere *sphere) const
{
	CollisionInfo info = sphere->collisionCheck(this);
	return CollisionInfo(info.collision, info.direction * -1.0f);
}
/*
 * Function which lets all the bodies added to this world collide with each other, calculates translations impulses.
 * And the end we step all bodies forward in time by dt
 */
void rWorld::CollideAndStep( rReal dt)
{
	// Update bodies
	for(unsigned int i = 0; i < StateArray.size(); i++)
	{
		// If not a static body
		if( StateArray[i]->InvMass > 0)
		{
			// Let the body do a step with the time and current gravity
			StateArray[i]->Step( dt, Gravity);
			StateArray[i]->CalculateMesh();
		}
	}

	// Clear collisions from last time
	CollisionArray.clear();

	// Clear CollisionPoints
#ifdef R_SAVE_COLLISIONPOINTS
	CollisionPoints.clear();
#endif

	// Overlapping Solving Code. Inner loop for how many iterations requested to solve any errors
	for(int iterations = 0; iterations < ERI; iterations++)
	{
		// If we are at the last iteration, save collisions
		// TODO fix this properly. Always add collisions but never duplicate
		bool push = false;
		if (iterations == 0)
			push = true;

		// Two loops to let everybody check with each other
		for( unsigned int i = 0; i < StateArray.size(); i++)
		{
			for( unsigned int j = i+1; j < StateArray.size(); j++)
			{
				// Sum of both bodies INV mass
				rReal MassRatio = StateArray[i]->InvMass + StateArray[j]->InvMass;

				// Check if a body is movable
				if (MassRatio > 0)
				{
					// Create a collision package between the 2 bodies in line to be tested
					rColinfo CollisionInfo( StateArray[i], StateArray[j]);

					// Check if we have a collision by Separating Axis Test, if so store information in the collision package
					if(::Collide( CollisionInfo))
					{
						// Are we overlapping?
						if( CollisionInfo.Depth > EPSILON)
						{
							//Save required translations to solve any errors
							StateArray[i]->Force_T += CollisionInfo.Force * (StateArray[i]->InvMass / MassRatio) * ERP;
							StateArray[j]->Force_T -= CollisionInfo.Force * (StateArray[j]->InvMass / MassRatio) * ERP;
						}

						// Should we push?
						if ( push)
							CollisionArray.push_back( CollisionInfo);
					}
				}
			}
		}

		// Apply any required translations as requested above
		for( unsigned int i = 0; i < StateArray.size(); i++)
		{
			rBody* body = StateArray[i];

			// If there is a
			if( body->Force_T.LengthSquared() > 0)
			{
				body->Position += body->Force_T;
				body->CalculateMeshTranslation( body->Force_T);
				body->Force_T = rVector( 0, 0);
			}
		}
	}

	// Get collision points and process them
	for( unsigned int i = 0; i < CollisionArray.size(); i++)
	{
		// Get collision point
		rVector CollisionPoint = ::CollisionPoint( CollisionArray[i]);

		// Add current collision point to the array
#ifdef R_SAVE_COLLISIONPOINTS
		CollisionPoints.push_back( CollisionPoint);
#endif

		// Process the collisionpoint
		ProcessCollisionPoint(	CollisionArray[i].getBody1(),
								CollisionArray[i].getBody2(),
								CollisionPoint,
								CollisionArray[i].Force,
								dt);
	}
}