~ubuntu-branches/ubuntu/natty/smc/natty

« back to all changes in this revision

Viewing changes to src/level/global_effect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Muammar El Khatib
  • Date: 2008-10-20 00:31:35 UTC
  • mfrom: (1.1.4 upstream) (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081020003135-5ac8cpecomfohvv5
Tags: 1.6-1
* New upstream release. (Closes:#479415)
* Bumped standards version to 3.8.0.
* debian/control: dpatch build dependency has been removed temporarily.
* debian/control: smc-data does not depend on smc anymore. This change will
  avoid a circular dependency. (Closes: #478712)
* smc does not segfault. (Closes: #500039, #491590) 
* Icon is not missed in Gnome Menu. Thanks to Saïvann for providing a 
  solution. (Closes: #491885)
* debian/control: smc-data's and smc-music's descriptions have been improved.
  (Closes: #493630)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
    global_effect.cpp  -  class for handling level global effects
3
 
                             -------------------
4
 
    copyright            : (C) 2006 - 2007 by Florian Richter
 
2
 * global_effect.cpp  -  class for handling level global effects
 
3
 *
 
4
 * Copyright (C) 2006 - 2008 Florian Richter
5
5
 ***************************************************************************/
6
6
/*
7
7
   This program is free software; you can redistribute it and/or modify
23
23
/* *** *** *** *** *** cGlobal_effect *** *** *** *** *** *** *** *** *** *** *** *** */
24
24
 
25
25
cGlobal_effect :: cGlobal_effect( void )
26
 
: cParticleAnimation()
 
26
: cParticle_Emitter()
27
27
{
28
 
        Init_default();
 
28
        Clear();
29
29
}
30
30
 
31
 
cGlobal_effect :: cGlobal_effect( XMLAttributes &attributes )
32
 
: cParticleAnimation()
 
31
cGlobal_effect :: cGlobal_effect( CEGUI::XMLAttributes &attributes )
 
32
: cParticle_Emitter()
33
33
{
34
 
        Init_default();
 
34
        Clear();
35
35
        Create_from_Stream( attributes );
36
36
}
37
37
 
40
40
 
41
41
}
42
42
 
43
 
void cGlobal_effect :: Init_default( void )
44
 
{
45
 
        Clear();
46
 
}
47
 
 
48
 
void cGlobal_effect :: Init( void )
 
43
void cGlobal_effect :: Init_Anim( void )
49
44
{
50
45
        if( ge_type == GL_EFF_NONE )
51
46
        {
52
47
                return;
53
48
        }
54
49
 
55
 
        if( ge_type == GL_EFF_FALLING || ge_type == GL_EFF_FLYING )
 
50
        if( ge_type == GL_EFF_FALLING )
56
51
        {
57
 
                // if the image doesn't exists
 
52
                // image doesn't exist
58
53
                if( !pVideo->Get_Surface( image_filename ) )
59
54
                {
60
55
                        valid = 0;
61
56
                }
62
 
                // image exists valid effect
 
57
                // image exists
63
58
                else
64
59
                {
65
60
                        image = pVideo->Get_Surface( image_filename );
 
61
                        // valid effect
66
62
                        valid = 1;
67
63
                }
68
64
        }
73
69
                float old_speedfactor = pFramerate->speedfactor;
74
70
                pFramerate->speedfactor = 1;
75
71
                // use time to live as seconds
76
 
                for( float i = 0; i < DESIRED_FPS * time_to_live; i++ )
 
72
                for( float i = 0; i < speedfactor_fps * time_to_live; i++ )
77
73
                {
78
74
                        Update();
79
 
                        Update_anim();
80
75
                }
81
76
 
82
77
                pFramerate->speedfactor = old_speedfactor;
85
80
 
86
81
void cGlobal_effect :: Clear( void )
87
82
{
88
 
        cParticleAnimation::Clear();
 
83
        cParticle_Emitter::Clear();
89
84
 
90
85
        ge_type = GL_EFF_NONE;
91
86
 
92
87
        image_filename.clear();
93
88
        image = NULL;
94
 
        Set_Emitter_Rect( GL_rect( 0, 0, GAME_RES_W, 0 ) );
 
89
        Set_Emitter_Rect( 0, 0, static_cast<float>(game_res_w), 0 );
95
90
        Set_Emitter_Time_to_Live( -1 );
96
 
        Set_Emitter_Iteration_Interval( 1 * 0.3f );
97
 
        Set_ZPos( 0.12f, 0 );
 
91
        Set_Emitter_Iteration_Interval( 0.3f );
 
92
        Set_Pos_Z( 0.12f, 0 );
98
93
        Set_Time_to_Live( 7, 0 );
99
94
        Set_Scale( 0.2f, 0.2f );
100
95
        Set_Speed( 2, 8 );
101
 
        Set_DirectionRange( 0, 90 );
102
 
        Set_ConstRotationZ( 0.5f, 10 );
 
96
        Set_Direction_Range( 0, 90 );
 
97
        Set_Rotation( 0, 0, 0, 1 );
 
98
        Set_Const_Rotation_Z( -5, 10 );
103
99
 
104
100
        valid = 0;
105
101
}
106
102
 
107
 
void cGlobal_effect :: Create_from_Stream( XMLAttributes &attributes )
 
103
void cGlobal_effect :: Create_from_Stream( CEGUI::XMLAttributes &attributes )
108
104
{
109
105
        // Type
110
 
        Set_type( (GlobalEffectType)attributes.getValueAsInteger( "type", GL_EFF_NONE ) );
 
106
        Set_Type( (GlobalEffectType)attributes.getValueAsInteger( "type", ge_type ) );
111
107
        // Image
112
 
        Set_image( attributes.getValueAsString( "image" ).c_str() );
 
108
        Set_Image( attributes.getValueAsString( "image", image_filename ).c_str() );
113
109
        // Creation Rect
114
 
        Set_Emitter_Rect( static_cast<float>(attributes.getValueAsInteger( "rect_x", 0 )), static_cast<float>(attributes.getValueAsInteger( "rect_y", 0 )), static_cast<float>(attributes.getValueAsInteger( "rect_w", GAME_RES_W )), static_cast<float>(attributes.getValueAsInteger( "rect_h", 0 )) );
115
 
        // if start position is 0 change it
116
 
        if( startposx == 0 && startposy == 0 )
117
 
        {
118
 
                Set_Emitter_Rect( startposx, -1, rect.w, rect.h );
119
 
        }
 
110
        Set_Emitter_Rect( static_cast<float>(attributes.getValueAsInteger( "rect_x", static_cast<int>(startposx) )), static_cast<float>(attributes.getValueAsInteger( "rect_y", static_cast<int>(startposy) )), static_cast<float>(attributes.getValueAsInteger( "rect_w", static_cast<int>(rect.w) )), static_cast<float>(attributes.getValueAsInteger( "rect_h", static_cast<int>(rect.h) )) );
120
111
        // Z Position
121
 
        Set_ZPos( attributes.getValueAsFloat( "z", 0.12f ), attributes.getValueAsFloat( "z_rand" ) );
 
112
        Set_Pos_Z( attributes.getValueAsFloat( "z", posz ), attributes.getValueAsFloat( "z_rand", posz_rand ) );
122
113
        // Time to Live
123
114
        if( attributes.exists( "time_to_live" ) )
124
115
        {
125
 
                Set_Time_to_Live( attributes.getValueAsFloat( "time_to_live", 7 ) );
 
116
                Set_Time_to_Live( attributes.getValueAsFloat( "time_to_live", time_to_live ), attributes.getValueAsFloat( "time_to_live_rand", time_to_live_rand ) );
126
117
        }
127
118
        // if not set uses old Lifetime mod
128
119
        else
132
123
        // Emitter Iteration Interval
133
124
        if( attributes.exists( "emitter_iteration_interval" ) )
134
125
        {
135
 
                Set_Emitter_Iteration_Interval( attributes.getValueAsFloat( "emitter_iteration_interval", 1.3f ) );
 
126
                Set_Emitter_Iteration_Interval( attributes.getValueAsFloat( "emitter_iteration_interval", emitter_iteration_interval ) );
136
127
        }
137
128
        // if not set uses old Creation speed ( 0.99.7 and below )
138
129
        else
140
131
                Set_Emitter_Iteration_Interval( ( 1 / attributes.getValueAsFloat( "creation_speed", 0.3f ) ) * 0.032f );
141
132
        }
142
133
        // Scale
143
 
        Set_Scale( attributes.getValueAsFloat( "scale", 0.2f ), attributes.getValueAsFloat( "scale_rand", 0.2f ) );
 
134
        Set_Scale( attributes.getValueAsFloat( "scale", size_scale ), attributes.getValueAsFloat( "scale_rand", size_scale_rand ) );
144
135
        // Speed
145
 
        Set_Speed( attributes.getValueAsFloat( "speed", 2 ), attributes.getValueAsFloat( "speed_rand", 8 ) );
 
136
        Set_Speed( attributes.getValueAsFloat( "speed", vel ), attributes.getValueAsFloat( "speed_rand", vel_rand ) );
146
137
        // Direction
147
 
        Set_DirectionRange( attributes.getValueAsFloat( "dir_range_start", 0 ), attributes.getValueAsFloat( "dir_range_size", 90 ) );
 
138
        Set_Direction_Range( attributes.getValueAsFloat( "dir_range_start", angle_start ), attributes.getValueAsFloat( "dir_range_size", angle_range ) );
 
139
        // start rotation
 
140
        Set_Rotation( attributes.getValueAsFloat( "rot_x", start_rotx ), attributes.getValueAsFloat( "rot_y", start_roty ), attributes.getValueAsFloat( "rot_z", start_rotz ), 1 );
148
141
        // Constant Rotation Z
149
 
        Set_ConstRotationZ( attributes.getValueAsFloat( "const_rotz", 0.5f ), attributes.getValueAsFloat( "const_rotz_rand", 10 ) );
 
142
        Set_Const_Rotation_Z( attributes.getValueAsFloat( "const_rotz", const_rotz ), attributes.getValueAsFloat( "const_rotz_rand", const_rotz_rand ) );
150
143
}
151
144
 
152
145
void cGlobal_effect :: Save_to_Stream( ofstream &file )
180
173
        file << "\t\t<Property name=\"z_rand\" value=\"" << posz_rand << "\" />" << std::endl;
181
174
        // Time to Live
182
175
        file << "\t\t<Property name=\"time_to_live\" value=\"" << time_to_live << "\" />" << std::endl;
 
176
        file << "\t\t<Property name=\"time_to_live_rand\" value=\"" << time_to_live_rand << "\" />" << std::endl;
183
177
        // Emitter Iteration Interval
184
178
        file << "\t\t<Property name=\"emitter_iteration_interval\" value=\"" << emitter_iteration_interval << "\" />" << std::endl;
185
179
        // scale
191
185
        // direction range
192
186
        file << "\t\t<Property name=\"dir_range_start\" value=\"" << angle_start << "\" />" << std::endl;
193
187
        file << "\t\t<Property name=\"dir_range_size\" value=\"" << angle_range << "\" />" << std::endl;
 
188
        // start rotation
 
189
        file << "\t\t<Property name=\"rot_x\" value=\"" << start_rotx << "\" />" << std::endl;
 
190
        file << "\t\t<Property name=\"rot_y\" value=\"" << start_roty << "\" />" << std::endl;
 
191
        file << "\t\t<Property name=\"rot_z\" value=\"" << start_rotz << "\" />" << std::endl;
194
192
        // constant rotation Z
195
193
        file << "\t\t<Property name=\"const_rotz\" value=\"" << const_rotz << "\" />" << std::endl;
196
194
        file << "\t\t<Property name=\"const_rotz_rand\" value=\"" << const_rotz_rand << "\" />" << std::endl;
212
210
                return;
213
211
        }
214
212
        
215
 
        Set_Pos( pCamera->x, pCamera->y );
216
 
        Update_anim();
 
213
        Set_Pos( startposx + pActive_Camera->x, startposy + pActive_Camera->y );
 
214
        // update particles
 
215
        Update_Particles();
 
216
        // update particle animation
 
217
        cParticle_Emitter::Update();
217
218
}
218
219
 
219
 
void cGlobal_effect :: Update_anim( void )
 
220
void cGlobal_effect :: Update_Particles( void )
220
221
{
221
 
        // find out of camera objects and move them to the opposite direction
222
 
 
223
 
        GL_rect camera_rect = GL_rect( pCamera->x, pCamera->y, GAME_RES_W, GAME_RES_H );
 
222
        GL_rect camera_rect = GL_rect( pActive_Camera->x, pActive_Camera->y, static_cast<float>(game_res_w), static_cast<float>(game_res_h) );
224
223
 
225
224
        for( ParticleList::iterator itr = objects.begin(), itr_end = objects.end(); itr != itr_end; ++itr )
226
225
        {
227
 
                // get  animation particle pointer
 
226
                // get animation particle pointer
228
227
                cParticle *obj = static_cast<cParticle *>(*itr);
229
228
                
230
229
                GL_rect anim_rect = GL_rect( obj->posx, obj->posy, obj->rect.w, obj->rect.h );
231
230
                
232
231
                // if not on screen
233
 
                if( !Col_Box( &anim_rect, &camera_rect ) )
 
232
                if( !Col_Box( &camera_rect, &anim_rect ) )
234
233
                {
235
234
                        // out in left
236
 
                        if( obj->posx + image->w < pCamera->x )
 
235
                        if( anim_rect.x + anim_rect.w < camera_rect.x )
237
236
                        {
238
237
                                // move to right
239
 
                                obj->Set_PosX( pCamera->x + camera_rect.w );
 
238
                                obj->Set_Pos_X( camera_rect.x + camera_rect.w - 1 );
240
239
                        }
241
240
                        // out in right
242
 
                        else if( obj->posx > pCamera->x + camera_rect.w )
 
241
                        else if( anim_rect.x > camera_rect.x + camera_rect.w )
243
242
                        {
244
243
                                // move to left
245
 
                                obj->Set_PosX( pCamera->x - image->w );
 
244
                                obj->Set_Pos_X( camera_rect.x + 1 );
246
245
                        }
247
246
                        // out on top
248
 
                        else if( obj->posy < pCamera->y - image->h - 1 )
 
247
                        else if( anim_rect.y + anim_rect.h < camera_rect.y )
249
248
                        {
250
 
                                obj->Set_PosY( pCamera->y + camera_rect.h );
 
249
                                // move to bottom
 
250
                                obj->Set_Pos_Y( camera_rect.y + camera_rect.h - 1 );
251
251
                        }
252
252
                        // out on bottom
253
 
                        else if( obj->posy > pCamera->y + camera_rect.h + 1 )
 
253
                        else if( anim_rect.y > camera_rect.y + camera_rect.h )
254
254
                        {
255
 
                                obj->Set_PosY( pCamera->y - image->h );
 
255
                                // move to top
 
256
                                obj->Set_Pos_Y( camera_rect.y + 1 );
256
257
                        }
257
258
                }
258
259
        }
259
 
 
260
 
        // update particle animation
261
 
        cParticleAnimation::Update();
262
260
}
263
261
 
264
262
void cGlobal_effect :: Draw( void )
265
263
{
266
 
        cParticleAnimation::Draw();
 
264
        cParticle_Emitter::Draw();
267
265
}
268
266
 
269
 
void cGlobal_effect :: Set_type( GlobalEffectType ntype )
 
267
void cGlobal_effect :: Set_Type( GlobalEffectType ntype )
270
268
{
271
269
        ge_type = ntype;
272
270
}
273
271
 
274
 
void cGlobal_effect :: Set_type( string ntype )
 
272
void cGlobal_effect :: Set_Type( string ntype )
275
273
{
276
274
        if( ntype.compare( "Disabled" ) == 0 )
277
275
        {
278
276
                ge_type = GL_EFF_NONE;
279
277
        }
280
 
        else if( ntype.compare( "Falling" ) == 0 )
 
278
        else if( ntype.compare( "Falling" ) == 0 || ntype.compare( "Default" ) == 0 )
281
279
        {
282
280
                ge_type = GL_EFF_FALLING;
283
281
        }
284
 
        else if( ntype.compare( "Flying" ) == 0 )
285
 
        {
286
 
                ge_type = GL_EFF_FLYING;
287
 
        }
288
282
        else
289
283
        {
290
284
                printf( "Warning : Unknown Global Effect type %s\n", ntype.c_str() );
291
285
        }
292
286
}
293
287
 
294
 
void cGlobal_effect :: Set_image( string nimg_file )
 
288
void cGlobal_effect :: Set_Image( string nimg_file )
295
289
{
296
290
        image_filename = nimg_file;
297
291
}
298
292
 
299
 
string cGlobal_effect :: Get_Typename( void )
 
293
string cGlobal_effect :: Get_Type_Name( void )
300
294
{
301
295
        if( ge_type == GL_EFF_NONE )
302
296
        {
306
300
        {
307
301
                return "Falling";
308
302
        }
309
 
        else if( ge_type == GL_EFF_FLYING )
310
 
        {
311
 
                return "Flying";
312
 
        }
313
 
        else
314
 
        {
315
 
                return "Unknown";
316
 
        }
317
303
 
318
 
        return "";
 
304
        return "Unknown";
319
305
}