diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml index 60db43f..b5ea7d8 100644 --- a/.idea/.idea.Motherload/.idea/workspace.xml +++ b/.idea/.idea.Motherload/.idea/workspace.xml @@ -11,28 +11,12 @@ - - - - - - - - - - - - - - - - + + - - - { + "keyToString": { + "C++ Project.Game.executor": "Debug", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "ignore.virus.scanning.warn.message": "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", + "settings.editor.selected.configurable": "preferences.sourceCode.C++", + "vue.rearranger.settings.migration": "true" }, - "keyToStringList": { - "rider.external.source.directories": [ - "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", - "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", - "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src" + "keyToStringList": { + "rider.external.source.directories": [ + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", + "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src" ] } -}]]> +} @@ -249,7 +235,8 @@ - + + - @@ -404,7 +399,8 @@ - diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp index db124de..8a62ad3 100644 --- a/Game/Levels/World/WorldLevel.cpp +++ b/Game/Levels/World/WorldLevel.cpp @@ -61,8 +61,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera), m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE); m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE); m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT); - m_Meter = new GuiMeter("gui/main/fuel_guage.png", Vector2f{100, 100}, Vector2f{336, 146}, 100, TextureManager::GetInstance()); - Texture* test = new Texture("gui/main/fuel_guage.png"); + // m_Meter = new GuiMeter("gui/main/fuel_guage.png", Vector2f{100, 100}, Vector2f{336, 146}, 100, TextureManager::GetInstance()); + // Texture* test = new Texture("gui/main/fuel_guage.png"); } WorldLevel::~WorldLevel() { delete m_RefeulBuilding; @@ -73,7 +73,7 @@ WorldLevel::~WorldLevel() { } void WorldLevel::Update(float elapsedSec) { m_Fps = 1 / elapsedSec; - m_Meter->Update(elapsedSec); + // m_Meter->Update(elapsedSec); int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); @@ -95,6 +95,23 @@ void WorldLevel::Update(float elapsedSec) { } } } + testCounter++; + std::vector ToDelete{}; + for(Particle* p : m_Particles) { + p->Update(elapsedSec); + if(p->IsDead()) { + ToDelete.emplace_back(p); + } + } + for (Particle* p : ToDelete) { + m_Particles.erase(std::remove(m_Particles.begin(), m_Particles.end(), p), m_Particles.end()); + delete p; + } + if(testCounter % 100 == 0) { + m_Particles.emplace_back(new Particle(Vector2f{100, 100}, Vector2f{float(utils::randRange(-200, 200)), 10},100, TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png"))); + } + + if (m_pSelectedTile != nullptr) { if (utils::isMouseDown(SDL_BUTTON_LEFT)) { m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR); @@ -180,6 +197,10 @@ void WorldLevel::Draw() const { m_RepairBuilding->Draw(); m_Player.Draw(); + for(Particle* p : m_Particles) { + p->Draw(); + } + utils::SetColor(Colors::GREEN); utils::DrawArrow(Vector2f{0, 0}, m_MousePos); @@ -194,7 +215,7 @@ void WorldLevel::Draw() const { screen->Draw(); } - m_Meter->Draw(); + // m_Meter->Draw(); } void WorldLevel::MouseMove(const Vector2f& mousePos) { m_MousePos = mousePos; diff --git a/Game/Levels/World/WorldLevel.h b/Game/Levels/World/WorldLevel.h index 53796c8..e9e7eb5 100644 --- a/Game/Levels/World/WorldLevel.h +++ b/Game/Levels/World/WorldLevel.h @@ -7,6 +7,7 @@ #include "Gui/Screens/ScreenManager.h" #include "Camera.h" #include "Gui/GuiMeter.h" +#include "Particle/Particle.h" class WorldLevel : public Level { @@ -27,6 +28,9 @@ public: std::vector m_Rects; + std::vector m_Particles; + int testCounter{ 0 }; + private: double m_Fps{ 0.0f }; diff --git a/Game/Particle/Particle.cpp b/Game/Particle/Particle.cpp index a83b9f5..bad2586 100644 --- a/Game/Particle/Particle.cpp +++ b/Game/Particle/Particle.cpp @@ -1,10 +1,19 @@ #include "pch.h" #include "Particle.h" -Particle::Particle(const Vector2f& pos, const Vector2f& velocity, Texture* pTexture): m_Position{ pos }, m_Velocity{ velocity }, m_pTexture{ pTexture } -{} +Particle::Particle(const Vector2f& pos, const Vector2f& velocity, float lifetime, Texture* pTexture): m_Position { pos }, m_Velocity { velocity }, m_LifeTime { lifetime }, + m_pTexture { pTexture } { +} void Particle::Update(float elapsedSec) { - + m_Acceleration = Vector2f { 0.0f, -9.81f * 20}; + m_Velocity += m_Acceleration * elapsedSec; + m_Position += m_Velocity * elapsedSec; + m_LifeTime -= elapsedSec; + m_Acceleration = Vector2f { 0.0f, 0.0f }; + } void Particle::Draw() const { - + m_pTexture->Draw(m_Position); +} +bool Particle::IsDead() const { + return m_LifeTime <= 0.0f; } diff --git a/Game/Particle/Particle.h b/Game/Particle/Particle.h index 5c55b21..a6237df 100644 --- a/Game/Particle/Particle.h +++ b/Game/Particle/Particle.h @@ -4,13 +4,17 @@ class Particle { public: Particle() = default; - Particle(const Vector2f& pos, const Vector2f& velocity, Texture* pTexture); + Particle(const Vector2f& pos, const Vector2f& velocity,float lifetime, Texture* pTexture); void Update(float elapsedSec); void Draw() const; + bool IsDead() const; + private: Vector2f m_Position; Vector2f m_Velocity; Vector2f m_Acceleration; + float m_LifeTime; + Texture* m_pTexture; }; diff --git a/Game/Player.cpp b/Game/Player.cpp index 51ff8db..2953179 100644 --- a/Game/Player.cpp +++ b/Game/Player.cpp @@ -166,6 +166,9 @@ void Player::Update(float elapsedTime, WorldLevel& level) { m_BobTimer = 0.0f; } + + + //check for keys if (m_State != PlayerState::Digging) { if (utils::isKeyDown(SDL_SCANCODE_W)) { diff --git a/Resources/particles/dirt_1.png b/Resources/particles/dirt_1.png new file mode 100644 index 0000000..6627f8c Binary files /dev/null and b/Resources/particles/dirt_1.png differ diff --git a/Resources/particles/dirt_2.png b/Resources/particles/dirt_2.png new file mode 100644 index 0000000..02ff851 Binary files /dev/null and b/Resources/particles/dirt_2.png differ diff --git a/Resources/particles/dirt_3.png b/Resources/particles/dirt_3.png new file mode 100644 index 0000000..4d73c28 Binary files /dev/null and b/Resources/particles/dirt_3.png differ diff --git a/Resources/particles/dirt_4.png b/Resources/particles/dirt_4.png new file mode 100644 index 0000000..48d8344 Binary files /dev/null and b/Resources/particles/dirt_4.png differ diff --git a/Resources/particles/dirt_5.png b/Resources/particles/dirt_5.png new file mode 100644 index 0000000..d6d2584 Binary files /dev/null and b/Resources/particles/dirt_5.png differ diff --git a/Resources/particles/dirt_6.png b/Resources/particles/dirt_6.png new file mode 100644 index 0000000..30a8181 Binary files /dev/null and b/Resources/particles/dirt_6.png differ diff --git a/Resources/particles/dirt_7.png b/Resources/particles/dirt_7.png new file mode 100644 index 0000000..99ba308 Binary files /dev/null and b/Resources/particles/dirt_7.png differ diff --git a/Resources/particles/dirt_8.png b/Resources/particles/dirt_8.png new file mode 100644 index 0000000..3917cf6 Binary files /dev/null and b/Resources/particles/dirt_8.png differ