コード例 #1
0
// If we've just taken damage, deal with the invincibility animation
void Player::HandleInvincibility(const jutil::GameTime& timespan)
{
	m_TimerInvincibility += timespan;

	// Flash the player sprite
	if (m_TimerInvincibility.ElapsedMilliseconds() % 4 == 0)
		SetAlpha(1.f);
	else
		SetAlpha(0.f);

	// If just been hit, apply a force to the player
	if (m_TimerInvincibility.ElapsedMilliseconds() < INVINCIBILITY_TIME*0.2f)
	{
		jmath::vec3 f;

		GetRigidBody()->ClearVelocity();

		if (m_TimerInvincibility.ElapsedMilliseconds() < 70)
			f.y = -0.6;
		if (m_TimerInvincibility.ElapsedMilliseconds() < 70)
			f.x = -0.3;
		if (m_Direction == Mega::Direction::LEFT)
			f.x = -f.x;

		GetRigidBody()->ApplyForce(f);

		m_PlayerState = TAKING_DAMAGE;
	}
	else
		m_PlayerState = UNKNOWN;
}
コード例 #2
0
void Level1Part1::initGameObjects(){

	// Boden Für Alle MapParts
	auto normalGround = new Ground(Vektoria::CHVector(2, 2.0, 42));
	normalGround->setName("NormalGround");
	normalGround->GetRigidBody()->GetCollider()->SetLayer(normalGround->getName());
	normalGround->getPlacement()->Translate(0, -1.0, -20);
	addGameObject(normalGround);
	// Fallenboden Für Alle MapParts
	auto pitGround = new Ground(Vektoria::CHVector(10, 2.0, 42));
	pitGround->setName("PitGround");
	pitGround->GetRigidBody()->GetCollider()->SetLayer(pitGround->getName());
	pitGround->getPlacement()->Translate(0, -1.5, -20);
	addGameObject(pitGround);

	PhysicsModule* physicsModule = ENGINE_PHYSICS;
	physicsModule->SetLayerProperty("NormalGround", "PitGround", false);
	physicsModule->SetLayerProperty("Player", "NormaleGround", true);
	physicsModule->SetLayerProperty("Player", "PitGround", false);
	

	// Mapbegrenzung
	auto wallLeft = new MapWall(Vektoria::CHVector(1.0f, 0.5f, 8.0f));
	wallLeft->getPlacement()->Translate(-1.1f, 0.25f, -4.0f);
	addGameObject(wallLeft);

	auto wallRight = new MapWall(Vektoria::CHVector(1.0f, 0.5f, 8.0f));
	wallRight->getPlacement()->Translate(1.1f, 0.25f, -4.0f);
	addGameObject(wallRight);

	// Fallen und Wände
	addGameObjectsFromFile("GameResources\\Levels\\level1\\part1\\gameobjects_part1.txt");

}
コード例 #3
0
PierrobotGear::PierrobotGear(jmath::vec2 pos, jvis::Texture* tex) :
	Enemy(pos, tex,
	Mega::Data::PIERROBOT_GEAR_NORMAL_HP, Mega::Data::PIERROBOT_GEAR_DIFFICULT_HP, // HP normal/difficult
	Mega::Data::PIERROBOT_GEAR_NORMAL_CONTACT_DMG, Mega::Data::PIERROBOT_GEAR_DIFFICULT_CONTACT_DMG) // Damage normal/difficult
{
	GetRigidBody()->SetCollisionFlags(jphys::ResolveX);
	GetRigidBody()->SetCollisionFlags(jphys::ResolveY);
}
コード例 #4
0
MT_Scalar	KX_BulletPhysicsController::GetMass()
{
	if (GetSoftBody())
		return GetSoftBody()->getTotalMass();
	
	MT_Scalar invmass = 0.f;
	if (GetRigidBody())
		invmass = GetRigidBody()->getInvMass();
	if (invmass)
		return 1.f/invmass;
	return 0.f;

}
コード例 #5
0
MT_Vector3 KX_BulletPhysicsController::GetLocalInertia()
{
	MT_Vector3 inertia(0.f, 0.f, 0.f);
	btVector3 inv_inertia;
	if (GetRigidBody()) {
		inv_inertia = GetRigidBody()->getInvInertiaDiagLocal();
		if (!btFuzzyZero(inv_inertia.getX()) &&
		        !btFuzzyZero(inv_inertia.getY()) &&
		        !btFuzzyZero(inv_inertia.getZ()))
			inertia = MT_Vector3(1.f/inv_inertia.getX(), 1.f/inv_inertia.getY(), 1.f/inv_inertia.getZ());
	}
	return inertia;
}
コード例 #6
0
void PierrobotGear::Spawn(jvis::AnimatedSprite& player)
{
	Enemy::Spawn(player);

	_direction = (player.GetPosition().x - m_SpawnPos.x <= 0) ? Mega::Direction::LEFT : Mega::Direction::RIGHT;

	SetNumColumns(1);
	SetNumFrames(2);
	SetDelay(160);

	SetSize(jmath::vec2(32));
	SetRectangle(jmath::vec4(72, 68, 32, 32));
	GetRigidBody()->SetCollisionType(jphys::BOX_REACTIVE);
	GetRigidBody()->SetVelocity(0);
}
コード例 #7
0
ファイル: Pin.cpp プロジェクト: Hengplank/kucgbowling
void Pin::GetBox(Box& boxOut)
{
    boxOut.Center() = GetRigidBody().GetPosition();
    
    Vector3 boxAxisX = GetRigidBody().GetROrientation() * Vector3::UNIT_X;
    Vector3 boxAxisY = GetRigidBody().GetROrientation() * Vector3::UNIT_Y;
    Vector3 boxAxisZ = GetRigidBody().GetROrientation() * Vector3::UNIT_Z;
    boxOut.Axis(0) = boxAxisX;
    boxOut.Axis(1) = boxAxisY;
    boxOut.Axis(2) = boxAxisZ;
    
    boxOut.Extent(0) = 0.31128f;
    boxOut.Extent(1) = 0.31128f;
    boxOut.Extent(2) = 0.97743f;
}
コード例 #8
0
    void GenericConstraintComponent::SetAttachments(SceneNode &sceneNodeB, const glm::mat4 &frameB)
    {
        RigidBody* bodyB = nullptr;

        auto dynamicsComponent = sceneNodeB.GetComponent<DynamicsComponent>();
        if (dynamicsComponent != nullptr)
        {
            dynamicsComponent->ApplySceneNodeScaling();
            dynamicsComponent->ApplySceneNodeTransformation();
            bodyB = &dynamicsComponent->GetRigidBody();
        }



        assert(bodyB != nullptr);



        if (this->constraint == nullptr)
        {
            this->constraint = new GenericConstraint(*bodyB, frameB);
        }
        else
        {
            this->constraint->SetAttachments(*bodyB, frameB);
        }


        this->OnChanged();
    }
