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";
} }*/
{ {
+13 -11
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)
@@ -59,10 +59,13 @@ 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)
{ {
Events::BallFellOffStage e; if (lives == pastLives)
e.entity = entity; {
EventBroker->Publish(e); Events::BallFellOffStage e;
return; e.entity = entity;
EventBroker->Publish(e);
return;
}
} }
} }
@@ -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();
+25 -21
View File
@@ -32,30 +32,34 @@ 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;
//Temporary. Create new ball. auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
auto ent = m_World->CreateEntity(); transformEntity->Position = glm::vec3(20, 20, -10);
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.f, -10.f);;
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
sprite->SpriteFile = "Textures/Ball.png";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
m_World->RemoveEntity(entity); //Temporary. Create new ball.
m_World->CommitEntity(ent); auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.f, -10.f);;
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
sprite->SpriteFile = "Textures/Ball.png";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
Events::SetImpulse e; m_World->RemoveEntity(entity);
e.Entity = ent; m_World->CommitEntity(ent);
e.Impulse = glm::vec2(0.f, -7.f);
e.Point = glm::vec2(transform->Position.x, transform->Position.y); Events::SetImpulse e;
EventBroker->Publish(e); e.Entity = ent;
e.Impulse = glm::vec2(0.f, -7.f);
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
EventBroker->Publish(e);
}
} }
} }
+10 -4
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];
m_EntitiesToBodies.erase(entity); if (body != nullptr) {
m_BodiesToEntities.erase(body); m_EntitiesToBodies.erase(entity);
m_BodiesToEntities.erase(body);
m_PhysicsWorld->DestroyBody(body);
}
m_PhysicsWorld->DestroyBody(body);
} }