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

- File List
- Globals

# inits.c

Go to the documentation of this file.

    00001
    00005 //    /**
    00006 //      *@defgroup inits inits.c
    00007 //      *Contains functions that initialize the base image lists, buttons, sprites and other specific game objects
    00008 //      *@{
    00009 //      */
    00010
    00011 /*----------------------------------------------------------------------------------------------------------*/
    00012
    00013 #ifndef _ALLEGRO5_
    00014 #define _ALLEGRO5_
    00015 #include <allegro5/allegro5.h>
    00016 #endif // _ALLEGRO5_
    00017
    00018 #ifndef _ALLEGRO5FONT_
    00019 #define _ALLEGRO5FONT_
    00020 #include <allegro5/allegro_font.h>
    00021 #endif // _ALLEGRO5FONT_
    00022
    00023 #ifndef _ALLEGRO5TTF_
    00024 #define _ALLEGRO5TTF_
    00025 #include <allegro5/allegro_ttf.h>
    00026 #endif // _ALLEGRO5TTF_
    00027
    00028 #ifndef _CHIPMUNK_
    00029 #define _CHIPMUNK_
    00030 #include "chipmunk.h"
    00031 #endif // _CHIPMUNK_
    00032
    00033 #ifndef _COMMONS_
    00034 #define _COMMONS_
    00035 #include "../include/commons.h"
    00036 #endif // _COMMONS_
    00037
    00038 #ifndef _BUTTONS_
    00039 #define _BUTTONS_
    00040 #include "../include/buttons.h"
    00041 #endif // _BUTTONS_
    00042
    00043 #ifndef _SPRITES_
    00044 #define _SPRITES_
    00045 #include "../include/sprites.h"
    00046 #endif // _SPRITES_
    00047
    00048 #ifndef _PHYSCOL_
    00049 #define _PHYSCOL_
    00050 #include "../include/physcol.h"
    00051 #endif // _PHYSCOL_
    00052
    00053 #ifndef _INITS_
    00054 #define _INITS_
    00055 #include "../include/inits.h"
    00056 #endif // _INITS_
    00057
    00058 /*----------------------------------------------------------------------------------------------------------*/
    00059
    00060 // Initializes the base image list, where all images are grabbed by SPRITE structures
    00061 _Bool init_base_images(void)
    00062 {
    00063     SIMAGEPTR ptri;
    00064     String images[27] = {"amean_1.png", "amean_2.png", "amean_3.png", "arm.png", "background_day.png",
    00065                          "brick_wallx2.png", "clamp_close.png", "clamp_open.png", "cloud.png", "flying_fist.png",
    00066                          "ground_block.png", "lazer.png", "plant_1.png", "plant_2.png", "raw_1.png", "raw_2.png",
    00067                          "spikes.png", "steel_wall.png", "stem.png", "stickfigure_attack_run.png",
    00068                          "stickfigure_attack_jump.png", "stickfigure_attack_slide.png", "stickfigure_dead.png",
    00069                          "stickfigure_lives.png", "stickfigure_move_1.png", "stickfigure_move_2.png", "stickfigure_slide.png"};
    00070
    00071     String labels[27] = {"AMEAN_1", "AMEAN_2", "AMEAN_3", "ARM", "BACKGROUND_DAY", "BRICK_WALL", "CLAMP_CLOSE",
    00072                          "CLAMP_OPEN", "CLOUD", "FLYING_FIST", "GROUND_BLOCK", "LAZER", "PLANT_1", "PLANT_2", "RAW_1",
    00073                          "RAW_2", "SPIKES", "STEEL_WALL", "STEM", "STICKFIGURE_ATTACK_RUN", "STICKFIGURE_ATTACK_JUMP",
    00074                          "STICKFIGURE_ATTACK_SLIDE", "STICKFIGURE_DEAD", "STICKFIGURE_LIVES", "STICKFIGURE_MOVE_1",
    00075                          "STICKFIGURE_MOVE_2", "STICKFIGURE_SLIDE"};
    00076
    00077     ptri = create_base_image_list(labels, images, sizeof(labels)/sizeof(*labels));
    00078
    00079     if(ptri == NULL) return false;
    00080
    00081     return true;
    00082 }
    00083
    00084 /*----------------------------------------------------------------------------------------------------------*/
    00085
    00086 // Initializes the main sprites; stickman, background etc.
    00087 _Bool init_core_sprites(void)
    00088 {
    00089     if(!init_base_images()) return false;
    00090
    00091     SPRITESPTR ptrs;
    00092
    00093     String jlabels[1] = {"BACKGROUND_DAY"};
    00094     ptrs = create_new_sprite("BACKGROUND",
    00095                              jlabels,
    00096                              sizeof(jlabels)/sizeof(*jlabels),
    00097                              NULL,
    00098                              NULL,
    00099                              NULL,
    00100                              0,
    00101                              "BACKGROUND_DAY",
    00102                              0,
    00103                              0,
    00104                              0,
    00105                              0,
    00106                              0,
    00107                              MNONE,
    00108                              true
    00109                             );
    00110     if(ptrs == NULL) return false;
    00111
    00112     String llabels[1] = {"GROUND_BLOCK"};
    00113     ptrs = create_new_sprite("GROUND",
    00114                              llabels,
    00115                              sizeof(llabels)/sizeof(*llabels),
    00116                              NULL,
    00117                              NULL,
    00118                              NULL,
    00119                              0,
    00120                              "GROUND_BLOCK",
    00121                              0,
    00122                              510,
    00123                              3,
    00124                              0,
    00125                              0,
    00126                              MNONE,
    00127                              true
    00128                             );
    00129     if(ptrs == NULL) return false;
    00130
    00131     return true;
    00132 }
    00133
    00134 /*----------------------------------------------------------------------------------------------------------*/
    00135
    00136 _Bool game_start_init(void)
    00137 {
    00138     SPRITESPTR ptrs;
    00139
    00140        String ilabels[8] = {"STICKFIGURE_ATTACK_RUN", "STICKFIGURE_ATTACK_JUMP", "STICKFIGURE_ATTACK_SLIDE",
    00141                             "STICKFIGURE_DEAD", "STICKFIGURE_LIVES", "STICKFIGURE_MOVE_1", "STICKFIGURE_MOVE_2",
    00142                             "STICKFIGURE_SLIDE"};
    00143     ptrs = create_new_sprite("STICKMAN",
    00144                              ilabels,
    00145                              sizeof(ilabels)/sizeof(*ilabels),
    00146                              NULL,
    00147                              NULL,
    00148                              NULL,
    00149                              0,
    00150                              "STICKFIGURE_MOVE_1",
    00151                              50,
    00152                              150,
    00153                              3,
    00154                              350,
    00155                              0,
    00156                              MNONE,
    00157                              true
    00158                             );
    00159     if(ptrs == NULL) return false;
    00160     if(create_physics_object(ptrs, 60, 1, 0.85f, 1, "STICKMAN") == NULL) return false;
    00161
    00162     String klabels[1] = {"CLOUD"};
    00163     ptrs = create_new_sprite("CLOUD",
    00164                              klabels,
    00165                              sizeof(klabels)/sizeof(*klabels),
    00166                              NULL,
    00167                              NULL,
    00168                              NULL,
    00169                              0,
    00170                              "CLOUD",
    00171                              263,
    00172                              225,
    00173                              3,
    00174                              0,
    00175                              0,
    00176                              MNONE,
    00177                              true
    00178                             );
    00179     if(ptrs == NULL) return false;
    00180
    00181     return true;
    00182 }
    00183
    00184 /*----------------------------------------------------------------------------------------------------------*/
    00185
    00186 // Initializes the startup buttons
    00187 _Bool init_buttons(void)
    00188 {
    00189     if(!init_button_images()) return false;
    00190
    00191     BUTTONPTR ptrb;
    00192     GDATAPTR game = get_game_data();
    00193
    00194     ptrb = create_new_button("STARTBUTTON",
    00195                              "DEFAULT",
    00196                              "NEW GAME",
    00197                              game->b_font,
    00198                              BCOLOR(255, 255, 255, 255), //80, 112/122, 255
    00199                              BCOLOR(65, 105, 255, 191),
    00200                              -280, //263
    00201                              125, //225
    00202                              263,
    00203                              BRIGHT,
    00204                              BVISIBLE,
    00205                              true
    00206                             );
    00207
    00208     if(ptrb == NULL) return false;
    00209
    00210     ptrb = create_new_button("HOWTOPLAYBUTTON",
    00211                              "DEFAULT",
    00212                              "HOW TO PLAY",
    00213                              game->b_font,
    00214                              BCOLOR(255, 255, 255, 255), //80, 112, 255
    00215                              BCOLOR(65, 105, 255, 191),
    00216                              -290, //263
    00217                              200, //225
    00218                              263,
    00219                              BRIGHT,
    00220                              BVISIBLE,
    00221                              true
    00222                             );
    00223
    00224     if(ptrb == NULL) return false;
    00225
    00226     ptrb = create_new_button("OPTIONSBUTTON",
    00227                              "DEFAULT",
    00228                              "OPTIONS",
    00229                              game->b_font,
    00230                              BCOLOR(255, 255, 255, 255), //80, 112, 255
    00231                              BCOLOR(65, 105, 255, 191),
    00232                              -300, //263
    00233                              275, //225
    00234                              263,
    00235                              BRIGHT,
    00236                              BVISIBLE,
    00237                              true
    00238                             );
    00239
    00240     if(ptrb == NULL) return false;
    00241
    00242     ptrb = create_new_button("HIGHSCOREBUTTON",
    00243                              "DEFAULT",
    00244                              "HIGH SCORE",
    00245                              game->b_font,
    00246                              BCOLOR(255, 255, 255, 255), //80, 112, 255
    00247                              BCOLOR(65, 105, 255, 191),
    00248                              -310, //263
    00249                              350, //225
    00250                              263,
    00251                              BRIGHT,
    00252                              BVISIBLE,
    00253                              true
    00254                             );
    00255
    00256     if(ptrb == NULL) return false;
    00257
    00258     ptrb = create_new_button("EXITBUTTON",
    00259                              "DEFAULT",
    00260                              "Exit",
    00261                              game->b_font,
    00262                              BCOLOR(255, 255, 255, 255), //80, 112, 255
    00263                              BCOLOR(65, 105, 255, 191),
    00264                              -320, //263
    00265                              425, //225
    00266                              263,
    00267                              BRIGHT,
    00268                              BVISIBLE,
    00269                              true
    00270                             );
    00271
    00272     if(ptrb == NULL) return false;
    00273
    00274     set_standard_button_animation(BSHIFTRIGHT);
    00275
    00276     return true;
    00277 }
    00278
    00279 /*----------------------------------------------------------------------------------------------------------*/
    00280
    00281 // Initializes the button image list, where all BUTTON structures grab the button images from
    00282 _Bool init_button_images(void)
    00283 {
    00284     BIMAGESPTR ptrbi;
    00285
    00286     char *labels[1] = {"DEFAULT"};
    00287     char *images[1] = {"button_n.png"};
    00288
    00289     ptrbi = create_new_button_image_list(labels, images, sizeof(labels)/sizeof(*labels));
    00290
    00291     if(ptrbi == NULL) return false;
    00292     return true;
    00293 }
    00294
    00295 /*----------------------------------------------------------------------------------------------------------*/
    00296
    00297 _Bool init_chipmunk(void)
    00298 {
    00299     cpSpace *space = cpSpaceNew();
    00300     // Define a gravity vector
    00301     space->gravity = cpv(0, 600);
    00302     space->iterations = 10;
    00303     space->elasticIterations = 10;
    00304     if(set_global_cpSpace(space) == NULL) return false;
    00305     float width, height;
    00306
    00307     SPRITESPTR ground = search_sprite_list_for_element("GROUND");
    00308     width = ground->sdata.currentimg->width;
    00309     height = ground->sdata.currentimg->height;
    00310     cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
    00311     staticBody->p = cpv(0+res_width/2, 0+res_height/2);
    00312     cpShape *floorShape = cpSegmentShapeNew(staticBody,
    00313                                             cpv(0-res_width/2, 0+res_height/2-(res_height-ground->sdata.y)),
    00314                                             cpv(0+res_width, 0+res_height/2-(res_height-ground->sdata.y)),
    00315                                             0);
    00316     floorShape->e = 0.5f;
    00317     floorShape->u = 0.2f;
    00318     floorShape->collision_type = 0;
    00319     floorShape->data = "FLOORSHAPE";
    00320     cpSpaceAddStaticShape(space, floorShape);
    00321
    00322     cpShape *leftShape = cpSegmentShapeNew(staticBody,
    00323                                            cpv(0-res_width/2, 0+res_height/2),
    00324                                            cpv(0-res_width/2, 0-res_height/2),
    00325                                            0);
    00326     leftShape->e = 0.5f;
    00327     leftShape->u = 0.2f;
    00328     leftShape->collision_type = 0;
    00329     leftShape->data = "LEFTSHAPE";
    00330     cpSpaceAddStaticShape(space, leftShape);
    00331
    00332     cpShape *rightShape = cpSegmentShapeNew(staticBody,
    00333                                             cpv(0+res_width/2, 0+res_height/2),
    00334                                             cpv(0+res_width/2, 0-res_height/2),
    00335                                             0);
    00336     rightShape->e = 0.5f;
    00337     rightShape->u = 0.2f;
    00338     rightShape->collision_type = 0;
    00339     rightShape->data = "RIGHTSHAPE";
    00340     cpSpaceAddStaticShape(space, rightShape);
    00341
    00342     cpShape *topShape = cpSegmentShapeNew(staticBody,
    00343                                           cpv(0-res_width/2, 0-res_height/2),
    00344                                           cpv(0+res_width/2, 0-res_height/2),
    00345                                           0);
    00346     topShape->e = 0.5f;
    00347     topShape->u = 0.2f;
    00348     topShape->collision_type = 0;
    00349     topShape->data = "TOPSHAPE";
    00350     cpSpaceAddStaticShape(space, topShape);
    00351
    00352     return true;
    00353 }
    00354
    00355 /*----------------------------------------------------------------------------------------------------------*/
    00356
    00357 //    /**
    00358 //      *@}
    00359 //      */