28 lines
664 B
C++
28 lines
664 B
C++
#include "components/GravityWellComponent.hpp"
|
|
|
|
#include "Entity.hpp"
|
|
#include "components/TransformComponent.hpp"
|
|
|
|
#include "raylib.h"
|
|
|
|
#include <algorithm>
|
|
|
|
void GravityWellComponent::Setup() {}
|
|
|
|
void GravityWellComponent::Update(float dt) {
|
|
auto transform = entity->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
|
|
active = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
|
|
|
const Vector2 mouse = GetMousePosition();
|
|
auto &t = transform->get();
|
|
const float blend = std::clamp(followLerp * dt, 0.0f, 1.0f);
|
|
t.x += (mouse.x - t.x) * blend;
|
|
t.y += (mouse.y - t.y) * blend;
|
|
}
|
|
|
|
void GravityWellComponent::Cleanup() {}
|