Esempio n. 1
0
void sceneShow::run_viewpoint_scene(CURRENT_FILE_FORMAT::file_scene_show_viewpoint viewpoint)
{
    std::cout << "** sceneShow::run_image_scene::START" << std::endl;
    float x = viewpoint.ini_x;
    float y = viewpoint.ini_y;


    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/" + viewpoint.filename, &image);

    //std::cout << "** sceneShow::run_image_scene::total_dist: " << total_dist << std::endl;

    while (total_dist > 0) {
        input.read_input();
        //std::cout << "total_dist: " << total_dist << std::endl;
        timer.delay(viewpoint.move_delay);
        std::cout << "rect - x[" << x << "], .y[" << y << "], w[" << viewpoint.w << "], h[" << viewpoint.h << "]" << std::endl;

        //void graphicsLib::showSurfacePortion(graphicsLib_gSurface *surfaceOrigin, const st_rectangle origin_rect, st_rectangle destiny_rect)
        graphLib.showSurfacePortion(&image, st_rectangle(x, y, viewpoint.w, viewpoint.h), st_rectangle(viewpoint.pos_x, viewpoint.pos_y, viewpoint.w, viewpoint.h));

        graphLib.updateScreen();
        x += speed_x;
        y += speed_y;
        total_dist--;
    }
    graphLib.showSurfacePortion(&image, st_rectangle(x, y, viewpoint.w, viewpoint.h), st_rectangle(viewpoint.pos_x, viewpoint.pos_y, viewpoint.w, image.height));
    timer.delay(viewpoint.move_delay);

    graphLib.updateScreen();
}
Esempio n. 2
0
// @TODO - this should only set some variables in a global and the drawinbg should be handled my show_scene()
// That way we can move the run_XXX methods into threads to run in paralel
void sceneShow::run_image_scene(CURRENT_FILE_FORMAT::file_scene_show_image scene_image)
{
    std::cout << "** sceneShow::run_image_scene::START" << std::endl;
    float x = scene_image.ini_x;
    float y = scene_image.ini_y;
    graphicsLib_gSurface image;
    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(RES_W, RES_H), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(0, 0, RES_W, RES_H), st_position(0, 0), &bg_image);
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/" + scene_image.filename, &image);

    std::cout << "** sceneShow::run_image_scene::total_dist: " << total_dist << std::endl;

    while (total_dist > 0) {
        input.read_input();
        //std::cout << "total_dist: " << total_dist << std::endl;
        timer.delay(scene_image.move_delay);
        // @TODO - copy background, but should be done in a smarter way as there can be several moving elements
        graphLib.showSurfaceAt(&bg_image, st_position(0, 0), false);
        graphLib.showSurfaceAt(&image, st_position(x, y), false);
        graphLib.updateScreen();
        x += speed_x;
        y += speed_y;
        total_dist--;
    }
    graphLib.showSurfaceAt(&image, st_position(x, y), false);
    graphLib.updateScreen();
}
Esempio n. 3
0
void sceneShow::show_scene(int n)
{
    if (n < 0) {
        return;
    }
    if (scene_list.size() <= n) {
        std::cout << "ERROR: Scene List[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        return;
    }
    CURRENT_FILE_FORMAT::file_scene_list scene = scene_list.at(n);
    input.clean();

    for (int i=0; i<SCENE_OBJECTS_N; i++) {
        input.read_input();
        int scene_seek_n = scene.objects[i].seek_n;
        //std::cout << ">> sceneShow::show_scene - i: " << i << ", scene_seek_n: " << scene_seek_n << std::endl;

        if (_interrupt_scene == true || input.p1_input[BTN_START] == 1) {
            scene_seek_n = -1;
            break;
        }

        if (scene_seek_n != -1) {
            int scene_type = scene.objects[i].type;
            //std::cout << "### scene_type[" << scene_type << "]" << std::endl;
            if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_TEXT) {
                show_text(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_AREA) {
                clear_area(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_SCREEN) {
                graphLib.clear_area(0 ,0, RES_W, RES_H, 0, 0, 0);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_IMAGE) {
                show_image(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_VIEWPOINT) {
                show_viewpoint(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_MUSIC) {
                play_music(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_SFX) {
                play_sfx(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_ANIMATION) {
                show_animation(scene_seek_n, scene.objects[i].repeat_value, scene.objects[i].repeat_type);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_STOP_MUSIC) {
                soundManager.stop_music();
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SUBSCENE) {
                show_scene(scene_seek_n);
            } else {
                std::cout << ">> sceneShow::show_scene - unknown scene_type[" << scene_type << "]" << std::endl;
            }
            std::cout << "show_scene::DELAY[" << i << "][" << scene.objects[i].delay_after << "]" << std::endl;
            if (input.waitScapeTime(scene.objects[i].delay_after) == 1) {
                _interrupt_scene = true;
            }
        } else {
            break;
        }
    }
    std::cout << "show_scene::DONE" << std::endl;
}
Esempio n. 4
0
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode)
{
    int frame_n = 0;
    CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n);
    long frame_timer = timer.getTimer() + scene.frame_delay;
    long started_timer = timer.getTimer();
    int repeat_times = 0;

    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image);
    int max_frames = image.width / scene.frame_w;

    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image);


    std::cout << "max_frames[" << max_frames << "], image.w[" << image.width << "], scene.frame_w[" << scene.frame_w << "]" << std::endl;

    while (true) {
        input.read_input();
        int x = frame_n*scene.frame_w;


        // stop condition
        if (repeat_times > 0 && repeat_n <= 1) {
            std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl;
            break;
        } else {
            if (repeat_mode == 0) { // time-mode
                if ((timer.getTimer() - started_timer) > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl;
                    break;
                }
            } else { // repeat number mode
                if (repeat_times > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl;
                    break;
                }
            }
        }
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        std::cout << "x[" << x << "], img.w[" << image.width << "], frame.w[" << scene.frame_w << "]" << std::endl;
        graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y));
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);


        if (frame_timer < timer.getTimer()) {
            frame_n++;
            if (frame_n >= max_frames) {
                frame_n = 0;
                repeat_times++;
            }
            frame_timer = timer.getTimer() + scene.frame_delay;
        }

    }
    // avoid leaving animation image trail if it is a repeating one
    if (repeat_n > 1) {
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);
    }
}