feat: add interactable component and test button
This commit is contained in:
@@ -29,6 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
void setupSkybox();
|
||||
void drawCrosshair();
|
||||
[[nodiscard]] CameraComponent* getSceneCamera() const;
|
||||
[[nodiscard]] bool isPlayerViewActive() const;
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
class Rigidbody;
|
||||
class CapsuleCollider;
|
||||
class Interactable;
|
||||
|
||||
// Dynamic capsule character. Velocity is driven directly (no forces) so movement stays responsive:
|
||||
// acceleration towards the wished velocity, own gravity, coyote time and jump buffering.
|
||||
class FirstPersonController final : public Component {
|
||||
public:
|
||||
explicit FirstPersonController(GameObject& parent);
|
||||
@@ -26,9 +25,9 @@ public:
|
||||
[[nodiscard]] float GetYaw() const { return m_Yaw; }
|
||||
void SetYaw(float yawRadians) { m_Yaw = yawRadians; }
|
||||
[[nodiscard]] float GetPitch() const { return m_Pitch; }
|
||||
void SetPitch(float pitchRadians) { m_Pitch = pitchRadians; }
|
||||
[[nodiscard]] float GetEyeHeight() const { return m_EyeHeight; }
|
||||
|
||||
// Eye position interpolated between the last two physics steps, so the camera moves smoothly at any framerate
|
||||
[[nodiscard]] glm::vec3 GetEyePosition() const;
|
||||
|
||||
void SetMovementSpeed(float speed) { m_WalkSpeed = speed; }
|
||||
@@ -39,12 +38,16 @@ public:
|
||||
|
||||
[[nodiscard]] bool IsGrounded() const { return m_Grounded; }
|
||||
|
||||
[[nodiscard]] Interactable* GetFocusedInteractable() const { return m_FocusedInteractable; }
|
||||
[[nodiscard]] glm::vec3 GetLookDirection() const;
|
||||
|
||||
[[nodiscard]] bool IsMouseCaptured() const { return InputManager::GetInstance().IsMouseCaptured(); }
|
||||
void SetMouseCaptured(bool captured);
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool CheckGrounded() const;
|
||||
[[nodiscard]] glm::vec3 GetWishDirection() const;
|
||||
[[nodiscard]] Interactable* FindFocusedInteractable() const;
|
||||
|
||||
Rigidbody* m_Rigidbody{nullptr};
|
||||
CapsuleCollider* m_Capsule{nullptr};
|
||||
@@ -63,6 +66,9 @@ private:
|
||||
float m_FallGravityMultiplier{1.6f};
|
||||
float m_CoyoteTime{0.1f};
|
||||
float m_JumpBufferTime{0.12f};
|
||||
float m_InteractDistance{3.0f};
|
||||
|
||||
Interactable* m_FocusedInteractable{nullptr};
|
||||
|
||||
bool m_Grounded{false};
|
||||
bool m_JumpHeld{false};
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
#define LIGHTKEEPER_GAMECOMPONENTLIST_H
|
||||
|
||||
#include <components/FirstPersonController.h>
|
||||
#include <components/InteractableButton.h>
|
||||
#include <components/PrintComponent.h>
|
||||
#include <components/TriggerLoggerComponent.h>
|
||||
|
||||
#define LIGHTKEEPER_GAME_COMPONENTS(X) \
|
||||
X(FirstPersonController) \
|
||||
X(InteractableButton) \
|
||||
X(PrintComponent) \
|
||||
X(TriggerLoggerComponent)
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef LIGHTKEEPER_INTERACTABLE_H
|
||||
#define LIGHTKEEPER_INTERACTABLE_H
|
||||
|
||||
#include <destrum/ObjectModel/Component.h>
|
||||
|
||||
class Interactable : public Component {
|
||||
public:
|
||||
virtual void Interact(GameObject& interactor) = 0;
|
||||
|
||||
[[nodiscard]] static Interactable* FindOnObjectOrParents(GameObject* object);
|
||||
|
||||
protected:
|
||||
Interactable(GameObject& parent, const std::string& name)
|
||||
: Component(parent, name) {}
|
||||
};
|
||||
|
||||
#endif // LIGHTKEEPER_INTERACTABLE_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef LIGHTKEEPER_INTERACTABLEBUTTON_H
|
||||
#define LIGHTKEEPER_INTERACTABLEBUTTON_H
|
||||
|
||||
#include <components/Interactable.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class InteractableButton final : public Interactable {
|
||||
public:
|
||||
explicit InteractableButton(GameObject& parent);
|
||||
|
||||
std::string GetTypeName() const override { return "InteractableButton"; }
|
||||
|
||||
void Start() override;
|
||||
void Interact(GameObject& interactor) override;
|
||||
|
||||
nlohmann::json Serialize() const override;
|
||||
void Deserialize(const nlohmann::json& data) override;
|
||||
void ImGuiInspector() override;
|
||||
|
||||
[[nodiscard]] std::size_t GetColorIndex() const { return m_ColorIndex; }
|
||||
[[nodiscard]] int GetPressCount() const { return m_PressCount; }
|
||||
|
||||
private:
|
||||
void ApplyColor();
|
||||
|
||||
std::size_t m_ColorIndex{0};
|
||||
int m_PressCount{0};
|
||||
};
|
||||
|
||||
#endif // LIGHTKEEPER_INTERACTABLEBUTTON_H
|
||||
Reference in New Issue
Block a user