From c3b54ef030866412db465adcd333a9d46361f2b3 Mon Sep 17 00:00:00 2001 From: PlatinumSkink Date: Tue, 29 Sep 2015 14:42:01 +0200 Subject: [PATCH] Implemented Combos which multiply score. Adjusted pad a bit. --- include/Core/Engine.h | 4 +- include/Game/BallSystem.h | 17 +++++++-- include/Game/CBall.h | 1 + include/Game/CPad.h | 2 +- include/Game/EComboEvent.h | 27 +++++++++++++ include/Game/LevelSystem.h | 5 ++- include/Game/PadSystem.h | 1 + src/game/CMakeLists.txt | 3 +- src/game/Game/BallSystem.cpp | 71 +++++++++++++++++++++++++++++------ src/game/Game/LevelSystem.cpp | 56 ++++++++++++--------------- src/game/Game/PadSystem.cpp | 7 +++- 11 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 include/Game/EComboEvent.h diff --git a/include/Core/Engine.h b/include/Core/Engine.h index ad45379..e001289 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -150,8 +150,8 @@ public: physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall; physics->Calculate = true; - auto plight = m_World->AddComponent(ent); - plight->Radius = 2.f; + //auto plight = m_World->AddComponent(ent); + //plight->Radius = 2.f; m_World->CommitEntity(ent); } diff --git a/include/Game/BallSystem.h b/include/Game/BallSystem.h index ac34ab0..3ead5d8 100644 --- a/include/Game/BallSystem.h +++ b/include/Game/BallSystem.h @@ -5,6 +5,7 @@ #include "Core/World.h" #include "Core/EventBroker.h" #include "Core/CTransform.h" +#include "Core/CTemplate.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" #include "Physics/EContact.h" @@ -12,17 +13,22 @@ #include "Rendering/CPointLight.h" #include "Game/CBall.h" #include "Game/CPowerUp.h" +#include "Game/CLife.h" #include "Game/ELifeLost.h" +#include "Game/EComboEvent.h" #include "Game/EResetBall.h" #include "Game/EMultiBall.h" #include "Game/EMultiBallLost.h" #include "Game/EGameOver.h" -namespace dd { +namespace dd +{ -namespace Systems { +namespace Systems +{ -class BallSystem : public System { +class BallSystem : public System +{ public: BallSystem(World *world, std::shared_ptr eventBroker) : System(world, eventBroker) { } @@ -49,9 +55,12 @@ public: void OnEntityRemoved(EntityID entity) override; EntityID CreateBall(); + void CreateLife(int); EntityID Ball() { return m_Ball; }; void SetBall(const EntityID& ball) { m_Ball = ball; } + float& XMovementMultiplier() { return m_XMovementMultiplier; } + void SetXMovementMultiplier(const float& xMovementMultiplier) { m_XMovementMultiplier = xMovementMultiplier; } float& EdgeX() { return m_EdgeX; } void SetEdgeX(const float& edgeX) { m_EdgeX = edgeX; } float& EdgeY() { return m_EdgeY; } @@ -68,6 +77,7 @@ public: void SetMultiBall(const bool& multiBall) { m_MultiBall = multiBall; } private: + float m_XMovementMultiplier = 2.f; float m_EdgeX = 3.2f; float m_EdgeY = 5.2f; int m_MultiBalls = 0; @@ -90,6 +100,7 @@ private: }; } + } #endif diff --git a/include/Game/CBall.h b/include/Game/CBall.h index 2990a3a..5dd1405 100644 --- a/include/Game/CBall.h +++ b/include/Game/CBall.h @@ -17,6 +17,7 @@ struct Ball : Component { int Number = 0; float Speed = 5.f; + int Combo = 0; }; } diff --git a/include/Game/CPad.h b/include/Game/CPad.h index f71c756..15afebd 100644 --- a/include/Game/CPad.h +++ b/include/Game/CPad.h @@ -22,7 +22,7 @@ struct Pad : Component float SlowdownModifier = 5.f; float AccelerationSpeed = 40.f; - float MaxSpeed = 20.f; + float MaxSpeed = 5.f; }; } diff --git a/include/Game/EComboEvent.h b/include/Game/EComboEvent.h new file mode 100644 index 0000000..7253f55 --- /dev/null +++ b/include/Game/EComboEvent.h @@ -0,0 +1,27 @@ +// +// Created by Adniklastrator on 2015-09-29. +// + +#ifndef DAYDREAM_ECOMBOEVENT_H +#define DAYDREAM_ECOMBOEVENT_H + +#include "Core/Entity.h" +#include "Core/EventBroker.h" + +namespace dd +{ + +namespace Events +{ + +struct ComboEvent : Event +{ + EntityID Ball; + int Combo; +}; + +} + +} + +#endif //DAYDREAM_ECOMBOEVENT_H diff --git a/include/Game/LevelSystem.h b/include/Game/LevelSystem.h index acf0129..6849d4f 100755 --- a/include/Game/LevelSystem.h +++ b/include/Game/LevelSystem.h @@ -7,6 +7,7 @@ #include "Core/System.h" #include "Core/CTransform.h" +#include "Core/CTemplate.h" #include "Core/EventBroker.h" #include "Core/World.h" #include "Rendering/CSprite.h" @@ -19,7 +20,7 @@ #include "Game/ELifeLost.h" #include "Game/EResetBall.h" #include "Game/EScoreEvent.h" -#include "Physics/CRectangleShape.h" +#include "Game/EComboEvent.h" #include "Game/EMultiBall.h" #include "Game/EMultiBallLost.h" #include "Game/EGameOver.h" @@ -28,6 +29,7 @@ #include "Game/Bricks/CPowerUpBrick.h" #include "Physics/CPhysics.h" #include "Physics/CCircleShape.h" +#include "Physics/CRectangleShape.h" #include "Physics/ESetImpulse.h" #include "Physics/EContact.h" #include "Sound/CCollisionSound.h" @@ -62,7 +64,6 @@ public: void Initialize() override; void CreateBasicLevel(int, int, glm::vec2, float); - void CreateLife(int); void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting. void LoadLevel(char[20]); void CreateBrick(int, int, glm::vec2, float, int); diff --git a/include/Game/PadSystem.h b/include/Game/PadSystem.h index ef9d9ef..9162083 100755 --- a/include/Game/PadSystem.h +++ b/include/Game/PadSystem.h @@ -9,6 +9,7 @@ #include "Core/System.h" #include "Core/Component.h" #include "Core/CTransform.h" +#include "Core/CTemplate.h" #include "Core/EventBroker.h" #include "Core/EKeyDown.h" #include "Core/EKeyUp.h" diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 0c8978c..8a8cca5 100755 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -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") diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 4a4ba17..53206fb 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -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 transform = m_World->AddComponent(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(ent); + model->ModelFile = "Models/Test/Ball/Ballopus.obj"; + std::shared_ptr circleShape = m_World->AddComponent(ent); + std::shared_ptr ball = m_World->AddComponent(ent); + ball->Speed = 5.f; + std::shared_ptr physics = m_World->AddComponent(ent); + std::shared_ptr ballTemplate = m_World->AddComponent(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(entity); + if (templateCheck != nullptr){ return; } auto ballComponent = m_World->GetComponent(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(entity); + auto life = m_World->GetComponent(entity); if (life != nullptr) { if (life->Number + 1 == PastLives()) { - /*m_World->RemoveComponent(entity); -// m_World->RemoveComponent(entity); - m_World->RemoveEntity(entity);*/ - SetPastLives(Lives()); - // } - //} + m_World->RemoveComponent(entity); + m_World->RemoveComponent(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(otherEntitiy, "Name") == "Pad"){ auto padTransform = m_World->GetComponent(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() / 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(ent); + /* auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(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 transform = m_World->AddComponent(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 lifeNr = m_World->AddComponent(life); + lifeNr->Number = number; + + auto model = m_World->AddComponent(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); diff --git a/src/game/Game/LevelSystem.cpp b/src/game/Game/LevelSystem.cpp index 92c7549..2f62a46 100755 --- a/src/game/Game/LevelSystem.cpp +++ b/src/game/Game/LevelSystem.cpp @@ -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 transform = m_World->AddComponent(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 lifeNr = m_World->AddComponent(life); - lifeNr->Number = number; - - auto model = m_World->AddComponent(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(entity); + if (templateCheck != nullptr){ return; } + auto ball = m_World->GetComponent(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(entity); + /*auto brick = m_World->GetComponent(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(entityBall); // m_World->RemoveComponent(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; diff --git a/src/game/Game/PadSystem.cpp b/src/game/Game/PadSystem.cpp index b767c89..43c71e7 100755 --- a/src/game/Game/PadSystem.cpp +++ b/src/game/Game/PadSystem.cpp @@ -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(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;