Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Piterson25 committed Dec 2, 2022
1 parent 839607c commit 389d651
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Defnight/Defnight.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
<ClCompile Include="Monster.cpp" />
<ClCompile Include="MonsterSystem.cpp" />
<ClCompile Include="MusicEngine.cpp" />
<ClCompile Include="Particle.cpp" />
<ClCompile Include="ParticleSystem.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="PlayerGUI.cpp" />
<ClCompile Include="Projectile.cpp" />
Expand Down Expand Up @@ -192,6 +194,8 @@
<ClInclude Include="Monster.h" />
<ClInclude Include="MonsterSystem.h" />
<ClInclude Include="MusicEngine.h" />
<ClInclude Include="Particle.h" />
<ClInclude Include="ParticleSystem.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="PlayerGUI.h" />
<ClInclude Include="Projectile.h" />
Expand Down
15 changes: 15 additions & 0 deletions Defnight/Defnight.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<Filter Include="Audio">
<UniqueIdentifier>{69ca86f2-c4fb-495b-92c5-15b3fd980e54}</UniqueIdentifier>
</Filter>
<Filter Include="Particles">
<UniqueIdentifier>{4bf78e1f-4197-4ee0-a264-863b90234515}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Drop.cpp">
Expand Down Expand Up @@ -113,6 +116,12 @@
<ClCompile Include="MonsterSystem.cpp">
<Filter>Entities</Filter>
</ClCompile>
<ClCompile Include="Particle.cpp">
<Filter>Particles</Filter>
</ClCompile>
<ClCompile Include="ParticleSystem.cpp">
<Filter>Particles</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Drop.h">
Expand Down Expand Up @@ -193,5 +202,11 @@
<ClInclude Include="MonsterSystem.h">
<Filter>Entities</Filter>
</ClInclude>
<ClInclude Include="Particle.h">
<Filter>Particles</Filter>
</ClInclude>
<ClInclude Include="ParticleSystem.h">
<Filter>Particles</Filter>
</ClInclude>
</ItemGroup>
</Project>
8 changes: 7 additions & 1 deletion Defnight/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ GameState::GameState(const float& gridSize, sf::RenderWindow* window, GameSettin
}

this->projectileSystem = new ProjectileSystem(vm);
this->particleSystem = new ParticleSystem(vm);

this->wave = 0;
this->sumHP = 15;
Expand All @@ -132,6 +133,7 @@ GameState::~GameState()
delete this->floatingTextSystem;
delete this->dropSystem;
delete this->tileMap;
delete this->particleSystem;
}

void GameState::initGUI()
Expand Down Expand Up @@ -164,6 +166,8 @@ void GameState::draw(sf::RenderTarget* target)

this->monsterSystem->draw(*target);

this->particleSystem->draw(*target);

this->floatingTextSystem->draw(*target);

target->setView(this->viewHUD);
Expand Down Expand Up @@ -329,7 +333,7 @@ void GameState::update(const float& dt)
this->playerGUI->updating_XP(dt);
this->playerGUI->updating_HP(this->soundEngine, dt);

this->projectileSystem->update(this->player, this->playerGUI, this->monsterSystem, this->background, this->tileMap, this->floatingTextSystem, dt);
this->projectileSystem->update(this->player, this->playerGUI, this->particleSystem, this->monsterSystem, this->background, this->tileMap, this->floatingTextSystem, this->soundEngine, dt);

this->dropSystem->update(this->player, this->playerGUI, this->floatingTextSystem, this->soundEngine, dt);

Expand All @@ -345,6 +349,8 @@ void GameState::update(const float& dt)

this->playerGUI->update(this->mousePosView, this->waveCountdown, this->monsterSystem, dt);

this->particleSystem->update(this->monsterSystem, this->floatingTextSystem, dt);

this->floatingTextSystem->update(dt);

this->updateMouseClick();
Expand Down
2 changes: 2 additions & 0 deletions Defnight/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "FloatingTextSystem.h"
#include "DropSystem.h"
#include "TileMap.h"
#include "ParticleSystem.h"

class GameState :
public State
Expand Down Expand Up @@ -47,6 +48,7 @@ class GameState :
sf::Texture tiles_texture;
sf::VertexArray vertexArray;
TileMap* tileMap;
ParticleSystem* particleSystem;

uint32_t wave;
uint32_t sumHP;
Expand Down
16 changes: 16 additions & 0 deletions Defnight/MonsterSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ void MonsterSystem::playerAttack(Player* player, FloatingTextSystem* floatingTex
}
}

