generated from avadae/minigin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f490201
commit c3b97a9
Showing
17 changed files
with
180 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "EnemiesSquadron.h" | ||
#include "GameObject.h" | ||
#include "Event.h" | ||
|
||
void EnemiesSquadron::Initialize(Fluffy::GameObject* pSquadronObject, Fluffy::Event& onEnemiesIdleStartEvent) | ||
{ | ||
m_pEnemiesSquadron = pSquadronObject; | ||
m_StartingPos = pSquadronObject->GetWorldPosition(); | ||
|
||
onEnemiesIdleStartEvent.AddListener(this); | ||
} | ||
|
||
void EnemiesSquadron::Update(const float deltaTime) | ||
{ | ||
if (!m_ShouldSway) | ||
return; | ||
|
||
m_pEnemiesSquadron->GetTransform().Translate(m_CurrentDirection * m_SwaySpeed * deltaTime, 0.0f); | ||
|
||
const float swayDistance{ m_pEnemiesSquadron->GetWorldPosition().x - m_StartingPos.x }; | ||
|
||
// squared for absolute distance | ||
if (swayDistance * swayDistance >= m_MaxSwayDistance * m_MaxSwayDistance) | ||
m_CurrentDirection *= -1.0f; | ||
} | ||
|
||
void EnemiesSquadron::Reset() | ||
{ | ||
m_pEnemiesSquadron->SetWorldPosition(m_StartingPos); | ||
m_ShouldSway = false; | ||
} | ||
|
||
void EnemiesSquadron::OnNotify(const Fluffy::EventType& eventType, const Fluffy::IEventParam* /*= nullptr*/) | ||
{ | ||
switch (eventType) | ||
{ | ||
case Fluffy::EventType::OnEnemiesIdleStart: | ||
m_ShouldSway = true; | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "Event.h" | ||
#include "IEventListener.h" | ||
#include "glm\glm.hpp" | ||
|
||
namespace Fluffy | ||
{ | ||
class GameObject; | ||
struct IEventParam; | ||
} | ||
|
||
class EnemiesSquadron final : public Fluffy::IEventListener | ||
{ | ||
public: | ||
inline bool IsInitialized() const { return m_pEnemiesSquadron != nullptr; } | ||
void Initialize(Fluffy::GameObject* pSquadronObject, Fluffy::Event& onEnemiesIdleStartEvent); | ||
inline void SetMaxSwayDistance(const float maxSwayDistance) { m_MaxSwayDistance = maxSwayDistance; } | ||
void Update(const float deltaTime); | ||
void Reset(); | ||
|
||
void OnNotify(const Fluffy::EventType& eventType, const Fluffy::IEventParam* pParam = nullptr) override; | ||
|
||
private: | ||
Fluffy::GameObject* m_pEnemiesSquadron{}; | ||
glm::vec2 m_StartingPos{}; | ||
float m_MaxSwayDistance{}; | ||
|
||
const float m_SwaySpeed{ 50.0f }; | ||
float m_CurrentDirection{ 1.0f }; | ||
|
||
bool m_ShouldSway{ false }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.