#include "pch.h" #include "WorldLevel.h" #include #include #include "colors.h" #include "utils.h" WorldLevel::WorldLevel(Camera* camera) : Level(camera), m_mousePos{ 0, 0 }, m_player(Player{ Point2f{ 0, 100 } }) { // 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) { int actualX = x - WORLD_WIDTH / 2; m_worldTiles[x][y] = new WorldTile{ Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT}, GroundTileTypes::Dirt}; } } // std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png"; // m_pTextTexture = new Texture(dirtPath); } WorldLevel::~WorldLevel() { //delete m_pTextTexture; } void WorldLevel::Update(float elapsedSec) { int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); m_mousePos = Point2f{ float(mouseX), float(mouseY) }; m_player.Update(elapsedSec, *this); } void WorldLevel::Draw() const { m_pCamera->BeginRendering(); for (size_t x { 0 }; x < WORLD_WIDTH; ++x) { for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) { m_worldTiles[x][y]->Draw(); } } 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, 10, 10); m_player.Draw(); m_pCamera->EndRendering(); //utils::SetColor(Colors::WHITE); //m_pTextTexture->Draw(Point2f{ 0, 0 }); } void WorldLevel::MouseMove(const Point2f& mousePos) { m_mousePos = mousePos; } WorldTile* WorldLevel::GetTileAt(const Point2f& pos) const { return nullptr; } void WorldLevel::SetTileAt(const Point2f& pos, WorldTile* tile) { } std::array, WorldLevel::WORLD_HEIGHT> WorldLevel::GetAllTiles() const { return m_worldTiles; }