mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 22:21:47 +01:00
Fix digging
This commit is contained in:
@@ -19,7 +19,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
m_player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
|
||||
m_mousePos { 0, 0 },
|
||||
m_viewport(viewport),
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
m_screenManager(ScreenManager::GetInstance()) {
|
||||
// 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) {
|
||||
@@ -39,22 +39,21 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
default:
|
||||
std::cout << "??" << '\n';
|
||||
}
|
||||
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager});
|
||||
|
||||
m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, Tiles::DIRT, TextureManager::GetInstance(), &m_gridManager });
|
||||
}
|
||||
}
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
|
||||
m_gridManager.GetTileAtIndex(x, 1)->SetTileType(Tiles::IRON);
|
||||
}
|
||||
m_refeulBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -50 }, TextureManager::GetInstance() };
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-700, -50})->SetTileType(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-650, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f{-600, -50})->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
}
|
||||
WorldLevel::~WorldLevel() {
|
||||
//delete m_pTextTexture;
|
||||
|
||||
}
|
||||
void WorldLevel::Update(float elapsedSec) {
|
||||
int mouseX, mouseY;
|
||||
@@ -62,7 +61,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
m_mousePos = Vector2f { float(mouseX), float(mouseY) };
|
||||
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
|
||||
|
||||
|
||||
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
|
||||
@@ -84,15 +83,16 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
}
|
||||
|
||||
//Get the diogonal tiles of the selected tile
|
||||
if(m_pSelectedTile != nullptr) {
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
|
||||
TileDirection direction = TileDirection::TopMiddle;
|
||||
const std::array<TileDirection, 8> directions = {TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft, TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight};
|
||||
const std::array<TileDirection, 8> directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
|
||||
TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
direction = directions[i];
|
||||
if(surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if(surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
|
||||
if (surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if (surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
|
||||
//surroundingTiles.GetTile(direction)->m_Hightlight = true;
|
||||
}
|
||||
}
|
||||
@@ -105,14 +105,13 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
if (screen != nullptr) {
|
||||
screen->Update(elapsedSec);
|
||||
}
|
||||
|
||||
|
||||
//Vector2f playerPos = m_player.GetPosition();
|
||||
//Vector2f newCameraPos = playerPos;
|
||||
//m_pCamera->SetPosition(newCameraPos);
|
||||
|
||||
//place the player in the center of the camera
|
||||
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
|
||||
|
||||
}
|
||||
void WorldLevel::Draw() const {
|
||||
m_pCamera->BeginRendering();
|
||||
@@ -131,15 +130,18 @@ void WorldLevel::Draw() const {
|
||||
}
|
||||
|
||||
utils::SetColor(Colors::MAGENTA);
|
||||
utils::FillEllipse(0, 0, 5, 5);
|
||||
utils::FillEllipse(-5, -5, 5, 5);
|
||||
|
||||
m_player.Draw();
|
||||
if(m_pSelectedTile != nullptr) {
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
m_pSelectedTile->Draw();
|
||||
}
|
||||
|
||||
m_refeulBuilding->Draw();
|
||||
|
||||
m_player.Draw();
|
||||
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::DrawArrow(Vector2f{0, 0}, m_mousePos);
|
||||
|
||||
m_pCamera->EndRendering();
|
||||
|
||||
utils::FillRect(utils::GetMousePos(), 10, 10);
|
||||
@@ -153,6 +155,32 @@ void WorldLevel::MouseMove(const Vector2f& mousePos) {
|
||||
}
|
||||
|
||||
void WorldLevel::ProcessImGui() {
|
||||
ImGui::Begin("Selected Tile");
|
||||
std::string tileType = "None";
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
switch (m_pSelectedTile->GetTileType()->getType()) {
|
||||
case GroundTileTypes::Air:
|
||||
tileType = "Air";
|
||||
break;
|
||||
case GroundTileTypes::Dirt:
|
||||
tileType = "Dirt";
|
||||
break;
|
||||
case GroundTileTypes::Iron:
|
||||
tileType = "Iron";
|
||||
break;
|
||||
case GroundTileTypes::Hard:
|
||||
tileType = "Hard";
|
||||
break;
|
||||
case GroundTileTypes::Stone:
|
||||
tileType = "Stone";
|
||||
break;
|
||||
default:
|
||||
tileType = "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
ImGui::Text("Selected Tile: %s", tileType.c_str());
|
||||
ImGui::End();
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
if (ImGui::BeginMenu("Properties")) {
|
||||
if (ImGui::MenuItem("TextureManager Info")) {
|
||||
@@ -166,29 +194,28 @@ void WorldLevel::ProcessImGui() {
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if(ImGui::BeginMenu("Screens")) {
|
||||
if(ImGui::MenuItem("Open Fuel screen")) {
|
||||
if (ImGui::BeginMenu("Screens")) {
|
||||
if (ImGui::MenuItem("Open Fuel screen")) {
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::Fuel);
|
||||
}
|
||||
|
||||
|
||||
if(ImGui::MenuItem("Open Sell screen")) {
|
||||
|
||||
if (ImGui::MenuItem("Open Sell screen")) {
|
||||
ScreenManager::GetInstance()->OpenScreen(ScreenManager::SellScreen);
|
||||
}
|
||||
|
||||
if(ImGui::MenuItem("Close Screen")) {
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
if (ImGui::MenuItem("Close Screen")) {
|
||||
ScreenManager::GetInstance()->CloseScreen();
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
const Vector2f screenPos = utils::GetMousePos();
|
||||
const std::string mousePos = "Mouse Pos: (" + std::to_string(screenPos.x) + ", " + std::to_string(screenPos.y) + ")";
|
||||
if(ImGui::BeginMenu(mousePos.c_str())) {
|
||||
|
||||
ImGui::EndMenu();
|
||||
if (ImGui::BeginMenu(mousePos.c_str())) {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user