Lives kind of work, and so does the demo!

This commit is contained in:
PlatinumSkink
2015-09-15 13:35:04 +02:00
parent 9db15aa898
commit ce878ac1db
4 changed files with 51 additions and 38 deletions
+3 -2
View File
@@ -81,6 +81,7 @@ public:
m_World->ComponentFactory.Register<Components::Ball>();
m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>();
m_World->ComponentFactory.Register<Components::Life>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>();
@@ -97,7 +98,7 @@ public:
//TODO: Remove tobias light-test code.
{
/*{
auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
@@ -106,7 +107,7 @@ public:
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}
}*/
{
+9 -7
View File
@@ -22,7 +22,7 @@ void dd::Systems::LevelSystem::Initialize()
void dd::Systems::LevelSystem::CreateLife(int number)
{
/*auto life = m_World->CreateEntity();
auto life = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-11.f + number, -8.f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
@@ -33,7 +33,7 @@ void dd::Systems::LevelSystem::CreateLife(int number)
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
sprite->SpriteFile = "Textures/Ball.png";
m_World->CommitEntity(life);*/
m_World->CommitEntity(life);
}
void dd::Systems::LevelSystem::Update(double dt)
@@ -58,6 +58,8 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
{
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (transformBall->Position.y < -10)
{
if (lives == pastLives)
{
Events::BallFellOffStage e;
e.entity = entity;
@@ -65,6 +67,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
return;
}
}
}
if (lives != pastLives)
{
@@ -72,9 +75,8 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
if (life != NULL)
{
if (life->number + 1 == pastLives) {
pastLives--;
//m_World->RemoveEntity(entity);
m_World->RemoveEntity(entity);
pastLives = lives;
}
}
}
@@ -196,8 +198,8 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
bool dd::Systems::LevelSystem::BallFellOffStage(const dd::Events::BallFellOffStage &event)
{
/*std::cout << "Did you get here?" << std::endl;
EntityID entity = event.entity;
std::cout << "Did you get here?" << std::endl;
/*EntityID entity = event.entity;
//Temporary. Create new ball.
auto ent = m_World->CreateEntity();
+6 -2
View File
@@ -32,10 +32,13 @@ void dd::Systems::PadSystem::Initialize()
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto ball = m_World->GetComponent<Components::Ball>(entity);
if (replaceBall == true)
{
if (ball != NULL) {
if (replaceBall == true) {
replaceBall = false;
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
transformEntity->Position = glm::vec3(20, 20, -10);
//Temporary. Create new ball.
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
@@ -58,6 +61,7 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
EventBroker->Publish(e);
}
}
}
void dd::Systems::PadSystem::Update(double dt)
{
+7 -1
View File
@@ -49,6 +49,8 @@ void dd::Systems::PhysicsSystem::Update(double dt)
b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) {
@@ -85,7 +87,8 @@ void dd::Systems::PhysicsSystem::Update(double dt)
b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) {
b2Vec2 position = body->GetPosition();
@@ -119,12 +122,15 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{
b2Body* body = m_EntitiesToBodies[entity];
if (body != nullptr) {
m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body);
m_PhysicsWorld->DestroyBody(body);
}
}
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
{