1 // $Id$
2
3 // Fish Supper
4 // Copyright 2006, 2007, 2009, 2010 Matthew Clarke <mafferyew@googlemail.com>
5 //
6 // This file is part of Fish Supper.
7 //
8 // Fish Supper is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // Fish Supper is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Fish Supper. If not, see <http://www.gnu.org/licenses/>.
20
21
22
23
24 #include "Star_particle_system.h"
25
26
27
28
29 // *******************
30 // *** CONSTRUCTOR ***
31 // *******************
Star_particle_system()32 FS::Star_particle_system::Star_particle_system()
33 {
34 active = false;
35
36 } // FS::Star_particle_system::Star_particle_system
37
38 // ******************
39 // *** DESTRUCTOR ***
40 // ******************
~Star_particle_system()41 FS::Star_particle_system::~Star_particle_system()
42 {
43 // NYI
44
45 } // FS::Star_particle_system::~Star_particle_system
46
47
48
49
50 // ************************
51 // *** MEMBER FUNCTIONS ***
52 // ************************
53
54 // **************************************************
55
update(int time_passed,SDL_Rect box)56 void FS::Star_particle_system::update(int time_passed, SDL_Rect box)
57 {
58 // Check if we need to launch a new star particle.
59 if ( (!stopped) && (num_stars < MAX_STARS) &&
60 ((time_passed - start_time) > LAUNCH_INTERVAL) )
61 {
62 launch_new_star(time_passed, box);
63 start_time = time_passed + ((time_passed - start_time) % LAUNCH_INTERVAL);
64 } // if
65
66 // Update existing star particles.
67 bool still_alive = false;
68
69 for (int i = 0; i < MAX_STARS; ++i)
70 {
71 if ( my_stars[i].active )
72 {
73 int age = time_passed - my_stars[i].start_time;
74 if ( age < lifespan )
75 {
76 gfx_ptr->draw_texture( FS_gfx::STAR, my_stars[i].x, my_stars[i].y,
77 false, 0.0, true, (1.0 - (age / lifespan)) );
78 still_alive = true;
79 }
80 else
81 {
82 my_stars[i].active = false;
83 } // if ... else
84 } // if
85 } // for
86
87 if ( !still_alive )
88 {
89 active = false;
90 } // if
91
92 } // FS::Star_particle_system::update
93
94 // **************************************************
95
activate(int t,SDL_Rect box)96 void FS::Star_particle_system::activate(int t, SDL_Rect box)
97 {
98 active = true;
99 stopped = false;
100 start_time = t;
101 num_stars = 0;
102
103 for (int i = 0; i < MAX_STARS; ++i)
104 {
105 my_stars[i].active = false;
106 } // for
107
108 // launch a new star straight away
109 launch_new_star(t, box);
110
111 } // FS::Star_particle_system::activate
112
113 // **************************************************
114
stop(int t)115 void FS::Star_particle_system::stop(int t)
116 {
117 stopped = true;
118
119 } // FS::Star_particle_system::stop
120
121 // **************************************************
122
launch_new_star(int t,SDL_Rect box)123 void FS::Star_particle_system::launch_new_star(int t, SDL_Rect box)
124 {
125 box.x -= STAR_WIDTH;
126 box.w += STAR_WIDTH;
127 box.y -= STAR_HEIGHT;
128 box.h += STAR_HEIGHT;
129
130 my_stars[num_stars].active = true;
131 my_stars[num_stars].x = box.x + (rand() % box.w);
132 my_stars[num_stars].y = box.y + (rand() % box.h);
133 my_stars[num_stars].start_time = t;
134
135 ++num_stars;
136
137 } // FS::Star_particle_system::launch_new_star
138
139 // **************************************************
140 // **************************************************
141 // **************************************************
142 // **************************************************
143 // **************************************************
144