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

« back to all changes in this revision

Viewing changes to src/enemies/spika.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Muammar El Khatib
  • Date: 2009-08-18 11:28:01 UTC
  • mfrom: (1.1.7 upstream) (5.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090818112801-qfhdmqouq8m1fwab
Tags: 1.9-1
* New upstream release.
* Bumped standards version to 3.8.3. No changes were needed in order to 
  accomplish this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        m_type = TYPE_SPIKA;
54
54
        m_pos_z = 0.09f;
55
55
 
56
 
        color_type = COL_DEFAULT;
57
 
        speed = 0;
58
 
        detection_size = 0;
 
56
        m_speed = 0.0f;
 
57
        m_detection_size = 0.0f;
 
58
        m_walk_count = 0.0f;
59
59
 
 
60
        m_color_type = COL_DEFAULT;
60
61
        Set_Color( COL_ORANGE );
61
62
}
62
63
 
63
64
cSpika *cSpika :: Copy( void )
64
65
{
65
66
        cSpika *spika = new cSpika( m_start_pos_x, m_start_pos_y );
66
 
        spika->Set_Color( color_type );
 
67
        spika->Set_Color( m_color_type );
67
68
 
68
69
        return spika;
69
70
}
73
74
        // position
74
75
        Set_Pos( static_cast<float>(attributes.getValueAsInteger( "posx" )), static_cast<float>(attributes.getValueAsInteger( "posy" )), 1 );
75
76
        // color
76
 
        Set_Color( static_cast<DefaultColor>(Get_Color_Id( attributes.getValueAsString( "color", Get_Color_Name( color_type ) ).c_str() )) );
 
77
        Set_Color( static_cast<DefaultColor>(Get_Color_Id( attributes.getValueAsString( "color", Get_Color_Name( m_color_type ) ).c_str() )) );
77
78
}
78
79
 
79
80
void cSpika :: Save_To_Stream( ofstream &file )
87
88
        file << "\t\t<Property name=\"posx\" value=\"" << static_cast<int>(m_start_pos_x) << "\" />" << std::endl;
88
89
        file << "\t\t<Property name=\"posy\" value=\"" << static_cast<int>(m_start_pos_y) << "\" />" << std::endl;
89
90
        // color
90
 
        file << "\t\t<Property name=\"color\" value=\"" << Get_Color_Name( color_type ) << "\" />" << std::endl;
 
91
        file << "\t\t<Property name=\"color\" value=\"" << Get_Color_Name( m_color_type ) << "\" />" << std::endl;
91
92
 
92
93
        // end enemy
93
94
        file << "\t</enemy>" << std::endl;
