I forgot to stage in my last commit.
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-09-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_ELIFELOST_H
|
||||||
|
#define DAYDREAM_ELIFELOST_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/Entity.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct LifeLost : Event
|
||||||
|
{
|
||||||
|
EntityID entity;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_ELIFELOST_H
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CLife.h"
|
#include "Game/CLife.h"
|
||||||
#include "Game/EStageCleared.h"
|
#include "Game/EStageCleared.h"
|
||||||
#include "Game/EBallFellOffStage.h"
|
#include "Game/ELifeLost.h"
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
#include "Physics/CCircleShape.h"
|
#include "Physics/CCircleShape.h"
|
||||||
@@ -68,10 +68,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||||
dd::EventRelay<LevelSystem, dd::Events::BallFellOffStage> m_EBall;
|
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||||
|
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool BallFellOffStage(const dd::Events::BallFellOffStage &event);
|
bool LifeLost(const dd::Events::LifeLost &event);
|
||||||
|
|
||||||
bool m_Initialized = false;
|
bool m_Initialized = false;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "Physics/ESetImpulse.h"
|
#include "Physics/ESetImpulse.h"
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/EBallFellOffStage.h"
|
#include "Game/ELifeLost.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -46,14 +46,14 @@ private:
|
|||||||
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
||||||
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
||||||
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
||||||
dd::EventRelay<PadSystem, dd::Events::BallFellOffStage> m_EBall;
|
dd::EventRelay<PadSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||||
|
|
||||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||||
bool OnKeyUp(const dd::Events::KeyUp &event);
|
bool OnKeyUp(const dd::Events::KeyUp &event);
|
||||||
|
|
||||||
|
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool BallFellOffStage(const dd::Events::BallFellOffStage &event);
|
bool LifeLost(const dd::Events::LifeLost &event);
|
||||||
|
|
||||||
EntityID removeThisObject = NULL;
|
EntityID removeThisObject = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ set(SOURCE_FILES
|
|||||||
${SOURCE_FILES_Rendering}
|
${SOURCE_FILES_Rendering}
|
||||||
${SOURCE_FILES_Transform}
|
${SOURCE_FILES_Transform}
|
||||||
${SOURCE_FILES_Physics}
|
${SOURCE_FILES_Physics}
|
||||||
${SOURCE_FILES_Game} ../../include/Game/CLife.h)
|
${SOURCE_FILES_Game} ../../include/Game/CLife.h ../../include/Game/ELifeLost.h)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
void dd::Systems::LevelSystem::Initialize()
|
void dd::Systems::LevelSystem::Initialize()
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EBall, LevelSystem::BallFellOffStage);
|
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::LifeLost);
|
||||||
|
|
||||||
for (int i = 0; i < lives; i++)
|
for (int i = 0; i < lives; i++)
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
{
|
{
|
||||||
if (lives == pastLives)
|
if (lives == pastLives)
|
||||||
{
|
{
|
||||||
Events::BallFellOffStage e;
|
Events::LifeLost e;
|
||||||
e.entity = entity;
|
e.entity = entity;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
return;
|
return;
|
||||||
@@ -116,7 +116,6 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
|||||||
float y = spaceToEdge + row * spacesBetweenBricks.y;
|
float y = spaceToEdge + row * spacesBetweenBricks.y;
|
||||||
transform->Scale = glm::vec3(1.6, 0.4, 0.);
|
transform->Scale = glm::vec3(1.6, 0.4, 0.);
|
||||||
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
||||||
//sprite->Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
|
||||||
m_World->CommitEntity(brick);
|
m_World->CommitEntity(brick);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,8 +142,6 @@ void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
|||||||
|
|
||||||
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
/*event.Entity1 - Vi vet inte vilken som.
|
|
||||||
event.Entity2 - */
|
|
||||||
EntityID entityBrick = event.Entity1;
|
EntityID entityBrick = event.Entity1;
|
||||||
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
||||||
if (brick == NULL)
|
if (brick == NULL)
|
||||||
@@ -152,83 +149,14 @@ bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EntityID entityBall = event.Entity2;
|
EntityID entityBall = event.Entity2;
|
||||||
//EntityID entity1 = event.Entity1;
|
|
||||||
//EntityID entity2 = event.Entity2;
|
|
||||||
|
|
||||||
//auto brick = m_World->GetComponent<Components::Brick>(entity1);
|
m_World->RemoveEntity(entityBrick);
|
||||||
//auto ball = m_World->GetComponent<Components::Ball>(entity2);
|
|
||||||
//std::cout << brick << std::endl;
|
|
||||||
//std::cout << ball << std::endl;
|
|
||||||
/*if (brick != NULL)
|
|
||||||
{
|
|
||||||
std::cout << "Entity1 is a brick!" << std::endl;
|
|
||||||
entityBrick = entity1;
|
|
||||||
if (ball != NULL)
|
|
||||||
{
|
|
||||||
std::cout << "Entity2 is a ball!" << std::endl;
|
|
||||||
entityBall = entity2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
brick = m_World->GetComponent<Components::Brick>(entity2);
|
|
||||||
if (brick != NULL)
|
|
||||||
{
|
|
||||||
std::cout << "Entity2 is a brick!" << std::endl;
|
|
||||||
entityBrick = entity2;
|
|
||||||
}
|
|
||||||
|
|
||||||
ball = m_World->GetComponent<Components::Ball>(entity1);
|
return true;
|
||||||
if (ball != NULL)
|
|
||||||
{
|
|
||||||
std::cout << "Entity1 is a ball!" << std::endl;
|
|
||||||
entityBall = entity1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityBrick != NULL && entityBall != NULL)
|
|
||||||
{*/
|
|
||||||
m_World->RemoveEntity(entityBrick);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::LevelSystem::BallFellOffStage(const dd::Events::BallFellOffStage &event)
|
bool dd::Systems::LevelSystem::LifeLost(const dd::Events::LifeLost &event)
|
||||||
{
|
{
|
||||||
std::cout << "Did you get here?" << std::endl;
|
|
||||||
/*EntityID entity = event.entity;
|
|
||||||
|
|
||||||
//Temporary. Create new ball.
|
|
||||||
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;
|
|
||||||
|
|
||||||
std::cout << "How about here?" << std::endl;
|
|
||||||
*/
|
|
||||||
//m_World->RemoveEntity(event.entity);
|
|
||||||
//entityToRemove = event.entity;
|
|
||||||
/* m_World->CommitEntity(ent);
|
|
||||||
|
|
||||||
std::cout << "Or here?" << std::endl;
|
|
||||||
|
|
||||||
Events::SetImpulse 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);
|
|
||||||
|
|
||||||
std::cout << "Maybe even here?" << std::endl;
|
|
||||||
*/
|
|
||||||
lives--;
|
lives--;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ void dd::Systems::PadSystem::Initialize()
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EBall, PadSystem::BallFellOffStage);
|
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, PadSystem::LifeLost);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd::Systems::PadSystem::BallFellOffStage(const dd::Events::BallFellOffStage &event)
|
bool dd::Systems::PadSystem::LifeLost(const dd::Events::LifeLost &event)
|
||||||
{
|
{
|
||||||
replaceBall = true;
|
replaceBall = true;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user