cs381/as6/components/GravityWellComponent.cpp

33 lines
748 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;
}
if (!controlledByMouse) {
active = alwaysActive;
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() {}