Example #1
0
/* --- OK, now we have eight. --- */
void setup(int argc, char * argv[])
{
    /* Read debugging args from command line */
    handle_debug_args(argc, argv);
    /* initialize locale from system settings: */
    initialize_locale("");      
    /* initialize settings and read in config files: */
    /* Note this now only does the global settings   */
    initialize_options();
    /* Command-line code now in own function: */
    handle_command_args(argc, argv);
    /* initialize default user's options (for resolution)*/
    initialize_options_user();
    /* SDL setup in own function:*/
    initialize_SDL();
    /* Read image and sound files: */
    load_data_files();
    /* Generate flipped versions of walking images */
    generate_flipped_images();
    /* Generate blended images (e.g., igloos) */
    generate_blended_images();
    /* Note that the per-user options will be set after the call to
       titlescreen, to allow for user-login to occur. 

       FIXME this means that command-line args will be overridden!
       Is this desirable? */
}
Example #2
0
// main function
int main(int, char**) {
    // introduction
    printf("    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n");
    printf("    |               CC322 - Organizacion de Computadoras I                 |\n");
    printf("    |                            .-----------.                             |\n");
    printf("    |                           /   AssPong   \\                            |\n");
    printf("    |                          '==============='                           |\n");
    printf("    |                                                                      |\n");
    printf("    |                          *** Equipo 9 ***                            |\n");
    printf("    |                          Cavazos Woo David                           |\n");
    printf("    |                      Corona Garcia Erick Daniel                      |\n");
    printf("    |                                                                      |\n");
    printf("    |    Instrucciones:                                                    |\n");
    printf("    |        [ESC]   Salir                                                 |\n");
    printf("    |        [SPACE] Reset                                                 |\n");
    printf("    |        [w]     Mover jugador 1 arriba                                |\n");
    printf("    |        [s]     Mover jugador 1 abajo                                 |\n");
    printf("    |        [UP]    Mover jugador 2 arriba                                |\n");
    printf("    |        [DOWN]  Mover jugador 2 abajo                                 |\n");
    printf("    |                                                                      |\n");
    printf("    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\n");

    initialize_SDL();

    // SDL_mixer initialization
    Mix_OpenAudio(AUDIO_FREQUENCY, MIX_DEFAULT_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFER_SIZE);
    g_music = Mix_LoadMUS("still_alive.ogg");

    printf("Presione [Enter] para continuar...");
    getchar();

    initializeVideoContext_SDL();

    // play music
    if (g_music == 0)
        printf("Unable to load music: %s", Mix_GetError());
    else
        Mix_PlayMusic(g_music, -1);

    srand((unsigned int)(time(0)));
    initializeDimensions();
    resetEverything();

    g_deltaTime = 0.0;
    g_player1Wins = 0;
    g_player2Wins = 0;

    g_isKeyDownW = FALSE;
    g_isKeyDownS = FALSE;
    g_isKeyDownUP = FALSE;
    g_isKeyDownDOWN = FALSE;

    // main loop
    Uint32 startTime;
    BOOL isRunning = TRUE;
    while (isRunning) {
        startTime = SDL_GetTicks();

        // update
        processEvents_SDL(&isRunning);
        update();

        // draw
        clearScreen_SDL();
        drawEverything();
        SDL_Flip(g_screen); // flip buffers

        // framerate cap
        g_deltaTime = SDL_GetTicks() - startTime;
        if (MILLISECONDS_CAP > g_deltaTime)
            SDL_Delay((Uint32)(MILLISECONDS_CAP - g_deltaTime));
        g_deltaTime = (SDL_GetTicks() - startTime) * 0.001;

        // show framerate
//        stringstream title;
//        title << "Pong - " << setprecision(1) << fixed <<
//                        (g_deltaTime == 0.0? double(FRAMERATE_CAP) : 1.0 / g_deltaTime) << " fps";
//        SDL_WM_SetCaption(title.str().c_str(), "");
    }

    // shutdown
    Mix_FreeMusic(g_music);
    Mix_CloseAudio();
    shutdown_SDL();

    // show winner
    printf("\n");
    printf("                       .--------------------------------.\n");
    printf("                      /   ");
    if (g_player1Wins == g_player2Wins)
        printf("  ~~~~ Empate ~~~~ ");
    else if (g_player1Wins > g_player2Wins)
        printf("Ganador: Jugador 1 ");
    else
        printf("Ganador: Jugador 2 ");
    printf("(%2u : %2u)   \\\n", g_player1Wins, g_player2Wins);
    printf("                     '===================================='\n");
    printf("Presione [Enter] para salir...");
    getchar();

    return EXIT_SUCCESS;
}
Example #3
0
int main(int argc, char *argv[])
{

    // Init Display/SDM
    int continuer = 1; /* la variable coninuer sera égale à 0 si on veux quitter le programme */
    display *disp;

    SDL_Event event;
    int repeat;
  /*  Uint8 *keystate;*/

    disp = initialize_display_module();
    initialize_SDL();
    repeat = SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 3);

    //Init du main_char
    character* main_char;
    main_char = init_mainChar();

    coordinate* speed;
    state cState;
    int* jumpSpeed;

    //Init Plateforme
    plateform* floor;
    floor = init_plateform();

    set_pHitbox(floor, 640, 200);
    set_pPosition(floor, 0, 640-200);

    set_dCharacter_sprite(disp, "sprite/main_character.bmp");
    set_dPlatform_sprite(disp, "sprite/floor.bmp");

    set_dPlatform_position(disp, get_pPosition(floor));

    SDL_BlitSurface(disp->platform->image, NULL, disp->screen, disp->platform->position);


    speed = get_cSpeed(main_char);
    cState = get_cState(main_char);

    while(continuer)
    {
        SDL_PollEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                continuer = 0;
                break;

            case SDL_KEYDOWN:
                switch(event.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        continuer = 0;
                        break;

                     case SDLK_LEFT:
                        if(cState == jump)
                            set_cSpeed(main_char, speed->x-1, speed->y);
                        else
                            set_cSpeed(main_char, -1, speed->y);
                        break;

                    case SDLK_RIGHT:
                        if(cState == jump)
                            set_cSpeed(main_char, speed->x+1, speed->y);
                        else
                            set_cSpeed(main_char, 1, speed->y);
                        break;

                    case SDLK_SPACE:
                        if(cState != jump)
                        {
                            set_cState(main_char, jump);
                            *jumpSpeed = 10;
                        }
                        break;
                }
        }

        if(get_cState(main_char) == jump)
            cJump(main_char, jumpSpeed);

        move_char(main_char);

        set_dCharacter_position(disp, get_cPosition(main_char));

        display_all(disp);
    }

    free_display_module(disp);
    free_SDL();

    free_mainChar(main_char);
    free_plateform(floor);

    return 0;
}