Draw the path
This commit is contained in:
parent
ea316ab997
commit
e6fc4e881c
@ -7,6 +7,8 @@
|
|||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "user_input.hpp"
|
#include "user_input.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
#include "pathfinder.hpp"
|
||||||
|
#include "math.hpp"
|
||||||
|
|
||||||
void GameLoop::Run() {
|
void GameLoop::Run() {
|
||||||
LOG_INFO("Running the game");
|
LOG_INFO("Running the game");
|
||||||
@ -16,6 +18,9 @@ void GameLoop::Run() {
|
|||||||
|
|
||||||
m_Window->ClearWindow();
|
m_Window->ClearWindow();
|
||||||
|
|
||||||
|
// TODO wrap all of the drawing in some function
|
||||||
|
// TODO rethink coupling and dependencies here
|
||||||
|
|
||||||
// draw the map (terrain tiles)
|
// draw the map (terrain tiles)
|
||||||
const Map &map = m_Game->GetMap();
|
const Map &map = m_Game->GetMap();
|
||||||
const auto &tiles = map.GetMapTiles();
|
const auto &tiles = map.GetMapTiles();
|
||||||
@ -29,6 +34,13 @@ void GameLoop::Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw the path, if it exists
|
||||||
|
WorldPos start_pos = m_Game->GetPlayer()->GetPosition();
|
||||||
|
for (const auto& next_pos: m_Game->GetPath()) {
|
||||||
|
m_Window->DrawLine(start_pos, next_pos);
|
||||||
|
start_pos = next_pos;
|
||||||
|
}
|
||||||
|
|
||||||
// draw all the entities (player etc)
|
// draw all the entities (player etc)
|
||||||
for (auto &entity : m_Game->GetEntities()) {
|
for (auto &entity : m_Game->GetEntities()) {
|
||||||
m_Window->DrawSprite(entity->GetPosition(), entity->GetSprite());
|
m_Window->DrawSprite(entity->GetPosition(), entity->GetSprite());
|
||||||
|
@ -24,6 +24,7 @@ public:
|
|||||||
std::shared_ptr<Player> GetPlayer() { return m_Player; }
|
std::shared_ptr<Player> GetPlayer() { return m_Player; }
|
||||||
std::vector<std::shared_ptr<Entity>>& GetEntities() { return m_Entities; }
|
std::vector<std::shared_ptr<Entity>>& GetEntities() { return m_Entities; }
|
||||||
const Map& GetMap() const { return m_Map; }
|
const Map& GetMap() const { return m_Map; }
|
||||||
|
const pathfinder::Path& GetPath() const { return m_Path; }
|
||||||
bool IsExitRequested() const { return m_ExitRequested; }
|
bool IsExitRequested() const { return m_ExitRequested; }
|
||||||
|
|
||||||
void AddEntity(std::shared_ptr<Entity> e);
|
void AddEntity(std::shared_ptr<Entity> e);
|
||||||
|
@ -109,3 +109,10 @@ void Window::DrawCircle(const WorldPos &position, float radius) {
|
|||||||
cy + static_cast<int>(std::round(radius * std::sin(a))));
|
cy + static_cast<int>(std::round(radius * std::sin(a))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::DrawLine(const WorldPos &A, const WorldPos &B)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 0, 0, 255);
|
||||||
|
SDL_RenderLine(m_Renderer.get(), A.x, A.y, B.x, B.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ public:
|
|||||||
void ClearWindow();
|
void ClearWindow();
|
||||||
void Flush();
|
void Flush();
|
||||||
void DrawCircle(const WorldPos &position, float radius);
|
void DrawCircle(const WorldPos &position, float radius);
|
||||||
|
void DrawLine(const WorldPos &A, const WorldPos &B);
|
||||||
|
|
||||||
std::shared_ptr<SDL_Renderer> m_Renderer = nullptr;
|
std::shared_ptr<SDL_Renderer> m_Renderer = nullptr;
|
||||||
SDL_Window *m_Window;
|
SDL_Window *m_Window;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user