20130313
[gdash.git] / src / cave / particle.hpp
blob63571ca125f7ca1205e9b511f04c62367fc85134
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef PARTICLE_HPP
18 #define PARTICLE_HPP
20 #include "config.h"
22 #include <vector>
23 #include "cave/helper/colors.hpp"
25 class ParticleSet {
26 public:
27 /// One single particle.
28 struct Particle {
29 float px, py; ///< Coordinate
30 float vx, vy; ///< Speed
33 /// This constructor creates a particle set, for the given cave coordinates.
34 /// 0,0 is the top left corner of the cave; 1,1 is the bottom right corner of
35 /// the top left cave cell. (So the max coordinates are the width and height
36 /// of the cave.)
37 /// @param cave_x Particle set starting x coordinate in cave coordinates.
38 /// @param cave_y Particle set starting y coordinate in cave coordinates.
39 /// @param dx Half the width of the region, in which originally particles are randomly generated.
40 /// @param dy Half the height of the region, in which originally particles are randomly generated.
41 /// @param vx Maximum original speed.
42 /// @param vy Maximum original speed.
43 ParticleSet(int count, float size, float opacity, float p0x, float p0y, float dp0x, float dp0y, float v0x, float v0y, float dvx, float dvy, const GdColor &color);
44 /// Move the particles.
45 /// @param dt_ms Time elapsed.
46 void move(int dt_ms);
47 /// Start using screen cordinates, if is_new is true.
48 void normalize(double factor);
50 typedef std::vector<Particle>::iterator iterator;
51 typedef std::vector<Particle>::const_iterator const_iterator;
53 iterator begin() { return particles.begin(); }
54 iterator end() { return particles.end(); }
55 const_iterator begin() const { return particles.begin(); }
56 const_iterator end() const { return particles.end(); }
58 GdColor color;
59 int life; ///< lifetime. starts from 1000, goes to 0.
60 bool is_new; ///< New particle set, the coordinates of which must be "normalized" to the cave screen coordinates
61 float size; ///< Size of the particles.
62 float opacity; ///< Opacity between 0 and 1. Values close to 1 not recommended.
64 private:
65 std::vector<Particle> particles;
68 #endif