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
aca3d84
commit e8b9d18
Showing
18 changed files
with
161 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Command.h" |
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,7 @@ | ||
#pragma once | ||
class Command | ||
{ | ||
public: | ||
virtual ~Command() = default; | ||
virtual void Execute(class GameObject*) {}; | ||
}; |
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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
#pragma once | ||
#include "Singleton.h" | ||
#include "MoveCommand.h" | ||
|
||
namespace dae | ||
{ | ||
class InputManager final : public Singleton<InputManager> | ||
{ | ||
public: | ||
~InputManager(); | ||
inline void SetInputReceiver(GameObject* pReceiver) { m_pInputReceiver = pReceiver; } | ||
bool ProcessInput(); | ||
void MapInput(SDL_Scancode input, Command* pCommand); | ||
|
||
private: | ||
|
||
GameObject* m_pInputReceiver{ nullptr }; | ||
std::unordered_map<SDL_Scancode, Command*> m_MappedInputs{}; | ||
}; | ||
|
||
} |
Binary file not shown.
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 @@ | ||
#include "MoveCommand.h" |
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,14 @@ | ||
#pragma once | ||
#include "Command.h" | ||
#include "GameObject.h" | ||
#include "MoveComponent.h" | ||
#include "glm/glm.hpp" | ||
|
||
class MoveCommand final : public Command | ||
{ | ||
public: | ||
void Execute(GameObject* pGameObject) override | ||
{ | ||
pGameObject->GetComponentOfType<MoveComponent>()->Move(glm::vec2(0.0f, 1.0f)); | ||
} | ||
}; |
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,27 @@ | ||
#include "MoveComponent.h" | ||
#include "GameObject.h" | ||
#include <vcruntime_typeinfo.h> | ||
|
||
MoveComponent::MoveComponent(const std::weak_ptr<class GameObject> pOwner, float verticalSpeed, float horizontalSpeed) | ||
: Component(pOwner) | ||
, m_VerticalSpeed{ verticalSpeed } | ||
, m_HorizontalSpeed{ horizontalSpeed } | ||
{ | ||
|
||
} | ||
|
||
void MoveComponent::Update(const float deltaTime) | ||
{ | ||
if (m_Movement != VEC_ZERO) | ||
{ | ||
glm::vec2 position{ GetOwner()->GetWorldPosition() }; | ||
glm::vec2 movement{ deltaTime * m_Movement }; | ||
GetOwner()->SetWorldPosition(position - movement); | ||
m_Movement = VEC_ZERO; | ||
} | ||
} | ||
|
||
void MoveComponent::Move(const glm::vec2& input) | ||
{ | ||
m_Movement = glm::vec2((input.x * m_HorizontalSpeed), (input.y * m_VerticalSpeed)); | ||
} |
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,28 @@ | ||
#pragma once | ||
#include "Component.h" | ||
#include <glm/glm.hpp> | ||
#include <memory> | ||
|
||
constexpr glm::vec2 VEC_ZERO{ 0.0f, 0.0f }; | ||
|
||
|
||
class MoveComponent final : public Component | ||
{ | ||
public: | ||
MoveComponent(const std::weak_ptr<class GameObject> pOwner, float verticalSpeed, float horizontalSpeed); | ||
void Update(const float deltaTime) override; | ||
|
||
std::string GetTypename() override | ||
{ | ||
return typeid(MoveComponent).name(); | ||
} | ||
|
||
void Move(const glm::vec2& input); | ||
|
||
private: | ||
float m_VerticalSpeed{}; | ||
float m_HorizontalSpeed{}; | ||
|
||
glm::vec2 m_Movement{}; | ||
}; | ||
|
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