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::Ball>();
m_World->ComponentFactory.Register<Components::Brick>(); m_World->ComponentFactory.Register<Components::Brick>();
m_World->ComponentFactory.Register<Components::Pad>(); m_World->ComponentFactory.Register<Components::Pad>();
m_World->ComponentFactory.Register<Components::Life>();
m_World->SystemFactory.Register<Systems::PhysicsSystem>( m_World->SystemFactory.Register<Systems::PhysicsSystem>(
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); }); [this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
m_World->AddSystem<Systems::PhysicsSystem>(); m_World->AddSystem<Systems::PhysicsSystem>();
@@ -97,7 +98,7 @@ public:
//TODO: Remove tobias light-test code. //TODO: Remove tobias light-test code.
{ /*{
auto t_BrickWall = m_World->CreateEntity(); auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall); auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.f, 0.f, -10.f); transform->Position = glm::vec3(0.f, 0.f, -10.f);
@@ -106,7 +107,7 @@ public:
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png"; sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png"; sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.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) 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); std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
transform->Position = glm::vec3(-11.f + number, -8.f, -10.f); transform->Position = glm::vec3(-11.f + number, -8.f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f); 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); std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
sprite->SpriteFile = "Textures/Ball.png"; sprite->SpriteFile = "Textures/Ball.png";
m_World->CommitEntity(life);*/ m_World->CommitEntity(life);
} }
void dd::Systems::LevelSystem::Update(double dt) 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); auto transformBall = m_World->GetComponent<Components::Transform>(entity);
if (transformBall->Position.y < -10) if (transformBall->Position.y < -10)
{
if (lives == pastLives)
{ {
Events::BallFellOffStage e; Events::BallFellOffStage e;
e.entity = entity; e.entity = entity;
@@ -65,6 +67,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
return; return;
} }
} }
}
if (lives != pastLives) if (lives != pastLives)
{ {
@@ -72,9 +75,8 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
if (life != NULL) if (life != NULL)
{ {
if (life->number + 1 == pastLives) { if (life->number + 1 == pastLives) {
pastLives--; m_World->RemoveEntity(entity);
pastLives = lives;
//m_World->RemoveEntity(entity);
} }
} }
} }
@@ -196,8 +198,8 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
bool dd::Systems::LevelSystem::BallFellOffStage(const dd::Events::BallFellOffStage &event) bool dd::Systems::LevelSystem::BallFellOffStage(const dd::Events::BallFellOffStage &event)
{ {
/*std::cout << "Did you get here?" << std::endl; std::cout << "Did you get here?" << std::endl;
EntityID entity = event.entity; /*EntityID entity = event.entity;
//Temporary. Create new ball. //Temporary. Create new ball.
auto ent = m_World->CreateEntity(); 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) void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto ball = m_World->GetComponent<Components::Ball>(entity); auto ball = m_World->GetComponent<Components::Ball>(entity);
if (replaceBall == true) if (ball != NULL) {
{ if (replaceBall == true) {
replaceBall = false; replaceBall = false;
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
transformEntity->Position = glm::vec3(20, 20, -10);
//Temporary. Create new ball. //Temporary. Create new ball.
auto ent = m_World->CreateEntity(); auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent); std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
@@ -57,6 +60,7 @@ void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID p
e.Point = glm::vec2(transform->Position.x, transform->Position.y); e.Point = glm::vec2(transform->Position.x, transform->Position.y);
EventBroker->Publish(e); EventBroker->Publish(e);
} }
}
} }
void dd::Systems::PadSystem::Update(double dt) 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; b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) { if (m_World->GetEntityParent(entity) == 0) {
@@ -85,7 +87,8 @@ void dd::Systems::PhysicsSystem::Update(double dt)
b2Body* body = i.second; b2Body* body = i.second;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (! transformComponent)
continue;
if (m_World->GetEntityParent(entity) == 0) { if (m_World->GetEntityParent(entity) == 0) {
b2Vec2 position = body->GetPosition(); b2Vec2 position = body->GetPosition();
@@ -119,10 +122,13 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
{ {
b2Body* body = m_EntitiesToBodies[entity]; b2Body* body = m_EntitiesToBodies[entity];
if (body != nullptr) {
m_EntitiesToBodies.erase(entity); m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body); m_BodiesToEntities.erase(body);
m_PhysicsWorld->DestroyBody(body); m_PhysicsWorld->DestroyBody(body);
}
} }