ScreenShakeSystem made. And some other things.
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CBACKGROUND_H
|
||||||
|
#define DAYDREAM_CBACKGROUND_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Background : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CBACKGROUND_H
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CWALL_H
|
||||||
|
#define DAYDREAM_CWALL_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Wall : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CWALL_H
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_ERAISEWATER_H
|
||||||
|
#define DAYDREAM_ERAISEWATER_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct RaiseWater : Event
|
||||||
|
{
|
||||||
|
float Amount;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_ERAISEWATER_H
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_ERESETALL_H
|
||||||
|
#define DAYDREAM_ERESETALL_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ResetAll : Event
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_ERESETALL_H
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_SCREENSHAKESYSTEM_H
|
||||||
|
#define DAYDREAM_SCREENSHAKESYSTEM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/CTransform.h"
|
||||||
|
#include "Core/CTemplate.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/World.h"
|
||||||
|
#include "Game/EPause.h"
|
||||||
|
#include "Game/EScreenShake.h"
|
||||||
|
//#include "Core/Camera.h" Camera Component
|
||||||
|
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class ScreenShakeSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScreenShakeSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
void InitializeObjects() override;
|
||||||
|
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
void FlipPause();
|
||||||
|
|
||||||
|
bool IsPaused() const { return m_Pause; }
|
||||||
|
void SetPause(const bool& pause) { m_Pause = pause; }
|
||||||
|
private:
|
||||||
|
bool m_Pause;
|
||||||
|
bool m_ScreenShake;
|
||||||
|
int m_ShakeIntensity;
|
||||||
|
glm::vec3 m_CameraPosition;
|
||||||
|
float m_ShakeRepresentativeIntensity;
|
||||||
|
float m_ShakeTimer;
|
||||||
|
float m_ShakeEndTime;
|
||||||
|
float m_TimeTakenToCoolDown;
|
||||||
|
float m_CoolerMultiplier;
|
||||||
|
glm::vec3 m_Random;
|
||||||
|
|
||||||
|
dd::EventRelay<ScreenShakeSystem, dd::Events::Pause> m_EPause;
|
||||||
|
dd::EventRelay<ScreenShakeSystem, dd::Events::ScreenShake> m_EScreenShake;
|
||||||
|
bool OnPause(const dd::Events::Pause &event);
|
||||||
|
bool OnScreenShake(const dd::Events::ScreenShake &event);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_SCREENSHAKESYSTEM_H
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-10-14.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Game/ScreenShakeSystem.h"
|
||||||
|
|
||||||
|
void dd::Systems::ScreenShakeSystem::Initialize()
|
||||||
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &ScreenShakeSystem::OnPause);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EScreenShake, &ScreenShakeSystem::OnScreenShake);
|
||||||
|
|
||||||
|
InitializeObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::ScreenShakeSystem::InitializeObjects()
|
||||||
|
{
|
||||||
|
m_Pause = false;
|
||||||
|
m_ScreenShake = false;
|
||||||
|
m_ShakeIntensity = 0;
|
||||||
|
m_CameraPosition = glm::vec3(0, 0, 0);
|
||||||
|
m_ShakeRepresentativeIntensity = 0;
|
||||||
|
m_ShakeTimer = 0;
|
||||||
|
m_ShakeEndTime = 0;
|
||||||
|
m_TimeTakenToCoolDown = 0;
|
||||||
|
m_CoolerMultiplier = 0;
|
||||||
|
m_Random = glm::vec3(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::ScreenShakeSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
|
{
|
||||||
|
if (IsPaused()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*auto camera = m_World->GetComponent<Components::Camera>(entity);
|
||||||
|
|
||||||
|
if (camera != nullptr) {
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
|
||||||
|
if (m_ScreenShake) {
|
||||||
|
m_CameraPosition = transform->Position - m_Random;
|
||||||
|
|
||||||
|
m_ShakeTimer += dt;
|
||||||
|
if (m_ShakeTimer >= m_ShakeEndTime) {
|
||||||
|
//std::cout << "Used: " << m_ShakeIntensity << " True: " << m_ShakeRepresentativeIntensity << std::endl;
|
||||||
|
m_ShakeRepresentativeIntensity -= m_ShakeRepresentativeIntensity * m_CoolerMultiplier * dt;
|
||||||
|
m_ShakeIntensity = m_ShakeRepresentativeIntensity;
|
||||||
|
if (m_ShakeIntensity <= 0) {
|
||||||
|
m_ScreenShake = false;
|
||||||
|
transform->Position = glm::vec3(0, 0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//std::cout << "Timer: " << m_ShakeTimer << " End: " << m_ShakeEndTime << std::endl;
|
||||||
|
}
|
||||||
|
m_Random.x = (rand() % m_ShakeIntensity);
|
||||||
|
m_Random.y = (rand() % m_ShakeIntensity);
|
||||||
|
|
||||||
|
float half = m_ShakeIntensity / 2;
|
||||||
|
|
||||||
|
m_Random.x = (m_Random.x - half) / 20;
|
||||||
|
m_Random.y = (m_Random.y - half) / 20;
|
||||||
|
|
||||||
|
//std::cout << "X: " << randomX << " Y: " << randomY << std::endl;
|
||||||
|
transform->Position = glm::vec3(m_Random);
|
||||||
|
} else {
|
||||||
|
m_CameraPosition = transform->Position;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::ScreenShakeSystem::OnPause(const dd::Events::Pause &event)
|
||||||
|
{
|
||||||
|
if (IsPaused()) {
|
||||||
|
SetPause(false);
|
||||||
|
} else {
|
||||||
|
SetPause(true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::ScreenShakeSystem::OnScreenShake(const dd::Events::ScreenShake &event)
|
||||||
|
{
|
||||||
|
m_ScreenShake = true;
|
||||||
|
m_ShakeIntensity = event.Intensity;
|
||||||
|
m_ShakeRepresentativeIntensity = event.Intensity;
|
||||||
|
m_ShakeEndTime = event.Time;
|
||||||
|
m_ShakeTimer = 0;
|
||||||
|
m_TimeTakenToCoolDown = event.TimeTakenToCoolDown;
|
||||||
|
m_CoolerMultiplier = m_ShakeIntensity / m_TimeTakenToCoolDown;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user