Beispiel #1
0
static void game_update_time(float dt, int b)
{
    int tick = (int) floor(my_clock);
    int tock = (int) floor(my_clock * 2);

    if (goal_e && goal_k < 1.0f)
        goal_k += dt;

   /* The ticking my_clock. */

    if (b)
    {
        if (my_clock < 600.f)
            my_clock -= dt;
        if (my_clock < 0.f)
            my_clock = 0.f;

        if (0 < tick && tick <= 10 && tick == (int) ceil(my_clock))
        {
            audio_play(AUD_TICK, 1.f);
            hud_time_pulse(1.50);
        }
        else if (0 < tock && tock <= 10 && tock == (int) ceil(my_clock * 2))
        {
            audio_play(AUD_TOCK, 1.f);
            hud_time_pulse(1.25);
        }
    }
}
Beispiel #2
0
static int play_loop_click(int b, int d)
{
    /*if (d)
    {
        if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
            rot_set(DIR_R, 1.0f, 0);
        if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
            rot_set(DIR_L, 1.0f, 0);

        click_camera(b);
    }
    else
    {
        if (config_tst_d(CONFIG_MOUSE_CAMERA_R, b))
            rot_clr(DIR_R);
        if (config_tst_d(CONFIG_MOUSE_CAMERA_L, b))
            rot_clr(DIR_L);
    }*/
    clickdown = d;
    if (d) {
        if (hittest == 1) {
            hud_pause();
            clickdown = 0;
            goto_state(&st_pause);
            audio_play(AUD_MENU, 1.0f);
        } else if (hittest == 2) {
            next_camera();
            audio_play(AUD_MENU, 1.0f);
        }
    } else {
        rot_clr(DIR_L | DIR_R);
    }

    return 1;
}
Beispiel #3
0
static int party_action(int i)
{
    switch (i)
    {
    case PARTY_1:
        audio_play(AUD_MENU, 1.f);
        hole_goto(1, 1);
        goto_state(&st_next);
        break;
    case PARTY_2:
        audio_play(AUD_MENU, 1.f);
        hole_goto(1, 2);
        goto_state(&st_next);
        break;
    case PARTY_3:
        audio_play(AUD_MENU, 1.f);
        hole_goto(1, 3);
        goto_state(&st_next);
        break;
    case PARTY_4:
        audio_play(AUD_MENU, 1.f);
        hole_goto(1, 4);
        goto_state(&st_next);
        break;
    case PARTY_B:
        audio_play(AUD_MENU, 1.f);
        goto_state(&st_course);
        break;
    }
    return 1;
}
Beispiel #4
0
static int conf_action(int tok, int val)
{
    int sound = config_get_d(CONFIG_SOUND_VOLUME);
    int music = config_get_d(CONFIG_MUSIC_VOLUME);
    int mouse = MOUSE_RANGE_MAP(config_get_d(CONFIG_MOUSE_SENSE));
    int r = 1;

    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case GUI_BACK:
        goto_state(&st_title);
        break;

    case CONF_VIDEO:
        goto_state(&st_conf_video);
        break;

    case CONF_PLAYER:
        goto_name(&st_conf, &st_conf, 1);
        break;

    case CONF_BALL:
        goto_state(&st_ball);
        break;

    case CONF_MOUSE_SENSE:
        config_set_d(CONFIG_MOUSE_SENSE, MOUSE_RANGE_UNMAP(val));

        gui_toggle(mouse_id[val]);
        gui_toggle(mouse_id[mouse]);
        break;

    case CONF_SOUND_VOLUME:
        config_set_d(CONFIG_SOUND_VOLUME, val);
        audio_volume(val, music);
        audio_play(AUD_BUMPM, 1.f);

        gui_toggle(sound_id[val]);
        gui_toggle(sound_id[sound]);
        break;

    case CONF_MUSIC_VOLUME:
        config_set_d(CONFIG_MUSIC_VOLUME, val);
        audio_volume(sound, val);
        audio_play(AUD_BUMPM, 1.f);

        gui_toggle(music_id[val]);
        gui_toggle(music_id[music]);

        break;
    }

    return r;
}
Beispiel #5
0
static int game_update_state(float dt)
{
    static float t = 0.f;

    struct s_vary *fp = &file.vary;
    float p[3];

    if (dt > 0.f)
        t += dt;
    else
        t = 0.f;

    /* Test for a switch. */

    if (sol_swch_test(fp, ball) == SWCH_INSIDE)
        audio_play(AUD_SWITCH, 1.f);

    /* Test for a jump. */

    if (jump_e == 1 && jump_b == 0 && (sol_jump_test(fp, jump_p, ball) ==
                                       JUMP_INSIDE))
    {
        jump_b  = 1;
        jump_e  = 0;
        jump_dt = 0.f;

        audio_play(AUD_JUMP, 1.f);
    }
    if (jump_e == 0 && jump_b == 0 && (sol_jump_test(fp, jump_p, ball) ==
                                       JUMP_OUTSIDE))
    {
        jump_e = 1;
    }

    /* Test for fall-out. */

    if (fp->uv[ball].p[1] < -10.f)
        return GAME_FALL;

    /* Test for a goal or stop. */

    if (t > 1.f && sol_goal_test(fp, p, ball))
    {
        t = 0.f;
        return GAME_GOAL;
    }

    if (t > idle_t)
    {
        t = 0.f;
        return GAME_STOP;
    }

    return GAME_NONE;
}
Beispiel #6
0
static int game_update_state(void)
{
    struct s_file *fp = &file;
    float p[3];
    float c[3];
    int n, e = swch_e;

    /* Test for a coin grab and a possible 1UP. */

    if ((n = sol_coin_test(fp, p, COIN_RADIUS)) > 0)
    {
        coin_color(c, n);
        part_burst(p, c);

        if (level_score(n))
            goal_e = 1;
    }

    /* Test for a switch. */

    if ((swch_e = sol_swch_test(fp, swch_e, 0)) != e && e)
        audio_play(AUD_SWITCH, 1.f);

    /* Test for a jump. */

    if (jump_e == 1 && jump_b == 0 && sol_jump_test(fp, jump_p, 0) == 1)
    {
        jump_b  = 1;
        jump_e  = 0;
        jump_dt = 0.f;
        
        audio_play(AUD_JUMP, 1.f);
    }
    if (jump_e == 0 && jump_b == 0 && sol_jump_test(fp, jump_p, 0) == 0)
        jump_e = 1;

    /* Test for a goal. */

    if (goal_e && sol_goal_test(fp, p, 0))
        return GAME_GOAL;

    /* Test for time-out. */

    if (my_clock <= 0.f)
        return GAME_TIME;

    /* Test for fall-out. */

    if (fp->uv[0].p[1] < fp->vv[0].p[1])
        return GAME_FALL;

    return GAME_NONE;
}
Beispiel #7
0
static int next_enter(struct state *st, struct state *prev)
{
    int id, jd;
    char str[MAXSTR];

    sprintf(str, _("Hole %02d"), curr_hole());

    if ((id = gui_vstack(0)))
    {
        gui_label(id, str, GUI_MED, 0, 0);
        gui_space(id);

        if ((jd = gui_vstack(id)))
        {
            gui_label(jd, _("Player"), GUI_SML, 0, 0);

            switch (curr_player())
            {
            case 1:
                gui_label(jd, "1", GUI_LRG, gui_red, gui_wht);
                if (curr_party() > 1) audio_play(AUD_PLAYER1, 1.f);
                break;
            case 2:
                gui_label(jd, "2", GUI_LRG, gui_grn, gui_wht);
                if (curr_party() > 1) audio_play(AUD_PLAYER2, 1.f);
                break;
            case 3:
                gui_label(jd, "3", GUI_LRG, gui_blu, gui_wht);
                if (curr_party() > 1) audio_play(AUD_PLAYER3, 1.f);
                break;
            case 4:
                gui_label(jd, "4", GUI_LRG, gui_yel, gui_wht);
                if (curr_party() > 1) audio_play(AUD_PLAYER4, 1.f);
                break;
            }

            gui_set_rect(jd, GUI_ALL);
        }
        gui_layout(id, 0, 0);
    }

    hud_init();
    game_set_fly(1.f);

    if (paused)
        paused = 0;

    return id;
}
Beispiel #8
0
static int conf_action(int i)
{
    int s = config_get_d(CONFIG_SOUND_VOLUME);
    int m = config_get_d(CONFIG_MUSIC_VOLUME);
    int r = 1;

    audio_play(AUD_MENU, 1.0f);

    switch (i)
    {
    case CONF_BACK:
        goto_state(&st_title);
        break;

    case CONF_VIDEO:
        goto_state(&st_video);
        break;

    case CONF_LANG:
        goto_state(&st_lang);
        break;

    default:
        if (100 <= i && i <= 110)
        {
            int n = i - 100;

            config_set_d(CONFIG_SOUND_VOLUME, n);
            audio_volume(n, m);
            audio_play(AUD_BUMP, 1.f);

            gui_toggle(sound_id[n]);
            gui_toggle(sound_id[s]);
        }
        if (200 <= i && i <= 210)
        {
            int n = i - 200;

            config_set_d(CONFIG_MUSIC_VOLUME, n);
            audio_volume(s, n);
            audio_play(AUD_BUMP, 1.f);

            gui_toggle(music_id[n]);
            gui_toggle(music_id[m]);
        }
    }

    return r;
}
void stunned() {
    
    audio_play(AUDIO_STUN_HIT);
    //@todo Disable non-essential interrupts (i.e. motion, IR)
    
    // i should be a value that causes delay for 10 sec.
    for (uint8_t i = 0; i < 200; i++) {
        LED_play_pattern(LED_STUN_SELF);
        delay_25ms_n_times(1);
    }
    
    audio_play(AUDIO_STUN_END);
    LED_play_pattern(LED_ARMED);
    /** @todo Re-enable non-essential interrupts */
}
Beispiel #10
0
static int pause_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case PAUSE_CONTINUE:
        audio_pause(0);
        video_set_grab(0);
        return goto_state(st_continue);

    case PAUSE_RESTART:
        if (progress_same())
        {
            audio_pause(0);
            video_set_grab(1);
            return goto_state(&st_play_ready);
        }
        break;

    case PAUSE_EXIT:
        progress_stat(GAME_NONE);
        progress_stop();
        audio_pause(0);
        audio_music_stop();
        return goto_state(&st_exit);
    }

    return 1;
}
Beispiel #11
0
int sound_play(const char *data, unsigned int len, sound_state *ss) {
    // Audio data struct for userdata
    sound_effect *se = malloc(sizeof(sound_effect));
    se->data = data;
    se->pos = 0;
    se->len = len;
    
    // Create stream
    audio_stream stream;
    stream.frequency = 8000;
    stream.channels = 1;
    stream.bytes = 1;
    stream.type = TYPE_EFFECT;
    stream.userdata = (void*)se;
    stream.preupdate = sound_preupdate;
    stream.update = sound_update;
    stream.close = sound_close;
    stream.snd = *ss;
    
    // Create openal stream
    if(audio_stream_create(&stream)) {
        free(se);
        return 1;
    }
    
    // Play
    audio_play(&stream);
    audio_stream_set_volume(&stream, ss->vol);
    
    // All done
    return 0;
}
Beispiel #12
0
static int display_action(int tok, int val)
{
    int r = 1;

    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case GUI_BACK:
        goto_state(display_back);
        display_back = NULL;
        break;

    case DISPLAY_SELECT:
        if (val != config_get_d(CONFIG_DISPLAY))
        {
            goto_state(&st_null);
            config_set_d(CONFIG_DISPLAY, val);
            r = video_mode(config_get_d(CONFIG_FULLSCREEN),
                           config_get_d(CONFIG_WIDTH),
                           config_get_d(CONFIG_HEIGHT));
            goto_state(&st_display);
        }
        break;
    }

    return r;
}
Beispiel #13
0
static int demo_end_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case DEMO_DEL:
        demo_paused = 0;
        hud_resume();
        return goto_state(&st_demo_del);
    case DEMO_KEEP:
        demo_paused = 0;
        demo_replay_stop(0);
        hud_resume();
        return goto_state(&st_demo);
    case DEMO_QUIT:
        demo_replay_stop(0);
        hud_resume();
        return 0;
    case DEMO_REPLAY:
        demo_replay_stop(0);
        hud_demo();
        progress_replay(curr_demo());
        return goto_state(&st_demo_play);
    case DEMO_CONTINUE:
        hud_demo();
        return goto_state(&st_demo_play);
    }
    return 1;
}
Beispiel #14
0
static int name_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case GUI_BACK:
        return goto_state(cancel_state);

    case NAME_OK:
        if (strlen(text_input) == 0)
            return 1;

        config_set_s(CONFIG_PLAYER, text_input);

        return goto_state(ok_state);

    case GUI_CL:
        gui_keyboard_lock();
        break;

    case GUI_BS:
        text_input_del();
        break;

    case GUI_CHAR:
        text_input_char(val);
        break;
    }
    return 1;
}
Beispiel #15
0
static int name_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case NAME_OK:
        if (strlen(player) == 0)
           return 1;

        config_set_s(CONFIG_PLAYER, player);

        return goto_state(ok_state);

    case NAME_CANCEL:
        return goto_state(cancel_state);

    case GUI_CL:
        gui_keyboard_lock();
        break;

    case GUI_BS:
        if (text_del_char(player))
            gui_set_label(name_id, player);
        break;

    case GUI_CHAR:
        if (text_add_char(val, player, sizeof (player)))
            gui_set_label(name_id, player);
    }
    return 1;
}
Beispiel #16
0
static int demo_del_action(int i)
{
    audio_play(AUD_MENU, 1.0f);

    demo_replay_stop(i == DEMO_DEL);
    return goto_state(&st_demo);
}
Beispiel #17
0
static int demo_action(int i)
{
    audio_play(AUD_MENU, 1.0f);

    switch (i)
    {
    case GUI_BACK:
        return goto_state(&st_title);

    case GUI_NEXT:
        first += DEMO_STEP;
        return goto_state(&st_demo);
        break;

    case GUI_PREV:
        first -= DEMO_STEP;
        return goto_state(&st_demo);
        break;

    case GUI_NULL:
        return 1;
        break;

    default:
        if (progress_replay(DEMO_GET(items, i)->filename))
        {
            last_viewed = i;
            demo_play_goto(0);
            return goto_state(&st_demo_play);
        }
        break;
    }
    return 1;
}
Beispiel #18
0
static int demo_end_action(int i)
{
    audio_play(AUD_MENU, 1.0f);

    switch (i)
    {
    case DEMO_DEL:
        demo_paused = 0;
        return goto_state(&st_demo_del);
    case DEMO_KEEP:
        demo_paused = 0;
        demo_replay_stop(0);
        return goto_state(&st_demo);
    case DEMO_QUIT:
        demo_replay_stop(0);
        return 0;
    case DEMO_REPLAY:
        demo_replay_stop(0);
        progress_replay(curr_demo_replay()->filename);
        return goto_state(&st_demo_play);
    case DEMO_CONTINUE:
        return goto_state(&st_demo_play);
    }
    return 1;
}
Beispiel #19
0
void settings_apply_play_freq(int value, bool playback)
{
    static const unsigned long play_sampr[] = { SAMPR_44, SAMPR_48 };
    static int prev_setting = 0;

    if ((unsigned)value >= ARRAYLEN(play_sampr))
        value = 0;

    bool changed = value != prev_setting;
    prev_setting = value;

    unsigned long elapsed = 0;
    unsigned long offset = 0;
    bool playing = changed && !playback &&
                   audio_status() == AUDIO_STATUS_PLAY;

    if (playing)
    {
        struct mp3entry *id3 = audio_current_track();
        elapsed = id3->elapsed;
        offset = id3->offset;
    }

    if (changed && !playback)
        audio_hard_stop();

    /* Other sub-areas of playback pick it up from the mixer */
    mixer_set_frequency(play_sampr[value]);

    if (playing)
        audio_play(elapsed, offset);
}
Beispiel #20
0
static int demo_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case GUI_BACK:
        return goto_state(&st_title);

    case GUI_NEXT:
        first += DEMO_STEP;
        return goto_state(&st_demo);
        break;

    case GUI_PREV:
        first -= DEMO_STEP;
        return goto_state(&st_demo);
        break;

    case DEMO_SELECT:
        if (progress_replay(DIR_ITEM_GET(items, val)->path))
        {
            last_viewed = val;
            demo_play_goto(0);
            return goto_state(&st_demo_play);
        }
        break;
    }
    return 1;
}
Beispiel #21
0
void game_set_goal(void)
{
    audio_play(AUD_SWITCH, 1.0f);
    goal_e = 1;

    game_cmd_goalopen();
}
Beispiel #22
0
static int time_out_action(int i)
{
    audio_play(AUD_MENU, 1.0f);

    switch (i)
    {
    case TIME_OUT_BACK:
        /* Fall through. */

    case TIME_OUT_OVER:
        progress_stop();
        return goto_state(&st_over);

    case TIME_OUT_SAVE:
        progress_stop();
        return goto_save(&st_time_out, &st_time_out);

    case TIME_OUT_NEXT:
        if (progress_next())
            return goto_state(&st_level);
        break;

    case TIME_OUT_SAME:
        if (progress_same())
            return goto_state(&st_level);
        break;
    }

    return 1;
}
Beispiel #23
0
int game_step(const float g[3], float dt)
{
    struct s_file *fp = &file;

    static float s = 0.f;
    static float t = 0.f;

    float d = 0.f;
    float b = 0.f;
    float st = 0.f;
    int i, n = 1, m = 0;

    s = (7.f * s + dt) / 8.f;
    t = s;

    if (jump_b)
    {
        jump_dt += dt;

        /* Handle a jump. */

        if (0.5 < jump_dt)
        {
            fp->uv[ball].p[0] = jump_p[0];
            fp->uv[ball].p[1] = jump_p[1];
            fp->uv[ball].p[2] = jump_p[2];
        }
        if (1.f < jump_dt)
            jump_b = 0;
    }
    else
    {
        /* Run the sim. */

        while (t > MAX_DT && n < MAX_DN)
        {
            t /= 2;
            n *= 2;
        }

        for (i = 0; i < n; i++)
        {
            d = sol_step(fp, g, t, ball, &m);

            if (b < d)
                b = d;
            if (m)
                st += t;
        }

        /* Mix the sound of a ball bounce. */

        if (b > 0.5)
            audio_play(AUD_BUMP, (float) (b - 0.5) * 2.0f);
    }

    game_update_view(dt);
    return game_update_state(st);
}
Beispiel #24
0
int main(int argc, char *argv[])
{
    SDL_Surface* screen = NULL, *menu = NULL;
    SDL_Rect positionMenu;
    SDL_Event event;

    int continuer = 1;

    audio_init();
    audio_play(1);

    SDL_Init(SDL_INIT_VIDEO);

    SDL_WM_SetIcon(IMG_Load("images/Mario.png"), NULL); // L'icône doit être chargée avant SDL_SetVideoMode
    screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); //Ouvre la page
    SDL_WM_SetCaption("Super Mario BROS", NULL); //Définit le titre

    menu = IMG_Load("images/menu.jpg"); //Charge l'image du menu
    positionMenu.x = screen->w / 2 - menu->w / 2; //Définit le menu au centre de la fenêtre
    positionMenu.y = 0;


    while (continuer)
    {
        SDL_WaitEvent(&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_1:

                        game(screen);
                        screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
                        break;
                    case SDLK_2:
                        credits(screen);
                        break;
                }
                break;
        }

        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); //Fond noir
        SDL_BlitSurface(menu, NULL, screen, &positionMenu); //Imprime le menu sur la page
        SDL_Flip(screen);
    }

    audio_stop();
    SDL_FreeSurface(menu); //Efface le menu
    SDL_Quit(); //Quitte

    return EXIT_SUCCESS;
}
Beispiel #25
0
void callback_av_audio(ToxAv *av, int32_t call_index, const int16_t *data, uint16_t samples, void *that)
{
    //qDebug() << "was called";
    ToxAvCSettings dest;
    if(toxav_get_peer_csettings(av, call_index, 0, &dest) == 0) {
        audio_play(call_index, data, samples, dest.audio_channels, dest.audio_sample_rate);
    }
}
Beispiel #26
0
void hole_goal(void)
{
    score_v[hole][player]++;

    if (score_v[hole][player] == 1)
        audio_play(AUD_ONE, 1.0f);

    else if (score_v[hole][player] == score_v[hole][0] - 2)
        audio_play(AUD_EAGLE, 1.0f);
    else if (score_v[hole][player] == score_v[hole][0] - 1)
        audio_play(AUD_BIRDIE, 1.0f);
    else if (score_v[hole][player] == score_v[hole][0])
        audio_play(AUD_PAR, 1.0f);
    else if (score_v[hole][player] == score_v[hole][0] + 1)
        audio_play(AUD_BOGEY, 1.0f);
    else if (score_v[hole][player] == score_v[hole][0] + 2)
        audio_play(AUD_DOUBLE, 1.0f);
    else
        audio_play(AUD_SUCCESS, 1.0f);

    stat_v[player] = 1;
    done++;

    if (done == party)
        audio_music_fade_out(2.0f);
}
Beispiel #27
0
/** responds to a audio frame call back from toxav
 *
 * Moving this here might break Android, if you know this commit compiles and runs on android, remove this line!
 */
static void utox_av_incoming_frame_a(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
                                    uint8_t channels, uint32_t sample_rate, void *userdata) {
    // debug("Incoming audio frame for friend %u \n", friend_number);
    #ifdef NATIVE_ANDROID_AUDIO
    audio_play(friend_number, pcm, sample_count, channels);
    #else
    sourceplaybuffer(friend_number, pcm, sample_count, channels, sample_rate);
    #endif
}
Beispiel #28
0
static void on_text_input(void)
{
    if (name_id)
    {
        gui_set_label(name_id, text_input);

        audio_play(AUD_MENU, 1.0f);
    }
}
Beispiel #29
0
static int over_enter(struct state *st, struct state *prev)
{
    audio_music_fade_out(2.0f);
    audio_play(AUD_OVER, 1.f);

    video_clr_grab();

    return over_gui();
}
Beispiel #30
0
static int play_ready_enter(struct state *st, struct state *prev)
{
    audio_play(AUD_READY, 1.0f);
    video_set_grab(1);

    hud_cam_pulse(config_get_d(CONFIG_CAMERA));

    return play_ready_gui();
}