Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////
- ///// main.cpp ///////
- ///////////////////////////////////////////////////////
- #include <SFML/Graphics.hpp>
- #include "Player.h"
- int main(){
- sf::RenderWindow Wnd(sf::VideoMode(800,600,32), "Particle Test");
- Player player;
- while(Wnd.isOpen()){
- sf::Event e;
- while(Wnd.pollEvent(e)){
- if(e.type == sf::Event::Closed){
- Wnd.close();
- }
- }
- player.update();
- Wnd.clear();
- player.draw(Wnd);
- Wnd.display();
- }
- return 0;
- }
- ///////////////////////////////////////////////////////
- ///// player.h ///////
- ///////////////////////////////////////////////////////
- #pragma once
- #include <SFML\Graphics.hpp>
- #include "Particle.h"
- class Player
- {
- public:
- Player();
- ~Player(void);
- sf::Texture texture;
- sf::Sprite sprite;
- void update();
- void draw(sf::RenderWindow& w);
- Particle particle;
- };
- ///////////////////////////////////////////////////////
- ///// player.cpp ///////
- //////////////////////////////////////////////////////
- #include "Player.h"
- Player::Player()
- {
- texture.loadFromFile("player2.png");
- sprite.setTextureRect(sf::IntRect(0,0,30,45));
- sprite.setTexture(texture);
- sprite.setPosition(200,200);
- }
- Player::~Player(void)
- {
- }
- void Player::update()
- {
- /* ... */
- particle.update();
- }
- void Player::draw(sf::RenderWindow& w)
- {
- particle.draw(w);
- w.draw(sprite);
- }
- ///////////////////////////////////////////////////////
- ///// particle.h ///////
- //////////////////////////////////////////////////////
- #pragma once
- #include <Thor/Particles.hpp>
- #include <Thor/Animation.hpp>
- #include <SFML/Graphics.hpp>
- class Particle
- {
- public:
- Particle(void);
- ~Particle(void);
- private:
- std::shared_ptr<sf::Texture> texture;
- thor::ParticleSystem System;
- thor::UniversalEmitter::Ptr Emitter;
- thor::FadeAnimation fader;
- sf::Clock clock;
- public:
- void update();
- void draw(sf::RenderWindow& w);
- };
- ///////////////////////////////////////////////////////
- ///// particle.cpp ///////
- //////////////////////////////////////////////////////
- #include "Particle.h"
- Particle::Particle(): Emitter(thor::UniversalEmitter::create()),
- texture(new sf::Texture),
- System(texture),
- fader(0.1f,0.1f)
- {
- System.addEmitter(Emitter);
- Emitter->setParticlePosition(sf::Vector2f(100,100));
- texture->loadFromFile("particle.png");
- }
- Particle::~Particle(void)
- {
- }
- void Particle::update()
- {
- System.update(clock.restart());
- }
- void Particle::draw(sf::RenderWindow& w)
- {
- w.draw(System);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement