Draw the path
This commit is contained in:
parent
ea316ab997
commit
e6fc4e881c
@ -7,6 +7,8 @@
|
||||
#include "window.hpp"
|
||||
#include "user_input.hpp"
|
||||
#include "log.hpp"
|
||||
#include "pathfinder.hpp"
|
||||
#include "math.hpp"
|
||||
|
||||
void GameLoop::Run() {
|
||||
LOG_INFO("Running the game");
|
||||
@ -16,6 +18,9 @@ void GameLoop::Run() {
|
||||
|
||||
m_Window->ClearWindow();
|
||||
|
||||
// TODO wrap all of the drawing in some function
|
||||
// TODO rethink coupling and dependencies here
|
||||
|
||||
// draw the map (terrain tiles)
|
||||
const Map &map = m_Game->GetMap();
|
||||
const auto &tiles = map.GetMapTiles();
|
||||
@ -29,11 +34,18 @@ 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)
|
||||
for (auto &entity : m_Game->GetEntities()) {
|
||||
m_Window->DrawSprite(entity->GetPosition(), entity->GetSprite());
|
||||
}
|
||||
|
||||
|
||||
m_Window->Flush();
|
||||
// TODO measure fps
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
|
@ -22,8 +22,9 @@ public:
|
||||
PathFindingDemo &operator=(PathFindingDemo &&) = delete;
|
||||
|
||||
std::shared_ptr<Player> GetPlayer() { return m_Player; }
|
||||
std::vector<std::shared_ptr<Entity>> &GetEntities() { return m_Entities; }
|
||||
const Map &GetMap() const { return m_Map; }
|
||||
std::vector<std::shared_ptr<Entity>>& GetEntities() { return m_Entities; }
|
||||
const Map& GetMap() const { return m_Map; }
|
||||
const pathfinder::Path& GetPath() const { return m_Path; }
|
||||
bool IsExitRequested() const { return m_ExitRequested; }
|
||||
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
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 Flush();
|
||||
void DrawCircle(const WorldPos &position, float radius);
|
||||
void DrawLine(const WorldPos &A, const WorldPos &B);
|
||||
|
||||
std::shared_ptr<SDL_Renderer> m_Renderer = nullptr;
|
||||
SDL_Window *m_Window;
|
||||
|
Loading…
x
Reference in New Issue
Block a user