mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 22:41:48 +01:00
Add Particles (basic)
This commit is contained in:
@@ -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<Particle*> 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;
|
||||
|
||||
@@ -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<Collision::CollisionRect> m_Rects;
|
||||
|
||||
std::vector<Particle*> m_Particles;
|
||||
int testCounter{ 0 };
|
||||
|
||||
private:
|
||||
double m_Fps{ 0.0f };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user