Fixed so generated bricks fo not collide with anything.
This commit is contained in:
@@ -24,6 +24,8 @@ struct Ball : Component
|
||||
bool Sticky = false;
|
||||
glm::vec3 StickyPlacement = glm::vec3(0, 0, 0);
|
||||
glm::vec3 SavedSpeed = glm::vec3(0, 1, 0);
|
||||
|
||||
int PosterBoy = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ struct Brick : Component
|
||||
int Type = 0;
|
||||
bool Removed = false;
|
||||
int Number = 100; // For the Kraken to keep track of which bricks needs replacing.
|
||||
bool BeingGenerated = false;
|
||||
glm::vec3 GenerationGoal;
|
||||
|
||||
//What number of types each is.
|
||||
const int EmptyBrickSpace = 0;
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace dd
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Life : Component {
|
||||
|
||||
struct Life : Component
|
||||
{
|
||||
int Number = 0;
|
||||
|
||||
float SinusAltitude = 1;
|
||||
bool Left = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ private:
|
||||
bool m_Pause = false;
|
||||
int m_Lives = 3;
|
||||
int m_PastLives = 3;
|
||||
float m_LifeSpeed = 0.8;
|
||||
|
||||
bool m_GodMode = false;
|
||||
|
||||
|
||||
@@ -64,6 +64,13 @@ void dd::Systems::BallSystem::Initialize()
|
||||
auto transform2 = m_World->GetComponent<Components::Transform>(ent2);
|
||||
transform2->Position = glm::vec3(-0.f, 0.26f, -10.f);
|
||||
transform2->Velocity = glm::vec3(0.0f, -10.f, 0.f);
|
||||
|
||||
/*auto PosterBoy = CreateBall();
|
||||
auto PosterBall = m_World->GetComponent<Components::Ball>(PosterBoy);
|
||||
PosterBall->PosterBoy = 1;
|
||||
auto Postertran = m_World->GetComponent<Components::Transform>(PosterBoy);
|
||||
Postertran->Position = glm::vec3(-3.f, -3.f, -10.f);
|
||||
Postertran->Velocity = glm::vec3(0.0f, 0.f, 0.f);*/
|
||||
}
|
||||
|
||||
SetReplaceBall(true);
|
||||
@@ -88,6 +95,11 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
if (templateCheck != nullptr){ return; }
|
||||
|
||||
if (ballComponent != nullptr) {
|
||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (ballComponent->PosterBoy == 1) {
|
||||
transformBall->Position = glm::vec3(-3, 3, -10);
|
||||
}
|
||||
|
||||
if (ReplaceBall()) {
|
||||
m_First = true;
|
||||
SetReplaceBall(false);
|
||||
@@ -97,24 +109,21 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
ballComponent->SavedSpeed = glm::vec3(random, 1, 0.f);
|
||||
//ballComponent->SavedSpeed = glm::vec3(0.f, 1, 0.f);
|
||||
ballComponent->Waiting = true;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
}
|
||||
|
||||
if (ballComponent->Waiting) {
|
||||
if (!m_Waiting) {
|
||||
m_Restarting = false;
|
||||
ballComponent->Waiting = false;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
/*std::uniform_real_distribution<float> dist(-0.5f, 0.5f);
|
||||
float random = dist(m_RandomGenerator);*/
|
||||
transform->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed;
|
||||
transformBall->Velocity = glm::normalize(ballComponent->SavedSpeed) * ballComponent->Speed;
|
||||
//transform->Velocity = glm::normalize(glm::vec3(0, 1, 0)) * ballComponent->Speed;
|
||||
} else if (!ballComponent->Sticky) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
transform->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||
transformBall->Velocity = glm::vec3(0.f, 0.f, 0.f);
|
||||
//transform->Position = glm::vec3(0.0f, -3.f, -10.f);
|
||||
if (m_First) {
|
||||
transform->Orientation = glm::quat();
|
||||
transformBall->Orientation = glm::quat();
|
||||
m_First = false;
|
||||
}
|
||||
return;
|
||||
@@ -124,8 +133,7 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
//TODO - Ball can stick to same pad just after detaching.
|
||||
if (!m_Waiting)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
transform->Velocity = ballComponent->SavedSpeed;
|
||||
transformBall->Velocity = ballComponent->SavedSpeed;
|
||||
m_StickyCounter--;
|
||||
if (m_StickyCounter > 0) {
|
||||
m_Sticky = true;
|
||||
@@ -134,7 +142,6 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
}
|
||||
}
|
||||
|
||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (glm::abs(transformBall->Velocity.y) < 2) {
|
||||
if (transformBall->Velocity.y > 0) {
|
||||
transformBall->Velocity.y = 2;
|
||||
|
||||
@@ -281,7 +281,19 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
|
||||
auto brick = m_World->GetComponent<Components::Brick>(entity);
|
||||
if (brick != nullptr) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (brick->BeingGenerated) {
|
||||
if (transform->Position == brick->GenerationGoal) {
|
||||
brick->BeingGenerated = false;
|
||||
auto cPhys = m_World->AddComponent<Components::Physics>(entity);
|
||||
cPhys->CollisionType = CollisionType::Type::Static;
|
||||
cPhys->GravityScale = 0.f;
|
||||
cPhys->Category = CollisionLayer::Type::Brick;
|
||||
cPhys->Mask = static_cast<CollisionLayer::Type>(CollisionLayer::Type::Ball | CollisionLayer::Type::Projectile | CollisionLayer::Type::Wall | CollisionLayer::LifeBuoy);
|
||||
}
|
||||
}
|
||||
|
||||
//Removes bricks that falls out of the stage.
|
||||
if (transform->Position.y < -10) {
|
||||
if (brick->Type == StandardBrick) {
|
||||
@@ -480,6 +492,8 @@ bool dd::Systems::LevelSystem::BrickGenerating(const dd::Events::BrickGenerating
|
||||
auto ent = CreateBrick(i, j, SpaceBetweenBricks(), SpaceToEdge(), -3.2, 1, m_BrickSet[getter], m_ColorSet[getter]);
|
||||
if (ent != NULL) {
|
||||
auto brick = m_World->GetComponent<Components::Brick>(ent);
|
||||
brick->BeingGenerated = true;
|
||||
m_World->RemoveComponent<Components::Physics>(ent);
|
||||
brick->Number = getter;
|
||||
m_KrakenBricks[getter] = true;
|
||||
auto transform = m_World->GetComponent<Components::Transform>(ent);
|
||||
@@ -490,6 +504,7 @@ bool dd::Systems::LevelSystem::BrickGenerating(const dd::Events::BrickGenerating
|
||||
} else {
|
||||
transform->Position = event.Origin2;
|
||||
}
|
||||
brick->GenerationGoal = e.GoalPosition;
|
||||
e.Entity = ent;
|
||||
e.Speed = 6;
|
||||
e.Queue = false;
|
||||
@@ -689,7 +704,11 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
||||
if (brick == nullptr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (brick->BeingGenerated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entityShot != 0) {
|
||||
// For when a brick gets shot.
|
||||
@@ -1101,7 +1120,7 @@ void dd::Systems::LevelSystem::GetNextLevel()
|
||||
1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0, 1, 2, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 6,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0};
|
||||
color =
|
||||
{w, w, w, w, w, w, w,
|
||||
|
||||
@@ -47,10 +47,29 @@ void dd::Systems::LifeSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
|
||||
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateCheck != nullptr){ return; }
|
||||
auto life = m_World->GetComponent<Components::Life>(entity);
|
||||
|
||||
if (Lives() != PastLives()) {
|
||||
auto life = m_World->GetComponent<Components::Life>(entity);
|
||||
if (life != nullptr) {
|
||||
|
||||
if (life != nullptr) {
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (life->Left) {
|
||||
if (transform->Position.x > 3) {
|
||||
life->Left = false;
|
||||
transform->Velocity.x = m_LifeSpeed;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (transform->Position.x < -3) {
|
||||
life->Left = true;
|
||||
transform->Velocity.x = -m_LifeSpeed;
|
||||
}
|
||||
}
|
||||
transform->Position.x += transform->Velocity.x * dt;
|
||||
/*glm::vec2 dir = glm::normalize(glm::vec2(transform->Velocity.x, transform->Velocity.y));
|
||||
glm::vec2 up = glm::vec2(0.f, 1.f);
|
||||
float angle = glm::acos(glm::dot<float>(dir, up)) * glm::sign(dir.x);
|
||||
transform->Orientation = glm::rotate(glm::quat(), angle, glm::vec3(0.f, 0.f, -1.f));*/
|
||||
if (Lives() != PastLives()) {
|
||||
if (life->Number + 1 == PastLives()) {
|
||||
m_World->RemoveEntity(entity);
|
||||
SetPastLives(Lives());
|
||||
@@ -64,7 +83,9 @@ void dd::Systems::LifeSystem::CreateLife(int number)
|
||||
auto life = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
|
||||
transform->Position = glm::vec3(-1.5f + number * 0.15f, -2.f, -5.f);
|
||||
//transform->Position = glm::vec3(-1.5f + number * 1.5f, -3.f, -10.f);
|
||||
transform->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
//transform->Scale = glm::vec3(0.2f, 0.2f, 0.2f);
|
||||
|
||||
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||
lifeNr->Number = number;
|
||||
@@ -81,7 +102,7 @@ bool dd::Systems::LifeSystem::OnLifeLost(const dd::Events::LifeLost &event)
|
||||
SetLives(Lives() - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::LifeSystem::OnPause(const dd::Events::Pause &event)
|
||||
|
||||
Reference in New Issue
Block a user