Ejemplo n.º 1
0
void PhysicsServer::SetObjectVel( int objID, const Vec3& v )
{
    if (objID < 0 || objID >= m_Objects.size()) return;
    PhysBody* pBody = m_Objects[objID]->GetRootBody();
    if (!pBody) return;
    pBody->SetVelocity( v );
}
Ejemplo n.º 2
0
void MainState::FireProjectile() {
	if (!m_FireReady) {
		return;
	}

	// (TODO:) manage projectiles; they are currently causing memory leaks
	
	Projectile* projectile = (Projectile*)m_EnginePtr->GetEntityManager()->CreateEntity("Projectile");
	projectile->TranslateTo(m_Player->GetWorldPosition());


	Texture* tex = m_EnginePtr->GetTextureRegistry()->GetTexture("projectile.png");
	Sprite* sprite = m_EntityManagerPtr->CreateSprite((Entity*)projectile, tex, 1);
	sprite->AddClip("idle", 0, 0, 30, 5, 1, 1, 1);
	sprite->SetOrigin(Vec2(0, 3));


	PhysBody* body = m_EntityManagerPtr->CreatePhysBody((Entity*)projectile, kPhysBodyDynamic, kPhysLayerFriendProj);
	body->SetOrigin(Vec2(0, 3));
	body->SetWidth(30.0);
	body->SetHeight(5.0);


	if (m_Player->GetFlipY()) {
		projectile->FlipY(true);
		body->SetVelocity(Vec2(-1.0, 0.0));
	}
	else {
		projectile->FlipY(false);
		body->SetVelocity(Vec2(1.0, 0.0));
	}

	m_EnginePtr->GetScene()->AddEntity(projectile, 0);

	// Adds the projectile to the projectile array
	m_ProjectileArray.PushBack(projectile);

	m_FireReady = false;
}