-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
839607c
commit 389d651
Showing
17 changed files
with
255 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "stdafx.h" | ||
#include "Functions.h" | ||
#include "Particle.h" | ||
|
||
Particle::Particle(const sf::VideoMode& vm, const std::string& name, const float& x, const float& y, const std::uint32_t& attack) | ||
:vm(vm), name(name), attack(attack) | ||
{ | ||
if (this->name == "bomb") | ||
this->texture.loadFromFile("external/assets/explosion.png"); | ||
this->sprite.setTexture(this->texture); | ||
this->sprite.setScale(calcScale(4, vm), calcScale(4, vm)); | ||
this->sprite.setTextureRect(sf::IntRect(0, 0, 32, 32)); | ||
this->sprite.setPosition(x - this->sprite.getGlobalBounds().width / 2.f, y - this->sprite.getGlobalBounds().height / 2.f); | ||
|
||
this->animationCooldown = 0; | ||
this->frame = 0; | ||
this->exploded = false; | ||
} | ||
|
||
Particle::~Particle() | ||
{ | ||
} | ||
|
||
const bool Particle::getExploded() const | ||
{ | ||
return this->exploded; | ||
} | ||
|
||
const uint32_t Particle::getAttack() const | ||
{ | ||
return this->attack; | ||
} | ||
|
||
const sf::FloatRect Particle::getGlobalBounds() const | ||
{ | ||
return this->sprite.getGlobalBounds(); | ||
} | ||
|
||
void Particle::update(const float& dt) | ||
{ | ||
if (!this->exploded) { | ||
this->animationCooldown += dt; | ||
if (this->animationCooldown >= 0.1f) { | ||
this->animationCooldown = 0.f; | ||
|
||
if (this->frame == 192) { | ||
this->exploded = true; | ||
this->frame = 192; | ||
} | ||
else { | ||
sf::IntRect intRect(this->frame, 0, 32, 32); | ||
this->sprite.setTextureRect(intRect); | ||
this->frame += 32; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void Particle::draw(sf::RenderTarget& target) | ||
{ | ||
target.draw(this->sprite); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef PARTICLE_H | ||
#define PARTICLE_H | ||
|
||
#include "MonsterSystem.h" | ||
#include "FloatingTextSystem.h" | ||
#include "SoundEngine.h" | ||
|
||
class MonsterSystem; | ||
class FloatingTextSystem; | ||
class SoundEngine; | ||
|
||
class Particle | ||
{ | ||
public: | ||
Particle(const sf::VideoMode& vm, const std::string& name, const float& x, const float& y, const std::uint32_t& attack); | ||
virtual ~Particle(); | ||
|
||
virtual const bool getExploded() const; | ||
virtual const uint32_t getAttack() const; | ||
virtual const sf::FloatRect getGlobalBounds() const; | ||
|
||
void update(const float& dt); | ||
void draw(sf::RenderTarget& target); | ||
private: | ||
sf::Sprite sprite; | ||
sf::Texture texture; | ||
sf::VideoMode vm; | ||
std::string name; | ||
|
||
uint32_t attack; | ||
|
||
float animationCooldown; | ||
uint32_t frame; | ||
|
||
bool exploded; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "stdafx.h" | ||
#include "Functions.h" | ||
#include "ParticleSystem.h" | ||
|
||
ParticleSystem::ParticleSystem(const sf::VideoMode& vm) | ||
:vm(vm) | ||
{ | ||
} | ||
|
||
ParticleSystem::~ParticleSystem() | ||
{ | ||
} | ||
|
||
void ParticleSystem::addParticle(const std::string& name, const float& x, const float& y, const std::uint32_t& attack) | ||
{ | ||
this->particles.emplace_back(new Particle(this->vm, name, x, y, attack)); | ||
} | ||
|
||
void ParticleSystem::update(MonsterSystem* monsterSystem, FloatingTextSystem* floatingTextSystem, const float& dt) | ||
{ | ||
for (const auto& particle : this->particles) { | ||
particle->update(dt); | ||
if (particle->getExploded()) monsterSystem->explosionAttack(&(*particle), floatingTextSystem); | ||
} | ||
|
||
for (auto particle = this->particles.begin(); particle != this->particles.end();) { | ||
if ((*particle)->getExploded()) { | ||
|
||
particle = this->particles.erase(particle); | ||
} | ||
else ++particle; | ||
} | ||
} | ||
|
||
void ParticleSystem::draw(sf::RenderTarget& target) | ||
{ | ||
for (const auto& particle : this->particles) { | ||
particle->draw(target); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef PARTICLESYSTEM_H | ||
#define PARTICLESYSTEM_H | ||
|
||
#include "Particle.h" | ||
#include "MonsterSystem.h" | ||
#include "FloatingTextSystem.h" | ||
#include "SoundEngine.h" | ||
|
||
class Particle; | ||
class MonsterSystem; | ||
class FloatingTextSystem; | ||
class SoundEngine; | ||
|
||
class ParticleSystem | ||
{ | ||
public: | ||
ParticleSystem(const sf::VideoMode& vm); | ||
virtual ~ParticleSystem(); | ||
|
||
void addParticle(const std::string& name, const float& x, const float& y, const std::uint32_t& attack); | ||
|
||
void update(MonsterSystem* monsterSystem, FloatingTextSystem* floatingTextSystem, const float& dt); | ||
void draw(sf::RenderTarget& target); | ||
private: | ||
std::list<std::unique_ptr<Particle>> particles; | ||
sf::VideoMode vm; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.