- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# enemystore.c

Go to the documentation of this file.

    00001
    00005 //    /**
    00006 //      *@defgroup enemystore enemystore.c
    00007 //      *Functions to create and keep track of enemies
    00008 //      *@{
    00009 //      */
    00010
    00011 /*----------------------------------------------------------------------------------------------------------*/
    00012
    00013 #ifndef _ALLEGRO5_
    00014 #define _ALLEGRO5_
    00015 #include <allegro5/allegro5.h>
    00016 #endif // _ALLEGRO5_
    00017
    00018 #ifndef _CHIPMUNK_
    00019 #define _CHIPMUNK_
    00020 #include "chipmunk.h"
    00021 #endif // _CHIPMUNK_
    00022
    00023 #ifndef _SPRITES_
    00024 #define _SPRITES_
    00025 #include "../include/sprites.h"
    00026 #endif // _SPRITES_
    00027
    00028 #ifndef _PHYSCOL_
    00029 #define _PHYSCOL_
    00030 #include "../include/physcol.h"
    00031 #endif // _PHYSCOL_
    00032
    00033 #ifndef _ENEMYSTORE_
    00034 #define _ENEMYSTORE_
    00035 #include "../include/enemystore.h"
    00036 #endif // _ENEMYSTORE_
    00037
    00038 /*----------------------------------------------------------------------------------------------------------*/
    00039
    00040 static int total_enemies = 0, ameans = 0, bwall = 0, clamp = 0, swall = 0, fist = 0, spikes = 0, raw = 0, plants = 0;
    00041
    00042 /*----------------------------------------------------------------------------------------------------------*/
    00043
    00044 int rand_int(int max)
    00045 {
    00046     srand((unsigned int)clock() * rand());
    00047     return (rand() % max) + 1;
    00048 }
    00049
    00050 /*----------------------------------------------------------------------------------------------------------*/
    00051
    00052 SPRITESPTR create_new_enemy(char *enemy_type)
    00053 {
    00054     SPRITESPTR enemy = NULL;
    00055     if(strcmp(enemy_type, "AMEAN") == 0)
    00056     {
    00057         ameans++;
    00058         char *labels[3] = {"AMEAN_1", "AMEAN_2", "AMEAN_3"};
    00059
    00060         enemy = create_new_sprite(enemy_type,
    00061                                   labels,
    00062                                   sizeof(labels)/sizeof(*labels),
    00063                                   NULL,
    00064                                   NULL,
    00065                                   NULL,
    00066                                   0,
    00067                                   "AMEAN_1",
    00068                                   805,
    00069                                   450,
    00070                                   3,
    00071                                   0,
    00072                                   0,
    00073                                   MNONE,
    00074                                   true
    00075                                 );
    00076         if(enemy == NULL) return false;
    00077         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00078     }
    00079     else if(strcmp(enemy_type, "BRICK_WALL") == 0)
    00080     {
    00081         bwall++;
    00082         char *labels[1] = {"BRICK_WALL"};
    00083         int y = 450;
    00084
    00085         if(rand_int(2) == 1)
    00086             y = 400;
    00087
    00088         enemy = create_new_sprite(enemy_type,
    00089                                   labels,
    00090                                   sizeof(labels)/sizeof(*labels),
    00091                                   NULL,
    00092                                   NULL,
    00093                                   NULL,
    00094                                   0,
    00095                                   "BRICK_WALL",
    00096                                   805,
    00097                                   y,
    00098                                   3,
    00099                                   0,
    00100                                   0,
    00101                                   MNONE,
    00102                                   true
    00103                                 );
    00104         if(enemy == NULL) return false;
    00105         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00106     }
    00107     else if(strcmp(enemy_type, "CLAMP") == 0)
    00108     {
    00109         clamp++;
    00110         char *labels[3] = {"CLAMP_OPEN", "CLAMP_CLOSE", "ARM"};
    00111
    00112         enemy = create_new_sprite(enemy_type,
    00113                                   labels,
    00114                                   sizeof(labels)/sizeof(*labels),
    00115                                   NULL,
    00116                                   NULL,
    00117                                   NULL,
    00118                                   0,
    00119                                   "CLAMP_OPEN",
    00120                                   805,
    00121                                   0,
    00122                                   3,
    00123                                   0,
    00124                                   0,
    00125                                   MNONE,
    00126                                   true
    00127                                 );
    00128         if(enemy == NULL) return false;
    00129         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00130     }
    00131     else if(strcmp(enemy_type, "STEEL_WALL") == 0)
    00132     {
    00133         swall++;
    00134         char *labels[1] = {"STEEL_WALL"};
    00135         int y = 450;
    00136
    00137         if(rand_int(2) == 1)
    00138             y = 380;
    00139
    00140         enemy = create_new_sprite(enemy_type,
    00141                                   labels,
    00142                                   sizeof(labels)/sizeof(*labels),
    00143                                   NULL,
    00144                                   NULL,
    00145                                   NULL,
    00146                                   0,
    00147                                   "STEEL_WALL",
    00148                                   805,
    00149                                   y,
    00150                                   3,
    00151                                   0,
    00152                                   0,
    00153                                   MNONE,
    00154                                   true
    00155                                 );
    00156         if(enemy == NULL) return false;
    00157         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00158     }
    00159     else if(strcmp(enemy_type, "FLYING_FIST") == 0)
    00160     {
    00161         fist++;
    00162         char *labels[1] = {"FLYING_FIST"};
    00163
    00164         enemy = create_new_sprite(enemy_type,
    00165                                   labels,
    00166                                   sizeof(labels)/sizeof(*labels),
    00167                                   NULL,
    00168                                   NULL,
    00169                                   NULL,
    00170                                   0,
    00171                                   "FLYING_FIST",
    00172                                   805,
    00173                                   410,
    00174                                   3,
    00175                                   0,
    00176                                   0,
    00177                                   MNONE,
    00178                                   true
    00179                                 );
    00180         if(enemy == NULL) return false;
    00181         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00182     }
    00183     else if(strcmp(enemy_type, "SPIKES") == 0)
    00184     {
    00185         spikes++;
    00186         char *labels[1] = {"SPIKES"};
    00187
    00188         enemy = create_new_sprite(enemy_type,
    00189                                   labels,
    00190                                   sizeof(labels)/sizeof(*labels),
    00191                                   NULL,
    00192                                   NULL,
    00193                                   NULL,
    00194                                   0,
    00195                                   "SPIKES",
    00196                                   805,
    00197                                   475,
    00198                                   3,
    00199                                   0,
    00200                                   0,
    00201                                   MNONE,
    00202                                   true
    00203                                 );
    00204         if(enemy == NULL) return false;
    00205         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00206     }
    00207     else if(strcmp(enemy_type, "RAW") == 0)
    00208     {
    00209         raw++;
    00210         char *labels[3] = {"RAW_1", "RAW_2", "LAZER"};
    00211
    00212         enemy = create_new_sprite(enemy_type,
    00213                                   labels,
    00214                                   sizeof(labels)/sizeof(*labels),
    00215                                   NULL,
    00216                                   NULL,
    00217                                   NULL,
    00218                                   0,
    00219                                   "RAW_1",
    00220                                   805,
    00221                                   465,
    00222                                   3,
    00223                                   0,
    00224                                   0,
    00225                                   MNONE,
    00226                                   true
    00227                                 );
    00228         if(enemy == NULL) return false;
    00229         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00230     }
    00231     else if(strcmp(enemy_type, "PLANT") == 0)
    00232     {
    00233         plants++;
    00234         char *labels[3] = {"PLANT_1", "PLANT_2", "STEM"};
    00235
    00236         enemy = create_new_sprite(enemy_type,
    00237                                   labels,
    00238                                   sizeof(labels)/sizeof(*labels),
    00239                                   NULL,
    00240                                   NULL,
    00241                                   NULL,
    00242                                   0,
    00243                                   "PLANT_2",
    00244                                   805,
    00245                                   465,
    00246                                   3,
    00247                                   0,
    00248                                   0,
    00249                                   MNONE,
    00250                                   true
    00251                                 );
    00252         if(enemy == NULL) return false;
    00253         if(create_physics_object(enemy, 60, 0.1f, 0.85f, 2, enemy) == NULL) return false;
    00254     }
    00255
    00256     total_enemies = ameans + bwall + clamp + swall + fist + spikes + plants + raw;
    00257     cpSpaceResizeActiveHash(get_global_cpSpace(), 80.0, total_enemies+1*10);
    00258
    00259
    00260     return enemy;
    00261 }
    00262
    00263 /*----------------------------------------------------------------------------------------------------------*/
    00264
    00265 void remove_enemy(SPRITESPTR sprite)
    00266 {
    00267     if(strcmp(sprite->slabel, "AMEAN") == 0)
    00268         ameans--;
    00269     else if(strcmp(sprite->slabel, "BRICK_WALL") == 0)
    00270         bwall--;
    00271     else if(strcmp(sprite->slabel, "CLAMP") == 0)
    00272         clamp--;
    00273     else if(strcmp(sprite->slabel, "STEEL_WALL") == 0)
    00274         swall--;
    00275     else if(strcmp(sprite->slabel, "FLYING_FIST") == 0)
    00276         fist--;
    00277     else if(strcmp(sprite->slabel, "SPIKES") == 0)
    00278         spikes--;
    00279     else if(strcmp(sprite->slabel, "RAW") == 0)
    00280         raw--;
    00281     else if(strcmp(sprite->slabel, "PLANT") == 0)
    00282         plants--;
    00283     remove_physics_object(sprite);
    00284     remove_element_from_sprite_list_ptr(sprite);
    00285 }
    00286
    00287 /*----------------------------------------------------------------------------------------------------------*/
    00288
    00289 void remove_all_enemies_of_type(char *enemy_label)
    00290 {
    00291     SPRITESPTR sprite;
    00292     if(strcmp(enemy_label, "AMEAN") == 0)
    00293     {
    00294         while((sprite = search_sprite_list_for_element("AMEAN")) != NULL)
    00295         {
    00296             remove_physics_object(sprite);
    00297             remove_element_from_sprite_list_ptr(sprite);
    00298         }
    00299         ameans = 0;
    00300     }
    00301     else if(strcmp(enemy_label, "BRICK_WALL") == 0)
    00302     {
    00303         while((sprite = search_sprite_list_for_element("BRICK_WALL")) != NULL)
    00304         {
    00305             remove_physics_object(sprite);
    00306             remove_element_from_sprite_list_ptr(sprite);
    00307         }
    00308         bwall = 0;
    00309     }
    00310     else if(strcmp(enemy_label, "CLAMP") == 0)
    00311     {
    00312         while((sprite = search_sprite_list_for_element("CLAMP")) != NULL)
    00313         {
    00314             remove_physics_object(sprite);
    00315             remove_element_from_sprite_list_ptr(sprite);
    00316         }
    00317         clamp = 0;
    00318     }
    00319     else if(strcmp(enemy_label, "STEEL_WALL") == 0)
    00320     {
    00321         while((sprite = search_sprite_list_for_element("STEEL_WALL")) != NULL)
    00322         {
    00323             remove_physics_object(sprite);
    00324             remove_element_from_sprite_list_ptr(sprite);
    00325         }
    00326         swall = 0;
    00327     }
    00328     else if(strcmp(enemy_label, "FLYING_FIST") == 0)
    00329     {
    00330         while((sprite = search_sprite_list_for_element("FLYING_FIST")) != NULL)
    00331         {
    00332             remove_physics_object(sprite);
    00333             remove_element_from_sprite_list_ptr(sprite);
    00334         }
    00335         fist = 0;
    00336     }
    00337     else if(strcmp(enemy_label, "SPIKES") == 0)
    00338     {
    00339         while((sprite = search_sprite_list_for_element("SPIKES")) != NULL)
    00340         {
    00341             remove_physics_object(sprite);
    00342             remove_element_from_sprite_list_ptr(sprite);
    00343         }
    00344         spikes = 0;
    00345     }
    00346     else if(strcmp(enemy_label, "RAW") == 0)
    00347     {
    00348         while((sprite = search_sprite_list_for_element("RAW")) != NULL)
    00349         {
    00350             remove_physics_object(sprite);
    00351             remove_element_from_sprite_list_ptr(sprite);
    00352         }
    00353         raw = 0;
    00354     }
    00355     else if(strcmp(enemy_label, "PLANT") == 0)
    00356     {
    00357         while((sprite = search_sprite_list_for_element("PLANT")) != NULL)
    00358         {
    00359             remove_physics_object(sprite);
    00360             remove_element_from_sprite_list_ptr(sprite);
    00361         }
    00362         plants = 0;
    00363     }
    00364 }
    00365
    00366 /*----------------------------------------------------------------------------------------------------------*/
    00367
    00368 void remove_all_enemies(void)
    00369 {
    00370     SPRITESPTR sprite;
    00371     while((sprite = search_sprite_list_for_element("AMEAN")) != NULL)
    00372     {
    00373         remove_physics_object(sprite);
    00374         remove_element_from_sprite_list_ptr(sprite);
    00375     }
    00376     while((sprite = search_sprite_list_for_element("BRICK_WALL")) != NULL)
    00377     {
    00378         remove_physics_object(sprite);
    00379         remove_element_from_sprite_list_ptr(sprite);
    00380     }
    00381     while((sprite = search_sprite_list_for_element("CLAMP")) != NULL)
    00382     {
    00383         remove_physics_object(sprite);
    00384         remove_element_from_sprite_list_ptr(sprite);
    00385     }
    00386     while((sprite = search_sprite_list_for_element("STEEL_WALL")) != NULL)
    00387     {
    00388         remove_physics_object(sprite);
    00389         remove_element_from_sprite_list_ptr(sprite);
    00390     }
    00391     while((sprite = search_sprite_list_for_element("FLYING_FIST")) != NULL)
    00392     {
    00393         remove_physics_object(sprite);
    00394         remove_element_from_sprite_list_ptr(sprite);
    00395     }
    00396     while((sprite = search_sprite_list_for_element("SPIKES")) != NULL)
    00397     {
    00398         remove_physics_object(sprite);
    00399         remove_element_from_sprite_list_ptr(sprite);
    00400     }
    00401     while((sprite = search_sprite_list_for_element("RAW")) != NULL)
    00402     {
    00403         remove_physics_object(sprite);
    00404         remove_element_from_sprite_list_ptr(sprite);
    00405     }
    00406     while((sprite = search_sprite_list_for_element("PLANT")) != NULL)
    00407     {
    00408         remove_physics_object(sprite);
    00409         remove_element_from_sprite_list_ptr(sprite);
    00410     }
    00411     total_enemies = 0;
    00412     ameans = 0;
    00413     bwall = 0;
    00414     clamp = 0;
    00415     swall = 0;
    00416     fist = 0;
    00417     spikes = 0;
    00418     raw = 0;
    00419     plants = 0;
    00420 }
    00421
    00422 /*----------------------------------------------------------------------------------------------------------*/
    00423
    00424
    00425 //    /**
    00426 //      *@}
    00427 //      */