Skip to content

Commit

Permalink
Added particle effects
Browse files Browse the repository at this point in the history
  • Loading branch information
SaronTetra committed Jun 14, 2018
1 parent 191e03a commit 721d6ff
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 14 deletions.
Binary file added PUTBRCK/PUTBRCK.rc
Binary file not shown.
18 changes: 16 additions & 2 deletions PUTBRCK/PUTBRCK.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Link>
<AdditionalLibraryDirectories>$(SolutionDir)SFML-2.4.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-main-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;opengl32.lib;openal32.lib;freetype.lib;jpeg.lib;winmm.lib;sfml-network-d.lib;ws2_32.lib;sfml-audio-d.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -96,6 +97,7 @@
<Link>
<AdditionalLibraryDirectories>$(SolutionDir)SFML-2.4.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-main-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;opengl32.lib;openal32.lib;freetype.lib;jpeg.lib;winmm.lib;sfml-network-d.lib;ws2_32.lib;sfml-audio-d.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -113,7 +115,8 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(SolutionDir)SFML-2.4.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;freetype.lib;jpeg.lib;gdi32.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sfml-main.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;freetype.lib;jpeg.lib;gdi32.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -131,7 +134,8 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(SolutionDir)SFML-2.4.2\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;freetype.lib;jpeg.lib;gdi32.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>sfml-main.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;freetype.lib;jpeg.lib;gdi32.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -151,6 +155,7 @@
<ClCompile Include="menu.cpp" />
<ClCompile Include="myrandom.cpp" />
<ClCompile Include="paddle.cpp" />
<ClCompile Include="particles.cpp" />
<ClCompile Include="quadtree.cpp" />
<ClCompile Include="resources.cpp" />
</ItemGroup>
Expand All @@ -167,10 +172,19 @@
<ClInclude Include="menu.h" />
<ClInclude Include="myrandom.h" />
<ClInclude Include="paddle.h" />
<ClInclude Include="particles.h" />
<ClInclude Include="quadtree.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="resources.h" />
<ClInclude Include="screens.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PUTBRCK.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="assets\PUTBRCK.ico" />
<Image Include="icon1.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
22 changes: 22 additions & 0 deletions PUTBRCK/PUTBRCK.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClCompile Include="menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="particles.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ball.h">
Expand Down Expand Up @@ -116,5 +119,24 @@
<ClInclude Include="menu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="particles.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PUTBRCK.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon1.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="assets\PUTBRCK.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
Binary file added PUTBRCK/assets/PUTBRCK.ico
Binary file not shown.
Binary file modified PUTBRCK/assets/sfx/PM_SA_CINEMATIC_IMPACT_21.ogg
Binary file not shown.
Binary file modified PUTBRCK/assets/sfx/PM_SA_IMPACT_33.ogg
Binary file not shown.
Binary file modified PUTBRCK/assets/textures/design.afdesign
Binary file not shown.
Binary file added PUTBRCK/assets/textures/particle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion PUTBRCK/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int editor::Run() {
//GUI
//==========================================================================
ImGui::SFML::Update(App, elapsed_);
ImGui::ShowDemoWindow();
//ImGui::ShowDemoWindow();
ImGui::SetNextWindowPos({ PLAYAREA_X + PLAYAREA_WIDTH, 0 });
ImGui::SetNextWindowSize({ App.getSize().x - PLAYAREA_X - PLAYAREA_WIDTH + 0.f, App.getSize().y + 0.f });
ImGui::Begin("editor");
Expand Down
47 changes: 36 additions & 11 deletions PUTBRCK/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ int game::Run() {
case sf::Keyboard::R:
restart();
break;
case sf::Keyboard::B:
particles_.emplace_back(particles(App, tx["point"], 100, sf::Color(255,0,255)));
particles_.back().spawn(500, 500);
break;
case sf::Keyboard::Z:
points[currentPoint].setSpeed(0, 500);
points[currentPoint].sprite().rotate(randomInt(0, 360));
points[currentPoint].move(pad->x(), pad->y() - 100);
currentPoint++;
if (currentPoint >= 25) {
currentPoint = 0;
}
break;
default:
break;
}
Expand Down Expand Up @@ -256,22 +269,26 @@ int game::Run() {
temp.setSize({ 1, laser.getLocalBounds().height });
App.draw(temp);
}
else if(time < 2000 && laserScale > 0) {
else if (laserScale > 0) {
if (!laserPlayed) {
for (auto& e : bricks) {
if (e.x1() < pad->x() + laser.getLocalBounds().width/2 && e.x2() > pad->x()-laser.getLocalBounds().width / 2) {
if (e.x1() < pad->x() + laser.getLocalBounds().width / 2 && e.x2() > pad->x() - laser.getLocalBounds().width / 2) {
particles_.emplace_back(particles(App, tx["point"], 50, e.sprite().getColor()));
particles_.back().spawn(e.x(), e.y());
e.toDelete = true;
}
}
audio.play("laser");
laserPlayed = true;
}
laser.setPosition(pad->x(), PLAYAREA_Y);
laser.setScale({ laserScale, 0.95f });
laser.setColor(sf::Color(255-laserScale*1, 100 - laserScale * 1, 0));
laserScale -= 0.05;
std::cout << laser.getScale().x << std::endl;
App.draw(laser);
}
laserScale -= 0.01;
if (laserScale > 0.01) {
laser.setPosition(pad->x(), PLAYAREA_Y);
laser.setScale({ laserScale, 0.95f });
laser.setColor(sf::Color(255, 100, 0, 255 - cooldownClock.getElapsedTime().asSeconds() * 50));
std::cout << 255 - cooldownClock.getElapsedTime().asSeconds() * 100 << std::endl;
App.draw(laser);
}
}
else {
cannonFire = false;
Expand Down Expand Up @@ -321,14 +338,22 @@ int game::Run() {
App.draw(e.sprite());
}


for(auto& e:particles_) {
e.move(elapsed_);
for (auto& f : e.getVector())
App.draw(f.sp_part);
}

for (auto &e : bricks) {
for (auto &f : balls) {
float tempX = e.sprite().getPosition().x;
float tempY = e.sprite().getPosition().y;
collision direction = checkCollision(f, &e);
f.bounce(direction);
f.bounce(direction);
if(direction != collision::none) {
App.draw(e.sprite());
particles_.emplace_back(particles(App, tx["point"], 25, e.sprite().getColor()));
particles_.back().spawn(tempX, tempY);
points[currentPoint].setSpeed(0, 500);
points[currentPoint].sprite().rotate(randomInt(0,360));
points[currentPoint].move(f.x(), f.y());
Expand Down
2 changes: 2 additions & 0 deletions PUTBRCK/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "bonus.h"
#include "quadtree.h"
#include "level.h"
#include "particles.h"


#define M_PI 3.14159265358979323846
Expand Down Expand Up @@ -45,6 +46,7 @@ class game : public cScreen {
std::vector<ball> points;
std::vector<brick> bricks;
std::vector<bonus> bonuses;
std::vector<particles> particles_;
paddle * pad;
sf::CircleShape point;

Expand Down
Binary file added PUTBRCK/icon1.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions PUTBRCK/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ int menu::Run() {
e.setFillColor(sf::Color(244, 59, 154));
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if(e.getString() == "Start") {
thisGame->resume();
return 0;
}
if(e.getString() == "Editor") {
Expand All @@ -104,6 +105,7 @@ int menu::Run() {
}
if(e.getString() == "Restart") {
thisGame->restart();
thisGame->resume();
return 0;
}
}
Expand Down
54 changes: 54 additions & 0 deletions PUTBRCK/particles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "particles.h"
#include "myrandom.h"
#include <iostream>


particles::particles(sf::RenderWindow & App, sf::Texture & tx_particle, unsigned int amount, sf::Color color)
: entity(tx_particle, {0,0}), App(App), amount(amount){

for(int i=0; i<amount; ++i) {
sf::Sprite temp;
temp.setTexture(tx_particle);
temp.setPosition(-100, -100);
temp.setColor(color);
temp.rotate(randomInt(0, 360));
particle temp2;
temp2.sp_part = temp;
particles_.push_back(temp2);
}
speed = 100;
lifeTime = sf::seconds(1);
alpha = 255;

}

particles::~particles() {
particles_.clear();
}

void particles::spawn(int x, int y) {
for(auto& e:particles_) {
e.sp_part.setPosition(x, y);
e.velX = 0.125 * randomInt(-8,8);
e.velY = 0.125 * randomInt(-8,8);
}
}

void particles::move(sf::Time dT) {
lifeTime -= dT;
if(lifeTime.asMilliseconds() < 0) {
particles_.clear();
}
alpha -= 10;
if (alpha <= 0) { alpha = 10; }
for (auto& e : particles_) {
float x = e.sp_part.getPosition().x;
float y = e.sp_part.getPosition().y;

e.sp_part.setPosition(x + e.velX * dT.asSeconds() * speed, y + e.velY * dT.asSeconds() * speed);
int r = e.sp_part.getColor().r;
int g = e.sp_part.getColor().g;
int b = e.sp_part.getColor().b;
e.sp_part.setColor(sf::Color(r, g, b, alpha + randomInt(0, 10)));
}
}
24 changes: 24 additions & 0 deletions PUTBRCK/particles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include "entity.h"

struct particle {
sf::Sprite sp_part;
float velX = 0;
float velY = 0;
};

class particles : public entity{
sf::RenderWindow& App;
std::vector<particle> particles_;
unsigned int amount;
int speed;
sf::Time lifeTime;
int alpha;
public:
particles(sf::RenderWindow &App, sf::Texture& tx_particle, unsigned int amount, sf::Color color);
~particles();
void spawn(int x, int y);
void move(sf::Time dT);
std::vector<particle> getVector() { return particles_; }
};

16 changes: 16 additions & 0 deletions PUTBRCK/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by PUTBRCK.rc
//
#define IDI_ICON1 102

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
1 change: 1 addition & 0 deletions PUTBRCK/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void TextureContainer::init() {
tx.loadTexture("assets/textures/ball_bonus.png", "bonusBall");
tx.loadTexture("assets/textures/point.png", "point");
tx.loadTexture("assets/textures/laser.png", "laser");
tx.loadTexture("assets/textures/particle.png", "particle");

music["bg1_A"].openFromFile("assets/music/PM_ATG_2_100BPM_A.ogg");
music["bg1_B"].openFromFile("assets/music/PM_ATG_2_100BPM_B.ogg");
Expand Down

0 comments on commit 721d6ff

Please sign in to comment.