Compare commits
No commits in common. "2f346c11c346a7c3320377a0e37a728b86a4d6fb" and "d3af79309259e54381be738fb3feadda1b874adf" have entirely different histories.
2f346c11c3
...
d3af793092
@ -15,18 +15,6 @@ public:
|
||||
WorldPos WindowToWorld(WindowPos) const;
|
||||
WindowSize WorldToWindowSize(WorldSize) const;
|
||||
WorldSize WindowToWorldSize(WindowSize) const;
|
||||
|
||||
template <typename T>
|
||||
requires std::floating_point<T>
|
||||
T WindowToWorldSize(T window_size) const {
|
||||
return window_size / static_cast<T>(m_Zoom);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::floating_point<T>
|
||||
T WorldToWindowSize(T world_size) const {
|
||||
return world_size * static_cast<T>(m_Zoom);
|
||||
}
|
||||
|
||||
private:
|
||||
// TODO this should be replaced with a matrix
|
||||
|
@ -67,10 +67,6 @@ public:
|
||||
|
||||
bool IsCollisionBoxVisible() const { return m_CollisionBoxVisible; }
|
||||
|
||||
void Select() { m_Selected = true; }
|
||||
void Deselect() { m_Selected = false; }
|
||||
bool IsSelected() const { return m_Selected; }
|
||||
|
||||
protected:
|
||||
WorldPos m_Position;
|
||||
WorldPos m_ActualVelocity;
|
||||
@ -80,7 +76,6 @@ protected:
|
||||
private:
|
||||
bool m_FlagExpired = false;
|
||||
bool m_CollisionBoxVisible = true;
|
||||
bool m_Selected = false;
|
||||
};
|
||||
|
||||
class Player final : public Entity {
|
||||
|
@ -43,19 +43,13 @@ void GameLoop::Draw() {
|
||||
// draw all the entities (player etc)
|
||||
for (auto &entity : m_Game->GetEntities()) {
|
||||
const auto &camera = m_Game->GetCamera();
|
||||
auto entity_pos = camera.WorldToWindow(entity->GetPosition());
|
||||
m_Window->DrawSprite(entity_pos,
|
||||
auto entity_pos_window = camera.WorldToWindow(entity->GetPosition());
|
||||
m_Window->DrawSprite(entity_pos_window,
|
||||
entity->GetSprite(),
|
||||
camera.GetZoom());
|
||||
if (entity->IsCollisionBoxVisible())
|
||||
{
|
||||
float collision_radius = camera.WorldToWindowSize(entity->GetCollisionRadius());
|
||||
m_Window->DrawCircle(entity_pos, collision_radius, 255, 0, 0);
|
||||
}
|
||||
if (entity->IsSelected())
|
||||
{
|
||||
float collision_radius = camera.WorldToWindowSize(entity->GetCollisionRadius());
|
||||
m_Window->DrawCircle(entity_pos, collision_radius, 0, 255, 0);
|
||||
m_Window->DrawCircle(entity_pos_window, entity->GetCollisionRadius());
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +57,7 @@ void GameLoop::Draw() {
|
||||
if (m_Game->IsSelectionBoxActive())
|
||||
{
|
||||
const auto& [corner_pos, size] = m_Game->GetSelectionBoxPosSize();
|
||||
m_Window->DrawRect(corner_pos, size, 200, 20, 20);
|
||||
m_Window->DrawRect(corner_pos, size, 200, 20, 20, 100);
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,7 +207,6 @@ void PathFindingDemo::HandleActions(const std::vector<UserAction> &actions)
|
||||
{
|
||||
m_SelectionBox.active = true;
|
||||
m_SelectionBox.start = action.Argument.position;
|
||||
m_SelectionBox.end = action.Argument.position;
|
||||
}
|
||||
else if (action.type == UserAction::Type::SELECTION_END)
|
||||
{
|
||||
@ -229,21 +228,10 @@ void PathFindingDemo::HandleActions(const std::vector<UserAction> &actions)
|
||||
};
|
||||
}
|
||||
|
||||
void PathFindingDemo::DeselectEntities()
|
||||
{
|
||||
std::for_each(m_SelectedEntities.begin(), m_SelectedEntities.end(), [](auto& x)
|
||||
{
|
||||
if (auto entity = x.lock())
|
||||
entity->Deselect();
|
||||
}
|
||||
);
|
||||
m_SelectedEntities.clear();
|
||||
}
|
||||
|
||||
void PathFindingDemo::SelectEntitiesInRectangle(WorldPos A, WorldPos B)
|
||||
{
|
||||
DeselectEntities();
|
||||
// TODO use colliders for this
|
||||
m_SelectedEntities.clear();
|
||||
auto [x_min, x_max] = std::minmax(A.x(), B.x());
|
||||
auto [y_min, y_max] = std::minmax(A.y(), B.y());
|
||||
for (const auto& entity : m_Entities)
|
||||
@ -254,7 +242,6 @@ void PathFindingDemo::SelectEntitiesInRectangle(WorldPos A, WorldPos B)
|
||||
if (x_in_range && y_in_range)
|
||||
{
|
||||
m_SelectedEntities.push_back(std::weak_ptr(entity));
|
||||
entity->Select();
|
||||
}
|
||||
}
|
||||
LOG_INFO("Selected ", m_SelectedEntities.size(), " entities");
|
||||
|
@ -43,10 +43,8 @@ public:
|
||||
WorldPos GetRandomPosition() const;
|
||||
|
||||
void SelectEntitiesInRectangle(WorldPos A, WorldPos B);
|
||||
void DeselectEntities();
|
||||
bool IsSelectionBoxActive() const { return m_SelectionBox.active; }
|
||||
std::pair<WindowPos, WindowSize> GetSelectionBoxPosSize();
|
||||
std::vector<std::weak_ptr<Entity>> GetSelectedEntities() { return m_SelectedEntities; }
|
||||
|
||||
private:
|
||||
const std::vector<Collision>& GetEntityCollisions();
|
||||
|
@ -91,10 +91,12 @@ void Window::DrawFilledRect(const WindowPos &position, const WindowSize size, ui
|
||||
SDL_RenderFillRect(m_Renderer.get(), &rect);
|
||||
}
|
||||
|
||||
void Window::DrawRect(const WindowPos &position, const WindowSize size, uint8_t R, uint8_t G, uint8_t B) {
|
||||
void Window::DrawRect(const WindowPos &position, const WindowSize size, uint8_t R,
|
||||
uint8_t G, uint8_t B, uint8_t fill_alpha) {
|
||||
SDL_FRect rect = {position.x(), position.y(), size.x(), size.y()};
|
||||
SDL_SetRenderDrawColor(m_Renderer.get(), R, G, B, 255);
|
||||
SDL_RenderRect(m_Renderer.get(), &rect);
|
||||
//SDL_RenderFillRect(m_Renderer.get(), &rect);
|
||||
}
|
||||
|
||||
void Window::ClearWindow() {
|
||||
@ -104,11 +106,10 @@ void Window::ClearWindow() {
|
||||
|
||||
void Window::Flush() { SDL_RenderPresent(m_Renderer.get()); }
|
||||
|
||||
// TODO use some struct for color
|
||||
void Window::DrawCircle(const WindowPos &position, float radius, uint8_t R, uint8_t G, uint8_t B) {
|
||||
void Window::DrawCircle(const WindowPos &position, float radius) {
|
||||
int cx = static_cast<int>(position.x());
|
||||
int cy = static_cast<int>(position.y());
|
||||
SDL_SetRenderDrawColor(m_Renderer.get(), R, G, B, 255);
|
||||
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 0, 0, 255);
|
||||
for (int i = 0; i < 360; ++i) {
|
||||
double a = i * M_PI / 180.0;
|
||||
SDL_RenderPoint(m_Renderer.get(),
|
||||
|
@ -25,10 +25,11 @@ public:
|
||||
void DrawSprite(const WindowPos &position, Sprite &s, float scale = 1.0f);
|
||||
void DrawFilledRect(const WindowPos &position, const WindowSize size, uint8_t R,
|
||||
uint8_t G, uint8_t B, uint8_t A);
|
||||
void DrawRect(const WindowPos &position, const WindowSize size, uint8_t R, uint8_t G, uint8_t B);
|
||||
void DrawRect(const WindowPos &position, const WindowSize size, uint8_t R,
|
||||
uint8_t G, uint8_t B, uint8_t fill_alpha);
|
||||
void ClearWindow();
|
||||
void Flush();
|
||||
void DrawCircle(const WindowPos &position, float radius, uint8_t R, uint8_t G, uint8_t B);
|
||||
void DrawCircle(const WindowPos &position, float radius);
|
||||
void DrawLine(const WindowPos &A, const WindowPos &B);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user