Exemplo n.º 1
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;
}
Exemplo n.º 2
0
static int next_buttn(int b, int d)
{
    if (d)
    {
        //senquack - on GCW Zero, you can press any A/X/Y/B to proceed (makes more sense)
#ifdef GCWZERO
        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b) ||
                config_tst_d(CONFIG_JOYSTICK_BUTTON_X, b) || config_tst_d(CONFIG_JOYSTICK_BUTTON_Y, b))
#else
        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
#endif //GCWZERO
        {
            if (num > 0)
            {
                if (hole_goto(num, -1))
                {
                    num = 0;
                    return goto_state(&st_next);
                }
                else
                {
                    num = 0;
                    return 1;
                }
            }
            return goto_state(&st_flyby);
        }
        //senquack - It really makes no sense to pause when asking to go the next hole, disabling that on GCW Zero:
#ifndef GCWZERO
        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
            return goto_pause(&st_over);
#endif //GCWZERO
    }
    return 1;
}
Exemplo n.º 3
0
int hole_move(void)
{
    if (hole + 1 < count)
    {
        hole++;

        game_free();
        back_free();

        if (hole_goto(hole, party))
            return 1;
    }
    return 0;
}
Exemplo n.º 4
0
static int next_buttn(int b, int d)
{
    if (d)
    {
        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
        {
            if (num > 0 && hole_goto(num, -1))
            {
                num = 0;
                return goto_state(&st_next);
            }
            return goto_state(&st_flyby);
        }
        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
            return goto_pause(&st_over);
    }
    return 1;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    int camera = 0;
    SDL_Joystick *joy = NULL;

    if (!fs_init(argv[0]))
    {
        fprintf(stderr, "Failure to initialize virtual file system: %s\n",
                fs_error());
        return 1;
    }

    srand((int) time(NULL));

    lang_init("neverball");

    opt_parse(argc, argv);

    config_paths(opt_data);
    fs_mkdir("Screenshots");

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
    {
        config_init();
        config_load();

        /* Cache Neverball's camera setting. */

        camera = config_get_d(CONFIG_CAMERA);

        /* Initialize the joystick. */

        if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
        {
            joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
            if (joy)
            {
                SDL_JoystickEventState(SDL_ENABLE);
                set_joystick(joy);
            }
        }

        /* Initialize the audio. */

        audio_init();

        /* Initialize the video. */

        if (video_init(TITLE, ICON))
        {
            int t1, t0 = SDL_GetTicks();

            /* Run the main game loop. */

            init_state(&st_null);

            if (opt_hole)
            {
                const char *path = fs_resolve(opt_hole);
                int loaded = 0;

                if (path)
                {
                    hole_init(NULL);

                    if (hole_load(0, path) &&
                        hole_load(1, path) &&
                        hole_goto(1, 1))
                    {
                        goto_state(&st_next);
                        loaded = 1;
                    }
                }

                if (!loaded)
                    goto_state(&st_title);
            }
            else
                goto_state(&st_title);

            while (loop())
                if ((t1 = SDL_GetTicks()) > t0)
                {
                    st_timer((t1 - t0) / 1000.f);
                    st_paint(0.001f * t1);
                    shot_take();
                    SDL_GL_SwapWindow(video_get_window());

                    t0 = t1;

                    if (config_get_d(CONFIG_NICE))
                        SDL_Delay(1);
                }
        }

        /* Restore Neverball's camera setting. */

        config_set_d(CONFIG_CAMERA, camera);
        config_save();

        SDL_Quit();
    }
    else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());

    return 0;
}
Exemplo n.º 6
0
void course_rand(void)
{
    course_goto(rand() % count);
    hole_goto(rand() % curr_count(), 4);
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    int camera = 0;
    SDL_Joystick *joy = NULL;

    if (!fs_init(argv[0]))
    {
        fprintf(stderr, "Failure to initialize virtual file system (%s)\n",
                fs_error());
        return 1;
    }

    srand((int) time(NULL));

    opt_parse(argc, argv);

    config_paths(opt_data);
    log_init("Neverputt", "neverputt.log");
    fs_mkdir("Screenshots");

    /* Request backlight stay on (ubuntu touch) */

    int dispreq = -1;

    DBusError err;
    dbus_error_init(&err);
    DBusConnection *conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
        log_printf("Failed to get system bus\n");
        dbus_error_free(&err);
        if (conn) {
            dbus_connection_unref(conn);
            conn = NULL;
        }
    } else {
        dbus_connection_set_exit_on_disconnect(conn, 0);

        DBusMessage *msg = dbus_message_new_method_call("com.canonical.Unity.Screen", "/com/canonical/Unity/Screen", "com.canonical.Unity.Screen", "keepDisplayOn");
        if (msg != NULL) {
            DBusMessage *reply = dbus_connection_send_with_reply_and_block(conn, msg, 300, NULL);
            if (reply) {
                if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &dispreq, DBUS_TYPE_INVALID)) dispreq = -1;
                dbus_message_unref(reply);
            }
            dbus_message_unref(msg);
        }

        if (dispreq == -1) log_printf("Failed to request backlight stay on\n");
    }

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0)
    {
        config_init();
        config_load();

        /* Initialize localization. */

        lang_init();

        /* Cache Neverball's camera setting. */

        camera = config_get_d(CONFIG_CAMERA);

        /* Initialize the joystick. */

        if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0)
        {
            joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE));
            if (joy)
            {
                SDL_JoystickEventState(SDL_ENABLE);
                set_joystick(joy);
            }
        }

        /* Initialize the audio. */

        audio_init();

        /* Initialize the video. */

        if (video_init())
        {
            int t1, t0 = SDL_GetTicks();

            /* Material system. */

            mtrl_init();

            /* Run the main game loop. */

            init_state(&st_null);

            if (opt_hole)
            {
                const char *path = fs_resolve(opt_hole);
                int loaded = 0;

                if (path)
                {
                    hole_init(NULL);

                    if (hole_load(0, path) &&
                            hole_load(1, path) &&
                            hole_goto(1, 1))
                    {
                        goto_state(&st_next);
                        loaded = 1;
                    }
                }

                if (!loaded)
                    goto_state(&st_title);
            }
            else
                goto_state(&st_title);

            while (loop())
                if ((t1 = SDL_GetTicks()) > t0)
                {
                    st_timer((t1 - t0) / 1000.f);
                    hmd_step();
                    st_paint(0.001f * t1);
                    video_swap();

                    t0 = t1;

                    if (config_get_d(CONFIG_NICE))
                        SDL_Delay(1);
                }

            mtrl_quit();
        }

        /* Restore Neverball's camera setting. */

        config_set_d(CONFIG_CAMERA, camera);
        config_save();

        /* Remove backlight request (ubuntu touch) */

        if (conn) {
            if (dispreq != -1) {
                DBusMessage *msg = dbus_message_new_method_call("com.canonical.Unity.Screen", "/com/canonical/Unity/Screen", "com.canonical.Unity.Screen", "removeDisplayOnRequest");
                dbus_message_append_args(msg, DBUS_TYPE_INT32, &dispreq, DBUS_TYPE_INVALID);
                if (msg != NULL) {
                    if (dbus_connection_send(conn, msg, NULL)) dbus_connection_flush(conn);
                    dbus_message_unref(msg);
                }
            }
            dbus_connection_close(conn);
            dbus_connection_unref(conn);
            dbus_shutdown();
        }

        SDL_Quit();
    }
    else log_printf("Failure to initialize SDL (%s)\n", SDL_GetError());

    return 0;
}