SHOW:
|
|
- or go back to the newest paste.
1 | /////////////////////////////////////////////////////// | |
2 | - | ///// main.cpp /////// |
2 | + | ///// main.cpp /////// |
3 | /////////////////////////////////////////////////////// | |
4 | #include <SFML/Graphics.hpp> | |
5 | #include "Player.h" | |
6 | int main(){ | |
7 | sf::RenderWindow Wnd(sf::VideoMode(800,600,32), "Particle Test"); | |
8 | ||
9 | Player player; | |
10 | while(Wnd.isOpen()){ | |
11 | sf::Event e; | |
12 | while(Wnd.pollEvent(e)){ | |
13 | if(e.type == sf::Event::Closed){ | |
14 | Wnd.close(); | |
15 | } | |
16 | } | |
17 | ||
18 | player.update(); | |
19 | Wnd.clear(); | |
20 | player.draw(Wnd); | |
21 | Wnd.display(); | |
22 | } | |
23 | return 0; | |
24 | } | |
25 | ||
26 | /////////////////////////////////////////////////////// | |
27 | - | ///// player.h /////// |
27 | + | ///// player.h /////// |
28 | /////////////////////////////////////////////////////// | |
29 | #pragma once | |
30 | #include <SFML\Graphics.hpp> | |
31 | #include "Particle.h" | |
32 | class Player | |
33 | { | |
34 | public: | |
35 | Player(); | |
36 | ~Player(void); | |
37 | sf::Texture texture; | |
38 | sf::Sprite sprite; | |
39 | void update(); | |
40 | void draw(sf::RenderWindow& w); | |
41 | Particle particle; | |
42 | ||
43 | }; | |
44 | ||
45 | /////////////////////////////////////////////////////// | |
46 | - | ///// player.cpp /////// |
46 | + | ///// player.cpp /////// |
47 | ////////////////////////////////////////////////////// | |
48 | #include "Player.h" | |
49 | Player::Player() | |
50 | { | |
51 | texture.loadFromFile("player2.png"); | |
52 | sprite.setTextureRect(sf::IntRect(0,0,30,45)); | |
53 | sprite.setTexture(texture); | |
54 | sprite.setPosition(200,200); | |
55 | ||
56 | } | |
57 | ||
58 | Player::~Player(void) | |
59 | { | |
60 | } | |
61 | ||
62 | void Player::update() | |
63 | { | |
64 | /* ... */ | |
65 | particle.update(); | |
66 | } | |
67 | ||
68 | void Player::draw(sf::RenderWindow& w) | |
69 | { | |
70 | particle.draw(w); | |
71 | w.draw(sprite); | |
72 | } | |
73 | ||
74 | /////////////////////////////////////////////////////// | |
75 | - | ///// particle.h /////// |
75 | + | ///// particle.h /////// |
76 | ////////////////////////////////////////////////////// | |
77 | #pragma once | |
78 | #include <Thor/Particles.hpp> | |
79 | #include <Thor/Animation.hpp> | |
80 | #include <SFML/Graphics.hpp> | |
81 | class Particle | |
82 | { | |
83 | public: | |
84 | Particle(void); | |
85 | ~Particle(void); | |
86 | private: | |
87 | std::shared_ptr<sf::Texture> texture; | |
88 | thor::ParticleSystem System; | |
89 | thor::UniversalEmitter::Ptr Emitter; | |
90 | thor::FadeAnimation fader; | |
91 | sf::Clock clock; | |
92 | public: | |
93 | void update(); | |
94 | void draw(sf::RenderWindow& w); | |
95 | }; | |
96 | ||
97 | ||
98 | /////////////////////////////////////////////////////// | |
99 | - | ///// particle.cpp /////// |
99 | + | ///// particle.cpp /////// |
100 | ////////////////////////////////////////////////////// | |
101 | #include "Particle.h" | |
102 | Particle::Particle(): Emitter(thor::UniversalEmitter::create()), | |
103 | texture(new sf::Texture), | |
104 | System(texture), | |
105 | fader(0.1f,0.1f) | |
106 | { | |
107 | System.addEmitter(Emitter); | |
108 | Emitter->setParticlePosition(sf::Vector2f(100,100)); | |
109 | texture->loadFromFile("particle.png"); | |
110 | } | |
111 | ||
112 | Particle::~Particle(void) | |
113 | { | |
114 | } | |
115 | ||
116 | void Particle::update() | |
117 | { | |
118 | System.update(clock.restart()); | |
119 | } | |
120 | ||
121 | void Particle::draw(sf::RenderWindow& w) | |
122 | { | |
123 | w.draw(System); | |
124 | } |