mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 12:21:48 +01:00
Add Imgui Navbar
This commit is contained in:
@@ -11,7 +11,12 @@
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
WorldLevel::WorldLevel(Camera* camera) : Level(camera), m_mousePos{ 0, 0 }, m_player(Player{ Point2f{ 0, 100 } }) {
|
||||
WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
|
||||
Level(camera),
|
||||
m_player(Player { Point2f { 0, 100 } }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport)
|
||||
{
|
||||
// The grid is 34 x 50 big, the top center is 0,0 in world coords
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -19,22 +24,7 @@ WorldLevel::WorldLevel(Camera* camera) : Level(camera), m_mousePos{ 0, 0 }, m_pl
|
||||
m_worldTiles[x][y] = new WorldTile{ Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT}, GroundTileTypes::Dirt, TextureManager::GetInstance()};
|
||||
}
|
||||
}
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{0.0f, 10.0f}, Point2f{40.0f, 40.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{170.0f, 70.0f}, Point2f{10.0f, 40.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{150.0f, 50.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{150.0f, 150.0f}, Point2f{75.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{170.0f, 50.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{190.0f, 50.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{110.0f, 50.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{50.0f, 130.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{50.0f, 150.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{50.0f, 170.0f}, Point2f{20.0f, 20.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{150.0f, 100.0f}, Point2f{10.0f, 1.0f} });
|
||||
m_Rects.push_back(Collision::CollisionRect{ Point2f{200.0f, 100.0f}, Point2f{20.0f, 60.0f} });
|
||||
|
||||
|
||||
// std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
|
||||
// m_pTextTexture = new Texture(dirtPath);
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
//delete m_pTextTexture;
|
||||
@@ -58,82 +48,12 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
}
|
||||
}
|
||||
if(selectedTile != nullptr) {
|
||||
selectedTile->SetTileType(GroundTileTypes::Air);
|
||||
if(utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||
selectedTile->SetTileType(GroundTileTypes::Air);
|
||||
}
|
||||
}
|
||||
|
||||
Point2f RayPoint = Point2f{m_pCamera->Viewport.width, m_pCamera->Viewport.height};
|
||||
Point2f RayDir = Point2f{m_mousePos.x - RayPoint.x, m_mousePos.y - RayPoint.y};
|
||||
|
||||
//wasd movement
|
||||
if(utils::isKeyDown(SDL_SCANCODE_W)) {
|
||||
m_Rects[0].vel.y += 20;
|
||||
}
|
||||
if(utils::isKeyDown(SDL_SCANCODE_S)) {
|
||||
m_Rects[0].vel.y += -10;
|
||||
}
|
||||
if(utils::isKeyDown(SDL_SCANCODE_A)) {
|
||||
m_Rects[0].vel.x += -10;
|
||||
}
|
||||
if(utils::isKeyDown(SDL_SCANCODE_D)) {
|
||||
m_Rects[0].vel.x += 10;
|
||||
}
|
||||
if(utils::isKeyDown(SDL_SCANCODE_SPACE)) {
|
||||
//check if the player is on the ground
|
||||
m_Rects[0].ContactMap[Collision::CollisionDirection::Bottom]->pos.y += 100;
|
||||
}
|
||||
m_Rects[0].vel.y -= 9.81f;
|
||||
|
||||
m_Rects[0].ContactMap.clear();
|
||||
|
||||
float t = 0, min_t = INFINITY;
|
||||
Point2f intersectionPoint, normal;
|
||||
|
||||
std::vector<std::pair<int, float>> contactTimes{};
|
||||
|
||||
m_player.Update(elapsedSec, *this);
|
||||
|
||||
// for (size_t i { 1 }; i < m_Rects.size(); ++i) {
|
||||
// if(Collision::DynamicRectVsRect(m_Rects[0], elapsedSec, m_Rects[i], intersectionPoint, normal, t)) {
|
||||
// contactTimes.push_back(std::pair<int, float>{i, t});
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b) {
|
||||
// return a.second < b.second;
|
||||
// });
|
||||
//
|
||||
// for (std::pair<int, float> contact_time : contactTimes) {
|
||||
// Collision::ResolveDynamicRectVsRect(m_Rects[0], elapsedSec, &m_Rects[contact_time.first]);
|
||||
// }
|
||||
|
||||
//contactTimes.clear();
|
||||
|
||||
// //loop over the worldTiles
|
||||
// for (int x {0} ; x < WORLD_WIDTH; ++x) {
|
||||
// for (int y {0}; y < WORLD_HEIGHT; ++y) {
|
||||
// if(m_worldTiles[x][y]->GetTileType() == GroundTileTypes::Dirt) {
|
||||
// if(Collision::DynamicRectVsRect(m_Rects[0], elapsedSec, m_worldTiles[x][y]->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
|
||||
// contactTimes.push_back(std::pair<int, float>{x + y * WORLD_WIDTH, t});
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b) {
|
||||
// return a.second < b.second;
|
||||
// });
|
||||
//
|
||||
// for (std::pair<int, float> contact_time : contactTimes) {
|
||||
// WorldTile* tile = m_worldTiles[contact_time.first % WORLD_WIDTH][contact_time.first / WORLD_WIDTH];
|
||||
// Collision::CollisionRect rect = tile->GetCollisionRect().getCollisionRect();
|
||||
// Collision::ResolveDynamicRectVsRect(m_Rects[0], elapsedSec, &rect);
|
||||
// //delete tile;
|
||||
// //WorldTile* tileRect = tile->GetCollisionRect().tile;
|
||||
// //tileRect->SetTileType(GroundTileTypes::Air);
|
||||
// }
|
||||
//
|
||||
// m_Rects[0].pos = m_Rects[0].pos + m_Rects[0].vel * elapsedSec;
|
||||
|
||||
}
|
||||
void WorldLevel::Draw() const {
|
||||
m_pCamera->BeginRendering();
|
||||
@@ -167,21 +87,6 @@ void WorldLevel::Draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i { 0 }; i < 4; ++i) {
|
||||
if(m_Rects[0].ContactMap.find(static_cast<Collision::CollisionDirection>(i)) != m_Rects[0].ContactMap.end()) {
|
||||
utils::SetColor(Colors::RED);
|
||||
Collision::CollisionRect* rect = m_Rects[0].ContactMap.at(static_cast<Collision::CollisionDirection>(i));
|
||||
utils::FillRect(rect->pos, rect->size.x, rect->size.y);
|
||||
}
|
||||
}
|
||||
|
||||
// utils::SetColor(Colors::WHITE);
|
||||
// for (int x { -100 }; x < 100; ++x) {
|
||||
// for (int y { -100 }; y < 100; ++y) {
|
||||
// utils::DrawLine(x * 50, -5000, x * 50, 50000);
|
||||
// utils::DrawLine(-5000, y * 50, 50000, y * 50);
|
||||
// }
|
||||
// }
|
||||
utils::SetColor(Colors::MAGENTA);
|
||||
utils::FillEllipse(0, 0, 5, 5);
|
||||
|
||||
@@ -191,21 +96,57 @@ void WorldLevel::Draw() const {
|
||||
void WorldLevel::MouseMove(const Point2f& mousePos) {
|
||||
m_mousePos = mousePos;
|
||||
}
|
||||
|
||||
void WorldLevel::ProcessImGui() {
|
||||
ImGui::Begin("Player Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Player Position: (%f, %f)", m_player.GetPosition().x, m_player.GetPosition().y);
|
||||
ImGui::Text("Player Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
|
||||
//PLAYER COLLISIONS
|
||||
ImGui::Text("Player Collisions:");
|
||||
// for (std::pair<Collision::CollisionDirection, Collision::CollisionRect*> contact : m_player.GetContactMap()) {
|
||||
// ImGui::Text("Direction: %d", contact.first);
|
||||
// ImGui::Text("Position: (%f, %f)", contact.second->pos.x, contact.second->pos.y);
|
||||
// ImGui::Text("Size: (%f, %f)", contact.second->size.x, contact.second->size.y);
|
||||
// }
|
||||
ImGui::End();
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("Properties")) {
|
||||
if (ImGui::MenuItem("TextureManager Info")) {
|
||||
m_ShowTextureManagerWindow = !m_ShowTextureManagerWindow;
|
||||
}
|
||||
if (ImGui::MenuItem("Camera Info")) {
|
||||
m_ShowCameraWindow = !m_ShowCameraWindow;
|
||||
}
|
||||
if(ImGui::MenuItem("Player Info")) {
|
||||
m_ShowPlayerInfo = !m_ShowPlayerInfo;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
if(m_ShowTextureManagerWindow) {
|
||||
ImGui::Begin("Texture Manager", &m_ShowTextureManagerWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Texture loading Count:");
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.0f, 1.0f, 1.0f), std::to_string(Texture::m_TextureCounter).c_str());
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if(m_ShowCameraWindow) {
|
||||
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
|
||||
if(ImGui::Button("Reset Camera")) {
|
||||
m_pCamera->SetPosition(Point2f{m_viewport.width / 2, m_viewport.height / 2});
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if(m_ShowPlayerInfo) {
|
||||
ImGui::Begin("Player Info", &m_ShowPlayerInfo, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Player Position: (%f, %f)", m_player.GetPosition().x, m_player.GetPosition().y);
|
||||
ImGui::Text("Player Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
|
||||
//PLAYER COLLISIONS
|
||||
ImGui::Text("Player Collisions:");
|
||||
// for (std::pair<Collision::CollisionDirection, Collision::CollisionRect*> contact : m_player.GetContactMap()) {
|
||||
// ImGui::Text("Direction: %d", contact.first);
|
||||
// ImGui::Text("Position: (%f, %f)", contact.second->pos.x, contact.second->pos.y);
|
||||
// ImGui::Text("Size: (%f, %f)", contact.second->size.x, contact.second->size.y);
|
||||
// }
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
WorldTile* WorldLevel::GetTileAt(const Point2f& pos) const {
|
||||
return nullptr;
|
||||
return m_worldTiles[pos.x][pos.y];
|
||||
}
|
||||
void WorldLevel::SetTileAt(const Point2f& pos, WorldTile* tile) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user