diff --git a/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version b/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version new file mode 100644 index 0000000..720d64f Binary files /dev/null and b/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version differ diff --git a/.idea/.idea.Motherload/.idea/vcs.xml b/.idea/.idea.Motherload/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.Motherload/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml new file mode 100644 index 0000000..6827606 --- /dev/null +++ b/.idea/.idea.Motherload/.idea/workspace.xml @@ -0,0 +1,169 @@ + + + + Game/Game.vcxproj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "customColor": "", + "associatedIndex": 1 +} + + + + { + "keyToString": { + "C++ Project.Game.executor": "Run", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + }, + "keyToStringList": { + "rider.external.source.directories": [ + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache", + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache", + "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src" + ] + } +} + + + + + + + + + + + + + + + + + 1711617171269 + + + + + + + + \ No newline at end of file diff --git a/Assets/PlayerWalk.aseprite b/Assets/PlayerWalk.aseprite new file mode 100644 index 0000000..c2c0cc2 Binary files /dev/null and b/Assets/PlayerWalk.aseprite differ diff --git a/Assets/PlayerWalk.png b/Assets/PlayerWalk.png new file mode 100644 index 0000000..ff6cce1 Binary files /dev/null and b/Assets/PlayerWalk.png differ diff --git a/Engine/utils.cpp b/Engine/utils.cpp index 0e3d5b1..91aa400 100644 --- a/Engine/utils.cpp +++ b/Engine/utils.cpp @@ -757,11 +757,8 @@ int utils::randRange(int min, int max) { } bool utils::isKeyDown(int keycode) { const Uint8* pStates = SDL_GetKeyboardState(nullptr); - if (pStates != nullptr) - { - if(pStates[keycode]) { - return true; - } + if (pStates != nullptr) { + return pStates[keycode]; } return false; } @@ -771,8 +768,10 @@ bool utils::isKeyPressed(int keycode) { if (pStates != nullptr) { if(pStates[keycode] && !s_KeyStates[keycode]) { s_KeyStates[keycode] = true; - return s_KeyStates[keycode]; + }else { + s_KeyStates[keycode] = false; } + return s_KeyStates[keycode]; } return false; } diff --git a/Game/Game.cpp b/Game/Game.cpp index 7a39475..c53e23e 100644 --- a/Game/Game.cpp +++ b/Game/Game.cpp @@ -47,8 +47,6 @@ void Game::Update(float elapsedSec) { void Game::Draw() const { utils::ClearBackground(Color4f(0.0f, 0.0f, 0.3f, 1.0f)); m_WorldLevel.Draw(); - TextureManager::GetInstance()->GetTexture("dingus.png")->Draw(Point2f{0,0}, {}, true); - TextureManager::GetInstance()->GetTexture("dingus.png")->Draw(Point2f{0,300}, {}, false); } void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) { @@ -76,7 +74,7 @@ void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) { //case SDL_BUTTON_LEFT: // std::cout << " left button " << std::endl; // break; - //case SDL_BUTTON_RIGHT: + //case SDL_BUTTON_RIGHT:k // std::cout << " right button " << std::endl; // break; //case SDL_BUTTON_MIDDLE: diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index a30b7d4..2540025 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -315,9 +315,6 @@ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s - - - diff --git a/Game/Player.cpp b/Game/Player.cpp index 876caa7..fdd46b4 100644 --- a/Game/Player.cpp +++ b/Game/Player.cpp @@ -67,7 +67,6 @@ void Player::Update(float elapsedTime, WorldLevel& level) { m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr; } - } } if(utils::isKeyDown(SDL_SCANCODE_A)) { @@ -93,7 +92,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) { if(m_DidJustDigRight) { if(!utils::isKeyDown(SDL_SCANCODE_D)) { m_DidJustDigRight = false; - } + } } m_ContactMap[Collision::CollisionDirection::Top] = nullptr; @@ -112,9 +111,10 @@ void Player::Update(float elapsedTime, WorldLevel& level) { for (int x { 0 }; x < WORLD_WIDTH; ++x) { for(int y { 0 }; y < WORLD_HEIGHT; ++y) { - if(gridManager.GetTileAtIndex(x,y)->GetTileType() == Tiles::DIRT) { - gridManager.GetTileAtIndex(x,y)->m_Hightlight = false; - if(Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) { + WorldTile* tile = gridManager.GetTileAtIndex(x,y); + if(*tile->GetTileType() != Tiles::AIR) { + tile->m_Hightlight = false; + if(Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) { contactTimes.push_back(std::pair{x + y * WORLD_WIDTH, t}); } } diff --git a/Game/TextureManager.cpp b/Game/TextureManager.cpp index 9be57bc..cd5c72b 100644 --- a/Game/TextureManager.cpp +++ b/Game/TextureManager.cpp @@ -15,6 +15,4 @@ Texture* TextureManager::GetTexture(const std::string& name) { Texture* pTexture = new Texture(name); m_Textures[name] = pTexture; return pTexture; -} - - +} \ No newline at end of file diff --git a/Game/WorldGridManager.h b/Game/WorldGridManager.h index ad01747..c513737 100644 --- a/Game/WorldGridManager.h +++ b/Game/WorldGridManager.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include "structs.h" @@ -11,6 +12,19 @@ static const int TILE_HEIGHT = 50; class WorldTile; +struct surroundingTiles { + std::array tiles; + + //Center of the surrounding tiles is 0, 0 + void SetTile(int x, int y, WorldTile* tile) { + tiles[x + y * 3] = tile; + } + + WorldTile* GetTile(int x, int y) { + return tiles[x + y * 3]; + } +}; + class WorldGridManager { public: diff --git a/Game/WorldLevel.cpp b/Game/WorldLevel.cpp index b9b45d7..0ff10ac 100644 --- a/Game/WorldLevel.cpp +++ b/Game/WorldLevel.cpp @@ -23,8 +23,23 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) { int actualX = x - WORLD_WIDTH / 2; Point2f pos = Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT}; - GroundTileType type = rand() % 2 == 0 ? Tiles::DIRT : Tiles::DIRT; - m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, Tiles::DIRT, TextureManager::GetInstance() }); + GroundTileType* type = Tiles::AIR; + switch(utils::randRange(0,2)) { + case 0: + type = Tiles::DIRT; + break; + case 1: + type = Tiles::IRON; + break; + case 2: + //AIR + break; + default: + std::cout << "??" << std::endl; + } + + + m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, type, TextureManager::GetInstance() }); } } for (size_t x { 0 }; x < WORLD_WIDTH; ++x) { @@ -92,7 +107,7 @@ void WorldLevel::Draw() const { //loop over worldtiles for (int x { 0 }; x < WORLD_WIDTH; ++x) { for (int y { 0 }; y < WORLD_HEIGHT; ++y) { - if(m_gridManager.GetTileAtIndex(x,y)->GetTileType() == Tiles::DIRT) { + if(*m_gridManager.GetTileAtIndex(x,y)->GetTileType() != Tiles::AIR) { Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().getCollisionRect(); utils::SetColor(Colors::GREEN); utils::DrawRect(rect.pos, rect.size.x, rect.size.y); diff --git a/Game/WorldTile.cpp b/Game/WorldTile.cpp index 5e923c1..3e8803d 100644 --- a/Game/WorldTile.cpp +++ b/Game/WorldTile.cpp @@ -6,16 +6,16 @@ #include "utils.h" -WorldTile::WorldTile(const Point2f& position, GroundTileType groundTileType, TextureManager* pTextureManager) : m_Position { position }, m_GroundTileType { groundTileType } { +WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager) : m_Position { position }, m_GroundTileType { groundTileType } { // const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png"; // m_pTexture = new Texture(dirtPath); - m_pTexture = pTextureManager->GetTexture(groundTileType.getPath()); + m_pTexture = pTextureManager->GetTexture(groundTileType->getPath()); } WorldTile::~WorldTile() { delete m_pTexture; } void WorldTile::Draw() const { - if (m_GroundTileType == Tiles::DIRT) { + if (*m_GroundTileType != Tiles::AIR) { m_pTexture->Draw(m_Position); if(m_Hightlight) { utils::SetColor(Colors::GREEN); diff --git a/Game/WorldTile.h b/Game/WorldTile.h index caaf47e..ea5836c 100644 --- a/Game/WorldTile.h +++ b/Game/WorldTile.h @@ -24,16 +24,20 @@ public: return m_type != rhs.m_type; } - bool operator== (const GroundTileType* rhs) const { + virtual bool operator== (const GroundTileType* rhs) const { return rhs->m_type == m_type; } - bool operator!= (const GroundTileType* rhs) const { + virtual bool operator!= (const GroundTileType* rhs) const { return rhs->m_type != m_type; } - virtual std::string getPath() { + virtual std::string getPath() const { return m_filePath; } + + virtual GroundTileTypes getType() const { + return m_type; + } protected: std::string m_filePath; private: @@ -42,37 +46,48 @@ private: class RandomGroundTile: public GroundTileType { public: - RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_variant(utils::randRange(1, maxRandom)) { + RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) { } ~RandomGroundTile() override = default; - std::string getPath() override { + bool operator== (const GroundTileType* rhs) const override{ + return rhs->getType() == this->getType(); + } + + bool operator!= (const GroundTileType* rhs) const override{ + return rhs->getType() != this->getType(); + } + + std::string getPath() const override { + int variant = utils::randRange(1, m_maxRandom); std::string toReplace{ "[0]" }; - std::string replacement = std::to_string(m_variant); + std::string replacement = std::to_string(utils::randRange(1, m_maxRandom)); size_t found = m_filePath.find(toReplace); - std::string newFilePath{ m_filePath }; + std::string newFilePath{ m_filePath }; + if(found != std::string::npos) { newFilePath.replace(found, 3, replacement); } + return newFilePath; } private: - int m_variant; + int m_maxRandom; }; namespace Tiles { - static GroundTileType AIR = GroundTileType("", GroundTileTypes::Air); - static GroundTileType DIRT = RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 6); - static GroundTileType IRON = GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron); + static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air); + static GroundTileType* DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5); + static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron); } class WorldTile { public: WorldTile() = default; - WorldTile(const Point2f& position, GroundTileType groundTileType, TextureManager* pTextureManager); + WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager); ~WorldTile(); void Draw() const; @@ -82,8 +97,8 @@ public: Point2f GetSize() const { return Point2f{ 50, 50 }; } - GroundTileType GetTileType() const { return m_GroundTileType; } - void SetTileType(GroundTileType type) { m_GroundTileType = type; } + GroundTileType* GetTileType() const { return m_GroundTileType; } + void SetTileType(GroundTileType* type) { m_GroundTileType = type; } Collision::TileCollisionRect GetCollisionRect(); @@ -92,7 +107,7 @@ public: private: Point2f m_Position; - GroundTileType m_GroundTileType; + GroundTileType* m_GroundTileType; Texture* m_pTexture; diff --git a/Prog2Engine.sln b/Motherload.sln similarity index 100% rename from Prog2Engine.sln rename to Motherload.sln