mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 08:09:19 +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 };
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user