Kod för boll mot bricka kollision
This commit is contained in:
@@ -8,8 +8,9 @@
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Game/CBrick.h"
|
||||
//#include "Core/EContact.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Game/EStageCleared.h"
|
||||
#include <fstream>
|
||||
@@ -53,6 +54,10 @@ public:
|
||||
void EndLevel();
|
||||
|
||||
private:
|
||||
//dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||
|
||||
bool OnContact(/*const dd::Events::Contact &event*/);
|
||||
|
||||
int numberOfBricks;
|
||||
int tRows = 7;
|
||||
int tLines = 8;
|
||||
|
||||
@@ -39,6 +39,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
auto brick = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
|
||||
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
|
||||
std::string fileName = "Textures/Bricks/";
|
||||
fileName.append(std::to_string(num));
|
||||
fileName.append(".png");
|
||||
@@ -71,6 +72,52 @@ void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
||||
return;
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::OnContact(/*const dd::Events::Contact &event,*/)
|
||||
{
|
||||
/*event.Entity1 - Vi vet inte vilken som.
|
||||
event.Entity2 - */
|
||||
std::string event = "I'm just a placeholder :(";
|
||||
EntityID entityBrick;
|
||||
EntityID entityBall;
|
||||
EntityID entity1;
|
||||
EntityID entity2;
|
||||
EntityID ball;
|
||||
|
||||
auto brick = m_World->GetComponent<Components::Brick>(entity1);
|
||||
if (brick != NULL)
|
||||
{
|
||||
entityBrick = entity1;
|
||||
ball = m_World->GetComponent<Components::Ball>(entity2);
|
||||
if (ball != NULL)
|
||||
{
|
||||
entityBall = entity2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
brick = m_World->GetComponent<Components::Brick>(entity2);
|
||||
if (brick != NULL)
|
||||
{
|
||||
entityBrick = entity2;
|
||||
}
|
||||
|
||||
ball = m_World->GetComponent<Components::Ball>(entity1);
|
||||
if (ball != NULL)
|
||||
{
|
||||
entityBall = entity1;
|
||||
}
|
||||
}
|
||||
|
||||
if (entityBrick != NULL && entityBall != NULL)
|
||||
{
|
||||
m_World->RemoveEntity(entityBrick);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::EndLevel()
|
||||
{
|
||||
Events::StageCleared e;
|
||||
|
||||
Reference in New Issue
Block a user