Tried to implement lives. Failed. Everything crashes if I try to RemoveEntity in Update.

This commit is contained in:
PlatinumSkink
2015-09-15 12:40:23 +02:00
parent 157fa36f68
commit 88bd96861d
9 changed files with 226 additions and 17 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ namespace Components
struct Ball : Component
{
int number = 0;
};
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Administrator on 2015-09-15.
//
#ifndef DAYDREAM_CLIFE_H
#define DAYDREAM_CLIFE_H
#include "Core/Component.h"
namespace dd
{
namespace Components
{
struct Life : Component {
int number = 0;
};
}
}
#endif //DAYDREAM_CLIFE_H
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Adniklastrator on 2015-09-14.
//
#ifndef DAYDREAM_EBALLFELLOFFSTAGE_H
#define DAYDREAM_EBALLFELLOFFSTAGE_H
#include "Core/EventBroker.h"
#include "Core/Entity.h"
namespace dd
{
namespace Events
{
struct BallFellOffStage : Event
{
EntityID entity;
};
}
}
#endif //DAYDREAM_EBALLFELLOFFSTAGE_H
+14 -2
View File
@@ -9,13 +9,17 @@
#include "Core/CTransform.h"
#include "Rendering/CSprite.h"
#include "Game/CBrick.h"
#include "Physics/EContact.h"
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Game/CBall.h"
#include "Game/CLife.h"
#include "Game/EStageCleared.h"
#include "Game/EBallFellOffStage.h"
#include "Physics/CBoxShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/ESetImpulse.h"
#include "Physics/EContact.h"
#include <fstream>
#include <iostream>
#include <intrin.h>
@@ -47,6 +51,7 @@ public:
void Initialize() override;
void CreateBasicLevel(int, int, glm::vec2, int);
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, int, int);
@@ -56,12 +61,17 @@ public:
void EndLevel();
void Update(double dt);
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
int lives = 3;
int pastLives = 3;
private:
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<LevelSystem, dd::Events::BallFellOffStage> m_EBall;
bool OnContact(const dd::Events::Contact &event);
bool BallFellOffStage(const dd::Events::BallFellOffStage &event);
bool m_Initialized = false;
@@ -70,6 +80,8 @@ private:
int tLines = 8;
glm::vec2 tSpaceBetweenBricks = glm::vec2(2, 0.5);
int tSpaceToEdge = 0;
EntityID entityToRemove = NULL;
};
}
+13 -5
View File
@@ -7,19 +7,22 @@
#include "Core/InputController.h"
#include "Core/System.h"
#include "Core/Component.h"
#include "Core/CTransform.h"
#include "Core/EventBroker.h"
#include "Core/EKeyDown.h"
#include "Core/EKeyUp.h"
#include "Input/EBindKey.h"
#include "Physics/EContact.h"
#include "Core/CTransform.h"
#include "Physics/CBoxShape.h"
#include "Physics/CPhysics.h"
#include "Physics/CCircleShape.h"
#include "Physics/ESetImpulse.h"
#include "Rendering/CSprite.h"
#include "Game/CBall.h"
#include "Core/Component.h"
#include "Physics/ESetImpulse.h"
#include "Physics/CCircleShape.h"
#include "Game/EBallFellOffStage.h"
namespace dd
@@ -37,17 +40,22 @@ public:
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
dd::EventRelay<PadSystem, dd::Events::BallFellOffStage> m_EBall;
bool OnKeyDown(const dd::Events::KeyDown &event);
bool OnKeyUp(const dd::Events::KeyUp &event);
bool OnContact(const dd::Events::Contact &event);
bool BallFellOffStage(const dd::Events::BallFellOffStage &event);
EntityID removeThisObject = NULL;
float slowdownModifier = 5.f;
float accelerationSpeed = 80.f;
@@ -61,7 +69,7 @@ private:
EntityID ent = 0;
Components::Transform* transform;
glm::vec3 acceleration = glm::vec3(0.f, 0.f, 0.f);
bool left = false, right = false;
bool left = false, right = false, replaceBall = false;
};
class PadSystem::PadSteeringInputController : InputController<PadSystem>
+1
View File
@@ -80,6 +80,7 @@ private:
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
m_PhysicsSystem->EventBroker->Publish(e);
}
void EndContact(b2Contact* contact)