コード例 #9
0
bool PierrobotGear::CheckToSwitchDirection(LevelLoader& level)
{
	jmath::vec2 tileCheck;
	tileCheck.x = (int)GetRigidBody()->GetPosition().x - ((int)GetRigidBody()->GetPosition().x % 16);
	tileCheck.y = (int)GetRigidBody()->GetPosition().y - ((int)GetRigidBody()->GetPosition().y % 16);

	tileCheck.x += _direction ? 16 : -32;


	if (level.TileExists(tileCheck))
	{
		tileCheck.x += _direction ? -0 : 16;

		if (jphys::BoundingBoxCentred(tileCheck, jmath::vec4(GetPositionXY(), GetRigidBody()->GetHitboxXY())))
			return true;
	}

	return false;
}
コード例 #10
0
/* Reverse function of the above, it will remove a shape from a compound shape
 * provided that the former was added to the later using  AddCompoundChild()
 */
void    KX_BulletPhysicsController::RemoveCompoundChild(KX_IPhysicsController* child)
{ 
	if (child == NULL || !IsCompound())
		return;
	// other controller must be a bullet controller too
	// verify that body and shape exist and match
	KX_BulletPhysicsController* childCtrl = dynamic_cast<KX_BulletPhysicsController*>(child);
	btRigidBody* rootBody = GetRigidBody();
	btRigidBody* childBody = childCtrl->GetRigidBody();
	if (!rootBody || !childBody)
		return;
	const btCollisionShape* rootShape = rootBody->getCollisionShape();
	if (!rootShape || 
		rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE)
		return;
	btCompoundShape* compoundShape = (btCompoundShape*)rootShape;
	// retrieve the shapeInfo
	CcdShapeConstructionInfo* childShapeInfo = childCtrl->GetShapeInfo();
	CcdShapeConstructionInfo* rootShapeInfo = GetShapeInfo();
	// and verify that the child is part of the parent
	int i = rootShapeInfo->FindChildShape(childShapeInfo, childCtrl);
	if (i < 0)
		return;
	rootShapeInfo->RemoveChildShape(i);
	if (childCtrl->m_bulletChildShape)
	{
		int numChildren = compoundShape->getNumChildShapes();
		for (i=0; i<numChildren; i++)
		{
			if (compoundShape->getChildShape(i) == childCtrl->m_bulletChildShape)
			{
				compoundShape->removeChildShapeByIndex(i);
				compoundShape->recalculateLocalAabb();
				break;
			}
		}
		delete childCtrl->m_bulletChildShape;
		childCtrl->m_bulletChildShape = NULL;
	}
	// recompute inertia of parent
	if (!rootBody->isStaticOrKinematicObject())
	{
		btVector3 localInertia;
		float mass = 1.f/rootBody->getInvMass();
		compoundShape->calculateLocalInertia(mass,localInertia);
		rootBody->setMassProps(mass,localInertia);
	}
	// must update the broadphase cache,
	GetPhysicsEnvironment()->refreshCcdPhysicsController(this);
	// reactivate the children
	GetPhysicsEnvironment()->enableCcdPhysicsController(childCtrl);
}
コード例 #11
0
ファイル: PlayerCar.cpp プロジェクト: AlanWills/SpinOut
//-----------------------------------------------------------------------------------------------------------------------------------
void PlayerCar::HandleInput(float elapsedGameTime, const Vector2& mousePosition)
{
  Car::HandleInput(elapsedGameTime, mousePosition);

  if (AcceptsInput())
  {
    const KeyboardInput& keyboard = ScreenManager::GetKeyboardInput();
    float velocityDiff = 0;
    float angleDiff = 0;

    bool notCollided = GetCollider()->GetCollisionStatus() == CollisionStatus::kStillNotCollided;

    if (keyboard.IsKeyDown(Keyboard::Keys::W) && notCollided)
    {
      velocityDiff += GetCarData()->GetAcceleration();
    }

    if (keyboard.IsKeyDown(Keyboard::Keys::S) && notCollided)
    {
      velocityDiff += -GetCarData()->GetBraking();
    }

    if (keyboard.IsKeyDown(Keyboard::Keys::A))
    {
      angleDiff = -GetCarData()->GetHandling();
    }

    if (keyboard.IsKeyDown(Keyboard::Keys::D))
    {
      angleDiff = GetCarData()->GetHandling();
    }

    GetRigidBody()->SetLinearAcceleration(Vector2(0, velocityDiff));
    GetRigidBody()->SetAngularVelocity(angleDiff);
  }
}
コード例 #12
0
void PierrobotGear::EnemyFunctionality(jvis::AnimatedSprite& player, LevelLoader& level, const jutil::GameTime& gametime)
{
	std::vector<jmath::vec2> collisions = level.CheckReturnCollision(*this);

	if (CheckToSwitchDirection(level))
		Mega::SwitchDirection(_direction);

	if (collisions.size() > 0)
	{
		float speed = 0.1f;
		if (_direction == Mega::Direction::LEFT)
			speed = -speed;

		GetRigidBody()->ApplyForce(jmath::vec3(speed, 0.f, 0.f));
	}
	jvis::AnimatedSprite::Update(gametime);
}
コード例 #13
0
void	KX_BulletPhysicsController::RestoreDynamics()
{
	btRigidBody *body = GetRigidBody();
	if (body && m_suspended)
	{
		// before make sure any position change that was done in this logic frame are accounted for
		SetTransform();
		GetPhysicsEnvironment()->updateCcdPhysicsController(this, 
			m_savedMass,
			m_savedCollisionFlags,
			m_savedCollisionFilterGroup,
			m_savedCollisionFilterMask);
		body->activate();
		m_bDyna = m_savedDyna;
		m_suspended = false;
	}
}
コード例 #14
0
void KX_BulletPhysicsController::SetMass(MT_Scalar newmass)
{
	btRigidBody *body = GetRigidBody();
	if (body && !m_suspended && newmass>MT_EPSILON && GetMass()>MT_EPSILON)
	{
		btVector3 grav = body->getGravity();
		btVector3 accel = grav / GetMass();
		
		btBroadphaseProxy* handle = body->getBroadphaseHandle();
		GetPhysicsEnvironment()->updateCcdPhysicsController(this, 
			newmass,
			body->getCollisionFlags(),
			handle->m_collisionFilterGroup, 
			handle->m_collisionFilterMask);
		body->setGravity(accel);
	}
}
コード例 #15
0
// Resolve collisions against the level tiles
void Player::HandleLevelCollisionResolution(const jutil::GameTime& timespan)
{
	m_HasCollidedBelow = false;

	// Set collision boxes to match changes in player position
	m_CollisionY.SetPosition(GetPosition());
	m_CollisionX.SetPosition(GetPosition());

	//Apply player force to collision body
	m_CollisionY.GetRigidBody()->ApplyForce(GetRigidBody()->GetForce());


	// Resolve collision on Y
	p_Level->CheckCollision(m_CollisionY);
	m_CollisionY.Update(timespan);
	jvis::AnimatedSprite::Update(timespan);

	// Resolve once more after gravitational updates
	p_Level->CheckCollision(m_CollisionY);

	// Resolve collision on X and grab positions of local blocks
	m_CollisionX.SetPosition(m_CollisionY.GetPosition());
	std::vector<jmath::vec2> collisions = p_Level->CheckReturnCollision(m_CollisionX);

	// Handle whether or not we're on a tile (i.e. whether we're allowed to jump)
	for (int i = 0; i < collisions.size(); ++i)
	{
		if (collisions[i].y <= m_CollisionY.GetRigidBody()->GetPosition().y)
		{
			if (std::abs(collisions[i].x + 8 - m_CollisionX.GetRigidBody()->GetPosition().x) < 10
				&& collisions[i].y - m_CollisionY.GetRigidBody()->GetPosition().y > -32)
				m_TimerJump.SetTime(JTime::Milliseconds(JUMP_LIMIT));
			continue;
		}
		if (collisions[i].y - m_CollisionY.GetRigidBody()->GetPosition().y <= m_CollisionY.GetRigidBody()->GetHitboxXY().y / 2//&& collisions[i].y - m_CollisionY.GetRigidBody()->GetPosition().y < 24
			&& std::abs(collisions[i].x + 7 - m_CollisionX.GetRigidBody()->GetPosition().x) < 10) // this used to be +8
		{
			m_HasCollidedBelow = true;
			break;
		}
	}

	m_CollisionY.SetPosition(m_CollisionX.GetPosition());
	SetPosition(m_CollisionX.GetPosition());
}
コード例 #16
0
Player::Player(jframe::Window* window, jvis::Texture* tex, LevelLoader* level, const jmath::vec4& rect, int cols, int frames, int delay)
	:
	p_Window(window),
	m_CanJump(true),
	m_JumpBtnHeld(false),
	m_Health(0), // 28
	m_TimerJump(0),
	m_Direction(Mega::Direction::RIGHT),
	jvis::AnimatedSprite(tex, rect, cols, 1, delay)
{
	p_Level = level;

	SetDelay(delay);

	// Physics setup
	SetSize(jmath::vec2(32, 32));
	GetRigidBody()->SetFriction(1.f);
	GetRigidBody()->SetMass(15.f);
	GetRigidBody()->SetDimensions(jmath::vec3(18, 28, 0));
	GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE);

	// Collision flags are removed because m_CollisionX and Y will deal with it
	GetRigidBody()->RemoveCollisionFlags(jphys::CollisionFlags::ResolveX);
	GetRigidBody()->RemoveCollisionFlags(jphys::CollisionFlags::ResolveY);


	// Collision resolution setup - these are to resolve X and Y collision separately
	m_CollisionY.GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE);
	m_CollisionY.GetRigidBody()->SetCollisionFlags(jphys::CollisionFlags::ResolveY);
	m_CollisionY.SetSize(jmath::vec2(8, 28));
	m_CollisionY.GetRigidBody()->MoveY(-3);

	m_CollisionX.GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE);
	m_CollisionX.GetRigidBody()->SetCollisionFlags(jphys::CollisionFlags::ResolveX);
	m_CollisionX.SetSize(jmath::vec2(18, 24));
	m_CollisionX.GetRigidBody()->MoveY(-3);

	// The 12 sprites that move outwards upon death
	for (int i = 0; i < 12; ++i)
	{
		m_DeathSprites.push_back(AnimatedSprite());
		m_DeathSprites.back().SetRectangle(jmath::vec4(8, 184, 16, 16));
		m_DeathSprites.back().SetSize(jmath::vec2(16));
		m_DeathSprites.back().SetNumColumns(4);
		m_DeathSprites.back().SetNumFrames(4);
		m_DeathSprites.back().SetTexture(GetTexture());
	}

	m_TimerDeath.SetTime(JTime::Milliseconds(DEATH_ANIMATION_TIME));
	m_TimerInvincibility.SetTime(JTime::Milliseconds(INVINCIBILITY_TIME));
	m_TimerBulletAnimationDelay.SetTime(JTime::Milliseconds(FIRING_ANIMATION_DELAY));
}
コード例 #17
0
void	KX_BulletPhysicsController::SuspendDynamics(bool ghost)
{
	btRigidBody *body = GetRigidBody();
	if (body && !m_suspended && !IsSensor())
	{
		btBroadphaseProxy* handle = body->getBroadphaseHandle();
		m_savedCollisionFlags = body->getCollisionFlags();
		m_savedMass = GetMass();
		m_savedDyna = m_bDyna;
		m_savedCollisionFilterGroup = handle->m_collisionFilterGroup;
		m_savedCollisionFilterMask = handle->m_collisionFilterMask;
		m_suspended = true;
		GetPhysicsEnvironment()->updateCcdPhysicsController(this, 
			0.0,
			btCollisionObject::CF_STATIC_OBJECT|((ghost)?btCollisionObject::CF_NO_CONTACT_RESPONSE:(m_savedCollisionFlags&btCollisionObject::CF_NO_CONTACT_RESPONSE)),
			btBroadphaseProxy::StaticFilter, 
			btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
		m_bDyna = false;
	}
}
コード例 #18
0
ファイル: player.cpp プロジェクト: phildunstan/apollo
void ApplyPlayerInput(const Time& time, const PlayerInput& playerInput)
{
	auto& playerRB = GetRigidBody(player.objectId);
	playerRB.velocity = playerInput.movement * playerMovementSpeed;

	if (glm::length(playerInput.facing) > 0.5f)
	{
		auto playerHeading = atan2f(-playerRB.facing.x, playerRB.facing.y);
		auto normalizedInput = glm::normalize(playerInput.facing);
		auto desiredHeading = atan2f(-normalizedInput.x, normalizedInput.y);
		auto delta = desiredHeading - playerHeading;
		if (delta < -PI)
		{
			delta += TWO_PI;
		}
		else if (delta > PI)
		{
			delta -= TWO_PI;
		}
		delta = clamp(delta, -playerRotationSpeed, playerRotationSpeed);
		auto newHeading = playerHeading + delta;

		playerRB.facing = Vector2(-sin(newHeading), cos(newHeading));
	}

	//// stop the player movement if they are colliding with the edge of the screen
	//const auto& collisionObject = GetCollisionObject(player.objectId);
	//Vector2 futurePosition = playerRB.position + playerRB.velocity * time.deltaTime;
	//if (BoundingBoxCollidesWithWorldEdge(futurePosition, playerRB.facing, collisionObject.boundingBoxDimensions))
	//{
	//	playerRB.velocity = Vector2 { 0.0f, 0.0f };
	//}

	if (playerInput.firing && ((time.elapsedTime - playerTimeOfLastShot) > 1.0f / playerFireRate))
	{
		FirePlayerBullet();
		playerTimeOfLastShot = time.elapsedTime;
	}
}
コード例 #19
0
void	KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
{

	if (!m_bDyna && !m_bSensor && !m_bCharacter)
	{
		btCollisionObject* object = GetRigidBody();
		object->setActivationState(ACTIVE_TAG);
		object->setCollisionFlags(object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
	} else
	{
		if (!nondynaonly)
		{
			/*
			btTransform worldTrans;
			if (GetRigidBody())
			{
				GetRigidBody()->getMotionState()->getWorldTransform(worldTrans);
				GetRigidBody()->setCenterOfMassTransform(worldTrans);
			}
			*/
			/*
			scaling?
			if (m_bDyna)
			{
				m_sumoObj->setScaling(MT_Vector3(1,1,1));
			} else
			{
				MT_Vector3 scale;
				GetWorldScaling(scale);
				m_sumoObj->setScaling(scale);
			}
			*/

		}
	}
}
コード例 #20
0
ファイル: Pin.cpp プロジェクト: Hengplank/kucgbowling
void Pin::GetBox(Vector3 box[8])
{
    // move the box vertices
    for (int i = 0; i < BoxVerticeCount; i++)
        box[i] = GetRigidBody().GetROrientation()*box_[i] + GetRigidBody().GetPosition();
}
コード例 #21
0
/* This function dynamically adds the collision shape of another controller to
 * the current controller shape provided it is a compound shape.
 * The idea is that dynamic parenting on a compound object will dynamically extend the shape
 */
void    KX_BulletPhysicsController::AddCompoundChild(KX_IPhysicsController* child)
{ 
	if (child == NULL || !IsCompound())
		return;
	// other controller must be a bullet controller too
	// verify that body and shape exist and match
	KX_BulletPhysicsController* childCtrl = dynamic_cast<KX_BulletPhysicsController*>(child);
	btRigidBody* rootBody = GetRigidBody();
	btRigidBody* childBody = childCtrl->GetRigidBody();
	if (!rootBody || !childBody)
		return;
	const btCollisionShape* rootShape = rootBody->getCollisionShape();
	const btCollisionShape* childShape = childBody->getCollisionShape();
	if (!rootShape || 
		!childShape || 
		rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE ||
		childShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
		return;
	btCompoundShape* compoundShape = (btCompoundShape*)rootShape;
	// compute relative transformation between parent and child
	btTransform rootTrans;
	btTransform childTrans;
	rootBody->getMotionState()->getWorldTransform(rootTrans);
	childBody->getMotionState()->getWorldTransform(childTrans);
	btVector3 rootScale = rootShape->getLocalScaling();
	rootScale[0] = 1.0/rootScale[0];
	rootScale[1] = 1.0/rootScale[1];
	rootScale[2] = 1.0/rootScale[2];
	// relative scale = child_scale/parent_scale
	btVector3 relativeScale = childShape->getLocalScaling()*rootScale;
	btMatrix3x3 rootRotInverse = rootTrans.getBasis().transpose();
	// relative pos = parent_rot^-1 * ((parent_pos-child_pos)/parent_scale)
	btVector3 relativePos = rootRotInverse*((childTrans.getOrigin()-rootTrans.getOrigin())*rootScale);
	// relative rot = parent_rot^-1 * child_rot
	btMatrix3x3 relativeRot = rootRotInverse*childTrans.getBasis();
	// create a proxy shape info to store the transformation
	CcdShapeConstructionInfo* proxyShapeInfo = new CcdShapeConstructionInfo();
	// store the transformation to this object shapeinfo
	proxyShapeInfo->m_childTrans.setOrigin(relativePos);
	proxyShapeInfo->m_childTrans.setBasis(relativeRot);
	proxyShapeInfo->m_childScale.setValue(relativeScale[0], relativeScale[1], relativeScale[2]);
	// we will need this to make sure that we remove the right proxy later when unparenting
	proxyShapeInfo->m_userData = childCtrl;
	proxyShapeInfo->SetProxy(childCtrl->GetShapeInfo()->AddRef());
	// add to parent compound shapeinfo (increments ref count)
	GetShapeInfo()->AddShape(proxyShapeInfo);
	// create new bullet collision shape from the object shapeinfo and set scaling
	btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin(), childCtrl->getConstructionInfo().m_bGimpact, true);
	newChildShape->setLocalScaling(relativeScale);
	// add bullet collision shape to parent compound collision shape
	compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape);
	// proxyShapeInfo is not needed anymore, release it
	proxyShapeInfo->Release();
	// remember we created this shape
	childCtrl->m_bulletChildShape = newChildShape;
	// recompute inertia of parent
	if (!rootBody->isStaticOrKinematicObject())
	{
		btVector3 localInertia;
		float mass = 1.f/rootBody->getInvMass();
		compoundShape->calculateLocalInertia(mass,localInertia);
		rootBody->setMassProps(mass,localInertia);
	}
	// must update the broadphase cache,
	GetPhysicsEnvironment()->refreshCcdPhysicsController(this);
	// remove the children
	GetPhysicsEnvironment()->disableCcdPhysicsController(childCtrl);
}
コード例 #22
0
void Player::HandleControls(const jutil::GameTime& timespan)
{

	// Directional movement
	if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_PRESS)
		MoveX(-0.05f);
	if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD)
	{
		GetRigidBody()->ApplyForce(jmath::vec3(-0.5f, 0.f, 0.f));
		m_Direction = Mega::Direction::LEFT;
	}
	else if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_RELEASE)
		GetRigidBody()->ClearForce();
	if (p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD)
	{
		GetRigidBody()->ApplyForce(jmath::vec3(0.5f, 0.f, 0.f));
		m_Direction = Mega::Direction::RIGHT;
	}
	
	/// Jumping

	// If space bar is just released, prevent jumping (to stop double jumping in the air)
	if (p_Window->GetKey(Mega::Keys::JUMP) == JKEY_RELEASE && m_TimerJump.ElapsedMilliseconds() > 0)
		m_TimerJump.SetTime(JTime::Milliseconds(JUMP_LIMIT));

	// If the player is standing on a block, allow jumping
	if (m_HasCollidedBelow && m_TimerJump.ElapsedMilliseconds() > 0 && m_TimerJump.ElapsedMilliseconds() >= JUMP_LIMIT && !(p_Window->GetKey(Mega::Keys::JUMP) == JKEY_PRESS || p_Window->GetKey(Mega::Keys::JUMP) == JKEY_HOLD))
		m_TimerJump.SetTime(JTime::Milliseconds(0));

	// If the player is mid-jump and can still hold the button for a longer jump, apply forces
	if (m_TimerJump.ElapsedMilliseconds() >= 0 && m_TimerJump.ElapsedMilliseconds() < JUMP_LIMIT && p_Window->GetKey(Mega::Keys::JUMP) == JKEY_HOLD)
	{
		m_TimerJump += timespan;
		if (m_TimerJump.ElapsedMilliseconds() < JUMP_LIMIT)
		{
			m_PlayerState = PlayerState::JUMPING;

			float t = std::max(m_TimerJump.ElapsedMilliseconds(), 250);
			GetRigidBody()->ApplyForce(jmath::vec3(0, -0.0095f*((t) / 12.f), 0.f));

			if (m_TimerJump.ElapsedMilliseconds() == timespan.ElapsedMilliseconds())
				GetRigidBody()->ApplyForce(jmath::vec3(0.f, -3.f, 0.f));

			if (m_TimerJump.ElapsedMilliseconds() != 0 && m_TimerJump.ElapsedMilliseconds() < 100)
			{
				jmath::vec3 v = GetRigidBody()->GetVelocity();
				v.x = 0.f;
				GetRigidBody()->SetVelocity(v);

				v = m_CollisionY.GetRigidBody()->GetVelocity();
				v.x = 0.f;
				m_CollisionY.GetRigidBody()->SetVelocity(v);

			}
		}
	}
	// Otherwise, we've ran out of jumping time 
	else if (m_TimerJump.ElapsedMilliseconds() < 0) 
	{
		m_TimerJump += timespan;
		if (m_TimerJump.ElapsedMilliseconds() > 0)
			m_TimerJump.SetTime(0);
	}

	// If the jump button has been released since jumping and we're on a tile, change state
	if (p_Window->GetKey(Mega::Keys::JUMP) != JKEY_HOLD && m_HasCollidedBelow)
		m_PlayerState = PlayerState::GROUNDED;


	m_TimerBulletAnimationDelay += timespan;

	//// Firing
	if (p_Window->GetKey(Mega::Keys::FIRE) == JKEY_PRESS)// && m_TimerBulletAnimationDelay.ElapsedMilliseconds() > FIRING_DELAY)
	{
		m_TimerBulletAnimationDelay.SetTime(0);
		jmath::vec2 pos = GetPositionXY();

		pos.x += static_cast<bool>(m_Direction) ? 12.f : -12.f;
		pos.y--;
		m_Bullets.push_back(Bullet(pos, m_Direction));
		m_Bullets.back().SetTexture(GetTexture());
		m_Bullets.back().SetRectangle(jmath::vec4(104, 72, 8, 8));
	}

	if (p_Window->GetKey(JKEY_KEY_C) == JKEY_PRESS)
		m_Health = 0;
}
コード例 #23
0
 void RigidBodyComponent::AddToWorld(btDynamicsWorld* world)
 {
     world->addRigidBody(&GetRigidBody());
 }
コード例 #24
0
	void RigidBodyComponent::RemoveFromWorld(btDynamicsWorld* world)
	{
		world->removeRigidBody(&GetRigidBody());
	}