void MonsterSystem::explosionAttack(Particle* particle, FloatingTextSystem* floatingTextSystem)
{
for (const auto& monster : monsters) {
if (monster->getGlobalBounds().intersects(particle->getGlobalBounds())) {
if (!monster->isDead() && !monster->getPunched() && monster->getSpawned()) {
const int attack = particle->getAttack();
floatingTextSystem->addFloatingText(std::to_string(-attack), calcChar(16, vm), monster->getPosition().x + calcX(32, vm), monster->getPosition().y + calcY(32, vm), sf::Color(255, 255, 255), false);
if (static_cast<int>(monster->getHP() - attack) < 0) monster->setHP(0);
else monster->setHP(monster->getHP() - attack);

monster->punch();
}
}
}
}

void MonsterSystem::projectileCollision(Projectile* proj, Player* player, FloatingTextSystem* floatingTextSystem)
{
for (const auto& monster : monsters) {
Expand Down
3 changes: 3 additions & 0 deletions Defnight/MonsterSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "TileMap.h"
#include "SoundEngine.h"
#include "DropSystem.h"
#include "Particle.h"
#include "ProjectileSystem.h"
#include "Projectile.h"
#include "FloatingTextSystem.h"
Expand All @@ -17,6 +18,7 @@ class PlayerGUI;
class TileMap;
class SoundEngine;
class DropSystem;
class Particle;
class ProjectileSystem;
class Projectile;
class FloatingTextSystem;
Expand All @@ -39,6 +41,7 @@ class MonsterSystem
const float& x, const float& y, const float& wave_mod);

void playerAttack(Player* player, FloatingTextSystem* floatingTextSystem, SoundEngine* soundEngine, bool& playedSound);
void explosionAttack(Particle* particle, FloatingTextSystem* floatingTextSystem);

void projectileCollision(Projectile* proj, Player* player, FloatingTextSystem* floatingTextSystem);

Expand Down
62 changes: 62 additions & 0 deletions Defnight/Particle.cpp
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);
}
38 changes: 38 additions & 0 deletions Defnight/Particle.h
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
40 changes: 40 additions & 0 deletions Defnight/ParticleSystem.cpp
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);
}
}
29 changes: 29 additions & 0 deletions Defnight/ParticleSystem.h
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
19 changes: 18 additions & 1 deletion Defnight/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ const bool Projectile::getCollidedMonster() const
return this->collidedMonster;
}

const float Projectile::getTimeExisting() const
{
return this->timeExisting;
}

const bool Projectile::getExploded() const
{
if (this->name == "bomb") return this->timeExisting >= 3.f;
return false;
}

const bool Projectile::isBomb() const
{
return this->name == "bomb";
}

void Projectile::calculateVelocity(const sf::Vector2f& coords)
{
this->angle = getAngle(this->sprite.getPosition().x, this->sprite.getPosition().y, coords.x, coords.y) + 90.f;
Expand Down Expand Up @@ -320,7 +336,7 @@ void Projectile::monsterCollision(Monster* monster, Player* player, FloatingText

}

if (this->collidedMonster) {
if (this->collidedMonster && this->name != "bomb") {
if ((static_cast<uint32_t>(Random::Float() * 100.f) + 1) <= player->getCriticalChance()) {
const int attack = 2 * this->attack;
floatingTextSystem->addFloatingText(std::to_string(-attack), calcChar(16, vm), monster->getPosition().x + calcX(32, vm), monster->getPosition().y + calcY(32, vm), sf::Color(233, 134, 39), false);
Expand Down Expand Up @@ -353,6 +369,7 @@ void Projectile::move(const float& dt)

void Projectile::update(const float& dt)
{
this->timeExisting += dt;
if (this->name == "shuriken") this->sprite.rotate(90.f / dt);
this->move(dt);
}
Expand Down
4 changes: 4 additions & 0 deletions Defnight/Projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Projectile
virtual const bool getCollided() const;
virtual const bool getCollidedPlayer() const;
virtual const bool getCollidedMonster() const;
virtual const float getTimeExisting() const;
virtual const bool getExploded() const;
virtual const bool isBomb() const;

void calculateVelocity(const sf::Vector2f& coords);

Expand All @@ -35,6 +38,7 @@ class Projectile
void update(const float& dt);
void draw(sf::RenderTarget& target);
private:
float timeExisting;
bool collided;
bool collidedPlayer;
bool collidedMonster;
Expand Down
Loading

0 comments on commit 389d651

Please sign in to comment.