Implemented Combos which multiply score. Adjusted pad a bit.

This commit is contained in:
PlatinumSkink
2015-09-29 14:42:01 +02:00
parent 94fc7c1ce6
commit c3b54ef030
11 changed files with 137 additions and 57 deletions
+1 -2
View File
@@ -94,8 +94,7 @@ set(SOURCE_FILES
${SOURCE_FILES_Physics}
${SOURCE_FILES_Game}
${SOURCE_FILES_Sound}
${SOURCE_FILES_GUI}
../../include/Game/EMultiBallLost.h)
${SOURCE_FILES_GUI})
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
+59 -12
View File
@@ -18,6 +18,30 @@ void dd::Systems::BallSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EMultiBallLost, &BallSystem::OnMultiBallLost);
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, &BallSystem::OnResetBall);
EVENT_SUBSCRIBE_MEMBER(m_EMultiBall, &BallSystem::OnMultiBall);
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(-0.f, 50.f, -10.f);
transform->Scale = glm::vec3(0.5f, 0.5f, 0.5f);
transform->Velocity = glm::vec3(0.0f, 0.f, 0.f);
auto model = m_World->AddComponent<Components::Model>(ent);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
ball->Speed = 5.f;
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
std::shared_ptr<Components::Template> ballTemplate = m_World->AddComponent<Components::Template>(ent);
physics->Static = false;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
m_World->CommitEntity(ent);
SetBall(ent);
for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}
}
void dd::Systems::BallSystem::Update(double dt)
@@ -32,12 +56,10 @@ void dd::Systems::BallSystem::Update(double dt)
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto ballComponent = m_World->GetComponent<Components::Ball>(entity);
if (ballComponent != nullptr) {
if (Ball() == NULL) {
SetBall(entity);
}
if (ReplaceBall() == true) {
SetReplaceBall(false);
@@ -90,15 +112,15 @@ void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
if (Lives() != PastLives()) {
/*auto life = m_World->GetComponent<Components::Life>(entity);
auto life = m_World->GetComponent<Components::Life>(entity);
if (life != nullptr) {
if (life->Number + 1 == PastLives()) {
/*m_World->RemoveComponent<Components::Life>(entity);
// m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);*/
SetPastLives(Lives());
// }
//}
m_World->RemoveComponent<Components::Life>(entity);
m_World->RemoveComponent<Components::Transform>(entity);
m_World->RemoveEntity(entity);
SetPastLives(Lives());
}
}
}
if (ballComponent != nullptr) {
@@ -163,11 +185,17 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
if (m_World->GetProperty<std::string>(otherEntitiy, "Name") == "Pad"){
auto padTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
float x = ballTransform->Position.x - padTransform->Position.x;
float x = (ballTransform->Position.x - padTransform->Position.x) * XMovementMultiplier();
float y = glm::cos((abs(x) / (1.6f)) * glm::pi<float>() / 2.f) + 1.f;
ballTransform->Velocity = glm::normalize(glm::vec3(x, y ,0.f)) * ballComponent->Speed;
ballComponent->Combo = 0;
Events::ComboEvent ec;
ec.Combo = ballComponent->Combo;
ec.Ball = ballEntity;
EventBroker->Publish(ec);
//std::cout << "Combo: " << ballComponent->Combo << std::endl;
}
else {
glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal);
@@ -181,6 +209,8 @@ EntityID dd::Systems::BallSystem::CreateBall()
{
auto ent = m_World->CloneEntity(Ball());
m_World->RemoveComponent<Components::Template>(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.26f, -10.f);
@@ -205,6 +235,23 @@ EntityID dd::Systems::BallSystem::CreateBall()
return ent;
}
void dd::Systems::BallSystem::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->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);
}
bool dd::Systems::BallSystem::OnLifeLost(const dd::Events::LifeLost &event)
{
SetLives(Lives() - 1);
+23 -33
View File
@@ -17,30 +17,9 @@ void dd::Systems::LevelSystem::Initialize()
EVENT_SUBSCRIBE_MEMBER(m_EPowerUpTaken, &LevelSystem::OnPowerUpTaken);
EVENT_SUBSCRIBE_MEMBER(m_EStageCleared, &LevelSystem::OnStageCleared);
/*for (int i = 0; i < Lives(); i++) {
CreateLife(i);
}*/
return;
}
void dd::Systems::LevelSystem::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->Scale = glm::vec3(0.1f, 0.1f, 0.1f);
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
lifeNr->Number = number;
auto model = m_World->AddComponent<Components::Model>(life);
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
m_World->CommitEntity(life);*/
}
void dd::Systems::LevelSystem::Update(double dt)
{
if (!m_Initialized) {
@@ -51,6 +30,9 @@ void dd::Systems::LevelSystem::Update(double dt)
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
auto ball = m_World->GetComponent<Components::Ball>(entity);
SetNotResettingTheStage(NotResettingTheStage() + 0.01 * dt);
@@ -93,14 +75,14 @@ void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 s
{
SetNumberOfBricks(rows * lines);
//std::cout << "You're only doing this once, right?" << std::endl;
int num = 0;
int num = Lines();
for (int i = 0; i < rows; i++) {
num++;
num--;
for (int j = 0; j < Lines(); j++) {
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
}
if (num == 7)
num = 0;
if (num == 1)
num = Lines();
}
SetNumberOfBricks(rows * lines);
@@ -121,9 +103,9 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
std::string fileName = "Textures/Bricks/";
/*std::string fileName = "Textures/Bricks/";
fileName.append(std::to_string(num));
fileName.append(".png");
fileName.append(".png");*/
//sprite->SpriteFile = fileName;
model->ModelFile = "Models/Test/Brick/Brick.obj";
if ((line == 1 && row == 4) || (line == 3 && row == 2) || (line == 5 && row == 2)) {
@@ -151,17 +133,17 @@ void dd::Systems::LevelSystem::ProcessCollision()
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
{
auto brick = m_World->GetComponent<Components::Brick>(entity);
/*auto brick = m_World->GetComponent<Components::Brick>(entity);
if (brick != nullptr) {
SetNumberOfBricks(NumberOfBricks() - 1);
Events::ScoreEvent es;
es.Score = brick->Score;
EventBroker->Publish(es);
/*if (numberOfBricks < 1) {
if (numberOfBricks < 1) {
EndLevel();
}*/
}
}
return;
return;*/
}
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
@@ -205,6 +187,12 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
}
if (ball != nullptr && Restarting() == false) {
ball->Combo += 1;
Events::ComboEvent ec;
ec.Combo = ball->Combo;
ec.Ball = entityBall;
EventBroker->Publish(ec);
auto ballTransform = m_World->GetComponent<Components::Transform>(entityBall);
// m_World->RemoveComponent<Components::Brick>(entityBrick);
@@ -237,11 +225,13 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
//SetMultiBalls(MultiBalls() + 1);
}
Events::ScoreEvent es;
es.Score = brick->Score;
es.Score = brick->Score * ball->Combo;
EventBroker->Publish(es);
std::cout << "Combo: " << ball->Combo << std::endl;
//std::cout << NumberOfBricks() << std::endl;
//std::cout << "Score: " << Score() << std::endl;
//std::cout << "Brick Score: " << brick->Score << std::endl;
std::cout << "Score: " << Score() << std::endl;
}
return true;
+5 -2
View File
@@ -31,7 +31,8 @@ void dd::Systems::PadSystem::Initialize()
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto templateCheck = m_World->GetComponent<Components::Template>(entity);
if (templateCheck != nullptr){ return; }
}
void dd::Systems::PadSystem::Update(double dt)
@@ -59,7 +60,9 @@ void dd::Systems::PadSystem::Update(double dt)
}
transform->Position += transform->Velocity * (float)dt;
transform->Velocity += acceleration * (float)dt;
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
if (glm::abs(transform->Velocity.x) > 1 || (!Left() && !Right())) {
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float) dt;
}
if (Left()) {
acceleration.x = -pad->AccelerationSpeed;