96
97
void cSpika :: Set_Color( DefaultColor col )
97
98
{
98
99
        // already set
99
 
        if( color_type == col )
 
100
        if( m_color_type == col )
100
101
        {
101
102
                return;
102
103
        }
104
105
        // clear old images
105
106
        Clear_Images();
106
107
 
107
 
        color_type = col;
108
 
 
109
 
        if( color_type == COL_ORANGE )
110
 
        {
111
 
                m_images.push_back( pVideo->Get_Surface( "enemy/spika/orange.png" ) );
112
 
 
113
 
                speed = 3;
114
 
                detection_size = 160;
115
 
                kill_points = 50;
116
 
 
117
 
                fire_resistant = 0;
118
 
        }
119
 
        else if( color_type == COL_GREEN )
120
 
        {
121
 
                m_images.push_back( pVideo->Get_Surface( "enemy/spika/green.png" ) );
122
 
 
123
 
                speed = 4;
124
 
                detection_size = 220;
125
 
                kill_points = 200;
126
 
 
127
 
                fire_resistant = 0;
128
 
        }
129
 
        else if( color_type == COL_GREY )
130
 
        {
131
 
                m_images.push_back( pVideo->Get_Surface( "enemy/spika/grey.png" ) );
132
 
 
133
 
                speed = 7;
134
 
                detection_size = 330;
135
 
                kill_points = 500;
136
 
 
137
 
                fire_resistant = 1;
 
108
        m_color_type = col;
 
109
 
 
110
        if( m_color_type == COL_ORANGE )
 
111
        {
 
112
                Add_Image( pVideo->Get_Surface( "enemy/spika/orange.png" ) );
 
113
 
 
114
                m_speed = 3;
 
115
                m_detection_size = 160.0f;
 
116
                m_kill_points = 50;
 
117
 
 
118
                m_fire_resistant = 0;
 
119
                m_ice_resistance = 0.0f;
 
120
        }
 
121
        else if( m_color_type == COL_GREEN )
 
122
        {
 
123
                Add_Image( pVideo->Get_Surface( "enemy/spika/green.png" ) );
 
124
 
 
125
                m_speed = 4;
 
126
                m_detection_size = 220.0f;
 
127
                m_kill_points = 200;
 
128
 
 
129
                m_fire_resistant = 0;
 
130
                m_ice_resistance = 0.1f;
 
131
        }
 
132
        else if( m_color_type == COL_GREY )
 
133
        {
 
134
                Add_Image( pVideo->Get_Surface( "enemy/spika/grey.png" ) );
 
135
 
 
136
                m_speed = 7;
 
137
                m_detection_size = 330.0f;
 
138
                m_kill_points = 500;
 
139
 
 
140
                m_fire_resistant = 1;
 
141
                m_ice_resistance = 0.5f;
138
142
        }
139
143
        else
140
144
        {
141
 
                printf( "Error : Unknown Spika Color %d\n", color_type );
 
145
                printf( "Error : Unknown Spika Color %d\n", m_color_type );
142
146
        }
143
147
 
144
148
        Set_Image_Num( 0, 1 );
145
149
 
146
150
        m_name = "Spika ";
147
 
        m_name += _(Get_Color_Name( color_type ).c_str());
 
151
        m_name += _(Get_Color_Name( m_color_type ).c_str());
148
152
}
149
153
 
150
154
void cSpika :: DownGrade( bool force /* = 0 */ )
151
155
{
152
156
        Set_Dead( 1 );
153
157
        m_massive_type = MASS_PASSIVE;
154
 
        counter = 0;
155
 
        m_velx = 0;
156
 
        m_vely = 0;
 
158
        m_counter = 0.0f;
 
159
        m_velx = 0.0f;
 
160
        m_vely = 0.0f;
157
161
        Set_Scale_Directions( 1, 1, 1, 1 );
158
162
 
159
163
        // default stomp death
164
168
        // falling death
165
169
        else
166
170
        {
167
 
                Set_Rotation_Z( 180 );
 
171
                Set_Rotation_Z( 180.0f );
168
172
        }
169
173
}
170
174
 
171
 
void cSpika :: DieStep( void )
 
175
void cSpika :: Update_Dying( void )
172
176
{
173
 
        counter += pFramerate->speedfactor * 0.1f;
 
177
        m_counter += pFramerate->m_speed_factor * 0.1f;
174
178
 
175
179
        // falling death
176
180
 
177
181
        // a little bit upwards first
178
 
        if( counter < 0.3f )
 
182
        if( m_counter < 0.3f )
179
183
        {
180
 
                Move( 0, -5 );
 
184
                Move( 0.0f, -5.0f );
181
185
        }
182
186
        // if not below the screen fall
183
187
        else if( m_pos_y < game_res_h + m_col_rect.m_h )
184
188
        {
185
 
                Move( 0, 20 );
 
189
                Move( 0.0f, 20.0f );
186
190
 
187
 
                Add_Scale( -pFramerate->speedfactor * 0.01f );
 
191
                Add_Scale( -pFramerate->m_speed_factor * 0.01f );
188
192
        }
189
193
        // if below disable
190
194
        else
191
195
        {
192
 
                m_rot_z = 0;
193
 
                Set_Scale( 1 );
 
196
                m_rot_z = 0.0f;
 
197
                Set_Scale( 1.0f );
194
198
                Set_Active( 0 );
195
199
        }
196
200
}
207
211
        // update rotation
208
212
        if( m_velx != 0 )
209
213
        {
210
 
                Add_Rotation_Z( ( m_velx / ( m_image->m_w * 0.01f ) ) * pFramerate->speedfactor );
 
214
                Add_Rotation_Z( ( m_velx / ( m_image->m_w * 0.01f ) ) * pFramerate->m_speed_factor );
211
215
        }
212
216
 
213
217
        // check for player
222
226
 
223
227
        GL_rect rect_right = rect_left;
224
228
        // left
225
 
        rect_left.m_x -= detection_size + ( m_col_rect.m_w / 2 );
226
 
        rect_left.m_w += detection_size;
 
229
        rect_left.m_x -= m_detection_size + ( m_col_rect.m_w / 2 );
 
230
        rect_left.m_w += m_detection_size;
227
231
        // right
228
232
        rect_right.m_x -= m_col_rect.m_w / 2;
229
 
        rect_right.m_w += detection_size;
 
233
        rect_right.m_w += m_detection_size;
230
234
 
231
235
 
232
236
        // if player is left
233
237
        if( pPlayer->maryo_type != MARYO_GHOST && player_rect.Intersects( rect_left ) )
234
238
        {
235
 
                if( m_velx > -speed )
 
239
                if( m_velx > -m_speed )
236
240
                {
237
 
                        m_velx -= speed * 0.1f * pFramerate->speedfactor;
 
241
                        m_velx -= m_speed * 0.1f * pFramerate->m_speed_factor;
238
242
 
239
 
                        if( m_velx < -speed )
 
243
                        if( m_velx < -m_speed )
240
244
                        {
241
 
                                m_velx = -speed;
 
245
                                m_velx = -m_speed;
242
246
                        }
243
247
                }
244
248
        }
245
249
        // if player is right
246
250
        else if( pPlayer->maryo_type != MARYO_GHOST && player_rect.Intersects( rect_right ) )
247
251
        {
248
 
                if( m_velx < speed )
 
252
                if( m_velx < m_speed )
249
253
                {
250
 
                        m_velx += speed * 0.1f * pFramerate->speedfactor;
 
254
                        m_velx += m_speed * 0.1f * pFramerate->m_speed_factor;
251
255
 
252
 
                        if( m_velx > speed )
 
256
                        if( m_velx > m_speed )
253
257
                        {
254
 
                                m_velx = speed;
 
258
                                m_velx = m_speed;
255
259
                        }
256
260
                }
257
261
        }
259
263
        else
260
264
        {
261
265
                // slow down
262
 
                m_velx -= (m_velx * 0.03f) * pFramerate->speedfactor;
 
266
                m_velx -= (m_velx * 0.03f) * pFramerate->m_speed_factor;
263
267
        }
264
268
 
265
269
        // play walking sound based on speed
266
 
        if( walk_count < m_rot_z - 30 || walk_count > m_rot_z + 30 )
 
270
        if( m_walk_count < m_rot_z - 30.0f || m_walk_count > m_rot_z + 30.0f )
267
271
        {
268
272
                pAudio->Play_Sound( "enemy/spika/move.ogg" );
269
273
 
270
 
                walk_count = m_rot_z;
 
274
                m_walk_count = m_rot_z;
271
275
        }
272
276
 
273
277
        // gravity
276
280
 
277
281
bool cSpika :: Is_Update_Valid( void )
278
282
{
279
 
        if( dead || m_freeze_counter )
 
283
        if( m_dead || m_freeze_counter )
280
284
        {
281
285
                return 0;
282
286
        }
290
294
        Col_Valid_Type basic_valid = Validate_Collision_Ghost( obj );
291
295
 
292
296
        // found valid collision
293
 
        if( basic_valid != COL_VTYPE_NO_GHOST )
 
297
        if( basic_valid != COL_VTYPE_NOT_POSSIBLE )
294
298
        {
295
299
                return basic_valid;
296
300
        }
297
301
 
298
302
        if( obj->m_massive_type == MASS_MASSIVE )
299
303
        {
300
 
                if( obj->m_type == TYPE_ROKKO )
301
 
                {
302
 
                        return COL_VTYPE_NOT_VALID;
303
 
                }
304
 
                if( obj->m_type == TYPE_GEE )
305
 
                {
306
 
                        return COL_VTYPE_NOT_VALID;
307
 
                }
308
 
                if( obj->m_type == TYPE_TURTLE_BOSS )
309
 
                {
310
 
                        return COL_VTYPE_NOT_VALID;
311
 
                }
312
 
                if( obj->m_type == TYPE_FURBALL_BOSS )
313
 
                {
314
 
                        return COL_VTYPE_NOT_VALID;
315
 
                }
316
 
                if( obj->m_type == TYPE_STATIC_ENEMY )
317
 
                {
318
 
                        return COL_VTYPE_NOT_VALID;
 
304
                switch( obj->m_type )
 
305
                {
 
306
                        case TYPE_ROKKO:
 
307
                        {
 
308
                                return COL_VTYPE_NOT_VALID;
 
309
                        }
 
310
                        case TYPE_GEE:
 
311
                        {
 
312
                                return COL_VTYPE_NOT_VALID;
 
313
                        }
 
314
                        case TYPE_TURTLE_BOSS:
 
315
                        {
 
316
                                return COL_VTYPE_NOT_VALID;
 
317
                        }
 
318
                        case TYPE_FURBALL_BOSS:
 
319
                        {
 
320
                                return COL_VTYPE_NOT_VALID;
 
321
                        }
 
322
                        case TYPE_STATIC_ENEMY:
 
323
                        {
 
324
                                return COL_VTYPE_NOT_VALID;
 
325
                        }
 
326
                        default:
 
327
                        {
 
328
                                break;
 
329
                        }
319
330
                }
320
331
 
321
332
                if( obj->m_sprite_array == ARRAY_ENEMY )
322
333
                {
323
 
                        // if moving collide
324
 
                        if( m_velx != 0 )
 
334
                        // collide only if moving
 
335
                        if( !Is_Float_Equal( m_velx, 0.0f ) )
325
336
                        {
326
337
                                // if enemy is spika and more powerful
327
 
                                if( obj->m_type == TYPE_SPIKA && speed < static_cast<cSpika *>(obj)->speed )
 
338
                                if( obj->m_type == TYPE_SPIKA && m_speed < static_cast<cSpika *>(obj)->m_speed )
328
339
                                {
329
340
                                        return COL_VTYPE_BLOCKING;
330
341
                                }
337
348
 
338
349
                return COL_VTYPE_BLOCKING;
339
350
        }
340
 
        if( obj->m_massive_type == MASS_HALFMASSIVE )
 
351
        else if( obj->m_massive_type == MASS_HALFMASSIVE )
341
352
        {
342
353
                // if moving downwards and the object is on bottom
343
354
                if( m_vely >= 0 && Is_On_Top( obj ) )
355
366
 
356
367
        if( collision->direction == DIR_LEFT || collision->direction == DIR_RIGHT )
357
368
        {
358
 
                m_velx = 0;
 
369
                m_velx = 0.0f;
359
370
        }
360
371
}
361
372
 
367
378
                return;
368
379
        }
369
380
 
370
 
        // only if moving
371
 
        if( !m_velx )
372
 
        {
373
 
                return;
374
 
        }
375
 
 
376
381
        cEnemy *enemy = static_cast<cEnemy *>(pActive_Sprite_Manager->Get_Pointer( collision->number ));
377
382
 
378
383
        // already dead
379
 
        if( enemy->dead )
 
384
        if( enemy->m_dead )
380
385
        {
381
386
                return;
382
387
        }
383
388
 
384
 
        // check spika power
 
389
        // if spika
385
390
        if( enemy->m_type == TYPE_SPIKA )
386
391
        {
387
392
                cSpika *spika = static_cast<cSpika *>(enemy);
388
393
 
389
394
                // if colliding spika is more powerful
390
 
                if( speed < spika->speed )
 
395
                if( m_speed < spika->m_speed )
391
396
                {
392
397
                        //enemy->Send_Collision( collision );
393
398
                        return;
401
406
                cTurtleBoss *turtle_boss = static_cast<cTurtleBoss *>(enemy);
402
407
 
403
408
                // downgrade until state change
404
 
                for( int i = turtle_boss->hits; i < turtle_boss->max_hits; i++ )
 
409
                for( int i = turtle_boss->m_hits; i < turtle_boss->m_max_hits; i++ )
405
410
                {
406
411
                        turtle_boss->DownGrade();
407
412
                }
408
413
 
409
 
                // turtle kills spika
 
414
                // boss kills spika
410
415
                DownGrade( 1 );
411
416
        }
412
417
        // state change for furball boss
413
418
        else if( enemy->m_type == TYPE_FURBALL_BOSS )
414
419
        {
415
420
                enemy->DownGrade();
416
 
                // kills spika
 
421
                // also hits us
 
422
                DownGrade( 1 );
 
423
        }
 
424
        // enemies that also hit us
 
425
        else if( ( enemy->m_type == TYPE_TURTLE && enemy->m_state == STA_RUN ) )
 
426
        {
 
427
                enemy->DownGrade( 1 );
 
428
                // also hits us
 
429
                DownGrade( 1 );
 
430
        }
 
431
        // enemies that only hit us
 
432
        else if( enemy->m_type == TYPE_SPIKEBALL )
 
433
        {
 
434
                // hits us
417
435
                DownGrade( 1 );
418
436
        }
419
437
        // kill enemy
420
438
        else
421
439
        {
422
 
                pAudio->Play_Sound( enemy->kill_sound );
423
 
                pHud_Points->Add_Points( enemy->kill_points, m_pos_x + m_image->m_w / 3, m_pos_y - 5, "", static_cast<Uint8>(255), 1 );
 
440
                // only if moving
 
441
                if( Is_Float_Equal( m_velx, 0.0f ) )
 
442
                {
 
443
                        return;
 
444
                }
 
445
 
 
446
                pAudio->Play_Sound( enemy->m_kill_sound );
 
447
                pHud_Points->Add_Points( enemy->m_kill_points, m_pos_x + m_image->m_w / 3, m_pos_y - 5, "", static_cast<Uint8>(255), 1 );
424
448
                enemy->DownGrade( 1 );
425
449
        }
426
450
}
451
475
                {
452
476
                        m_velx -= 10;
453
477
                }
454
 
        }
455
 
        // unsupported collision direction
456
 
        else
457
 
        {
458
 
                return;
459
 
        }
460
478
 
461
 
        Reset_on_Ground();
 
479
                Reset_On_Ground();
 
480
        }
462
481
}
463
482
 
464
483
/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */